Graderpractice for programmers

Back to 254275 OOP Lab 5-10

Q16. Add isAppleWatch method

Problem

Reuse your Smartwatch class from question 5. Add a method named isAppleWatch that returns true if the operating system is "WatchOS".

Test code:


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

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

        if (w.isAppleWatch()) {
            System.out.println(w.getName() + " is an Apple Watch");
        }
        else {
            System.out.println("Not an Apple Watch");
        }
    }

    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

Fossil Sport
Red
8500
Android Wear

Output

Not an Apple Watch

Input

Apple Watch Nike Edition
Black
25000
WatchOS

Output

Apple Watch Nike Edition is an Apple Watch

Submit your solution

java