Graderpractice for programmers

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

4. 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:

class MT2bTask4 {
    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

Input

G-SHOCK GA-110
Black
3150

Output

G-SHOCK GA-110 is too expensive

Submit your solution

java