Graderpractice for programmers

Back to 254275 OOP - Labs 1-5 Review

L. Seats and sofas ✰

Problem

A seat has a colour and a maximum number of people who can sit down. If the seat can sit more than 1 person then it is a sofa or a bench. Complete the Seat class by writing 3 methods:

  • getColour returns the colour of the seat
  • getMaxPeople returns the maximum number of people who can sit
  • isSofaOrBench returns true if the maximum number of people is greater than 2

Submit the Seat.java file ONLY!

Template:
class Seat {
    private String colour;
    private int maxPeople;

    public Seat(String colour, int maxPeople) {
        this.colour = colour;
        this.maxPeople = maxPeople;
    }
}
Test code:
class TestE {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Seat seat = new Seat(sc.nextLine(), sc.nextInt());
        System.out.print("The " + seat.getColour() + " seat can sit " + seat.getMaxPeople() + " people - ");
        if (seat.isSofaOrBench()) {
            System.out.println("it's a sofa!");
        }
        else {
            System.out.println("not a sofa!");
         }
    }
}

Examples

Input

blue
1

Output

The blue seat can sit 1 people - not a sofa!

Input

green
4

Output

The green seat can sit 4 people - it's a sofa!

Submit your solution

java