Graderpractice for programmers

Back to 254275 OOP - Labs 6-10 Review

4. Create a subclass

Problem

A fighter plane is an aeroplane designed for military combat. A fighter can carry up to a maximum weight of weapons. Create the Fighter class as a subclass of Aeroplane, with an extra field for "maximumWeaponsWeight".

Test code:

class Task4 {

    public static void main(String[] args) {
        Aeroplane ap = input();
        System.out.print("The " + ap.getModel() + " has ");
        System.out.print(ap.getEngines() + " engines and ");
        System.out.println(ap.getSeats() + " seats");
    }

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

Examples

Input

Lockheed Martin F-35 Lightning II
1
1
1100

Output

The Lockheed Martin F-35 Lightning II has 1 engines and 1 seats

Submit your solution

java