Graderpractice for programmers

Back to 254275 OOP Lab 5-10

Q14. Add isBudget method

Problem

Reuse your Watch class from question 3. Add a method named isBudget that returns true if the watch is less than 1000 baht (0-999).

Test code:


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

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

        if (w.isBudget()) {
            System.out.println(w.getName() + " is under 1000 baht");
        }
        else {
            System.out.println(w.getName() + " is too expensive");
        }
    }

    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

Casio Analogue
Metal
650

Output

Casio Analogue is under 1000 baht

Submit your solution

java