Graderpractice for programmers

Back to 254275 OOP Lab 5-10

Q11. Create Watch

Problem

Write a class named Watch with members name, colour and price. The class needs a constructor and get methods for each member.

Test code:

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

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

        System.out.println("Watch name: " + w.getName());
        System.out.println("Colour: " + w.getColour());
        System.out.println("Price: " + w.getPrice() + " baht");
    }

    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

Guess
Rose Gold
7600

Output

Watch name: Guess
Colour: Rose Gold
Price: 7600 baht

Submit your solution

java