Graderpractice for programmers

Back to 254275 OOP - Labs 6-10 Review

6. Add method for detecting same IP address

Problem

Reuse your NetworkPrinter class from question 5. Add a method named isNotSameIPAddress that takes another network printer and returns true if the 2 printers do not have the same IP address.

Test code:

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

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

        System.out.print(np1.getFullName() + " and " + np2.getFullName());
        if (np1.isNotSameIPAddress(np2)) {
            System.out.println(" can be on the same network");
        }
        else {
            System.out.println(" can not be on the same network");
        }
    }

    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

Canon
H2000
t
c
7500
10.10.99.100
HP
Deskjet 1110
i
c
3500
10.10.99.101

Output

Canon H2000 and HP Deskjet 1110 can be on the same network

Input

Canon
H2000
t
c
7500
10.10.99.100
HP
Deskjet 1110
i
c
3500
10.10.99.100

Output

Canon H2000 and HP Deskjet 1110 can not be on the same network

Submit your solution

java