Graderpractice for programmers

Back to 254275 OOP - Labs 6-10 Review

1. Create Printer class

Problem

Write a class named Printer with members for brand, model, type (l=laser, i=inkject, t=thermal), colour (true or false) and price. The class needs a constructor and get methods for each member.

Test code:

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

    public static void main(String[] args) {
        Printer p = input();

        System.out.println("Brand: " + p.getBrand());
        System.out.println("Model: " + p.getModel());
        System.out.println("Type: " + p.getType());
        System.out.println("Colour: " + p.isColour());
        System.out.println("Price: " + p.getPrice() + " baht");
    }

    private static Printer input() {
        String brand = sc.nextLine();
        String model = sc.nextLine();
        char type = sc.nextLine().charAt(0);
        boolean colour = sc.nextLine().equalsIgnoreCase("C");
        int price = Integer.parseInt(sc.nextLine());
        return new Printer(brand, model, type, colour, price);
    }
}

Examples

Input

HP
1100W
l
c
5800

Output

Brand: HP
Model: 1100W
Type: l
Colour: true
Price: 5800 baht

Submit your solution

java