Graderpractice for programmers

254275 OOP - Mini Test 1 (Sec 1 & 2)

Awaiting submission
Read in an integer. If it is less than zero, print "negative". If it is greater than zero, print "positive". Else print "zero".
Awaiting submission
The sequence of square numbers is 12, 22, 32, 42, ..., n2. Read in the number n and print out the sequence of square numbers up to the n-th item.
Awaiting submission
Read in an integer x. Print a large letter C using asterisk (*). It should have a line of x asterisks at the top, left and bottom.
Awaiting submission
Read in a list of words. For each word, print out the first and last character. When the program reaches the word "quit" then stop.
Awaiting submission
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!");
         }
    }
}