Graderpractice for programmers

Back to 254275 OOP - Labs 6-10 Review

5. Create subclass NetworkPrinter

Problem

NetworkPrinter is a subclass of Printer. NetworkPrinter has a string member named ipAddress. Write the NetworkPrinter class.

Test code:

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

    public static void main(String[] args) {
        NetworkPrinter np = input();

        System.out.println(np.getFullName() + " has the IP address " + np.getIPAddress());
    }

    private static NetworkPrinter 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());
        String ipAddress = sc.nextLine();
        return new NetworkPrinter(brand, model, type, colour, price, ipAddress);
    }
}

Examples

Input

HP
Deskjet 5000W
i
C
4200
192.168.0.55

Output

HP Deskjet 5000W has the IP address 192.168.0.55

Submit your solution

java