Graderpractice for programmers

Back to 254275 OOP - Mini Test 2 (Sec 3 & 4)

2. Add toString method

Problem

Reuse your Watch class from question 1. Add a method named toString that returns the name and the colour.

Test code:

class MT2bTask2 {
    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        Watch w = input();

        System.out.println(w.toString());
    }

    private static Watch input() {
        String name = sc.nextLine();
        String colour = sc.nextLine();
        int price = Integer.parseInt(sc.nextLine());
        return new Watch(name, colour, price);
    }
}

Examples

Input

Apple Watch 32mm
Black
11000

Output

Apple Watch 32mm Black

Input

Guess
Rose Gold
7600

Output

Guess Rose Gold

Submit your solution

java