Graderpractice for programmers

Back to 254275 OOP Lab 5-10

Q15. Create subclass Smartwatch

Problem

Smartwatch is a subclass of Watch. Smartwatch has a String member named operatingSystem (e.g. "WatchOS" or "Android Wear"). Write the Smartwatch class.

Test code:


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

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

        System.out.println("Watch name: " + w.getName());
        System.out.println("Operating System: " + w.getOperatingSystem());
    }

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

Examples

Input

Apple Watch Series 4
Silver
11500
WatchOS

Output

Watch name: Apple Watch Series 4
Operating System: WatchOS

Input

Fossil Sport
Red
8500
Android Wear

Output

Watch name: Fossil Sport
Operating System: Android Wear

Submit your solution

java