Graderpractice for programmers

Back to 254275 OOP - Labs 1-5 Review

M. Houses ✰

Problem

A house has a living room, a kitchen, X bedrooms and Y toilets. Complete the House class by writing 3 methods:

  • getBedrooms returns the number of bedrooms X
  • getToilets returns the number of toilets Y
  • getTotal returns the total number of rooms (X + Y + 2)

Submit the House.java file ONLY!

Template:
class House {
    private int bedrooms;
    private int toilets;

    public House(int bedrooms, int toilets) {
        this.bedrooms = bedrooms;
        this.toilets = toilets;
    }
}
Test code:
class TestE {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        House h = new House(sc.nextInt(), sc.nextInt());
        System.out.println("My house has " + h.getTotal() + " rooms including " + h.getBedrooms() + " bedrooms and " + h.getToilets() + " toilets.");
    }
}

Examples

Input

2
1

Output

My house has 5 rooms including 2 bedrooms and 1 toilets.

Input

3
3

Output

My house has 8 rooms including 3 bedrooms and 3 toilets.

Submit your solution

java