Graderpractice for programmers

Back to 254275 OOP - Labs 6-10 Review

2. Add the toString method

Problem

Add a new method to the Aeroplane named toString.

Test code:

class Task2 {

    public static void main(String[] args) {
        Aeroplane ap = input();
        System.out.println(ap.toString());
    }

    public static Aeroplane input() {
        Scanner sc = new Scanner(System.in);
        String model = sc.nextLine();
        int engines = Integer.parseInt(sc.nextLine());
        int seats = Integer.parseInt(sc.nextLine());
        return new Aeroplane(model, engines, seats);
    }
}

Examples

Input

Airbus A320
2
180

Output

Airbus A320 (180 seats)

Submit your solution

java