Add a user-defined exception that can be thrown by one of the…
Question Answered step-by-step Add a user-defined exception that can be thrown by one of the… Add a user-defined exception that can be thrown by one of the methods as part of the validation or error checking. The main method should then create an instance of the class and call the method in such a way that the exception is thrown (e.g. invalid input or state of the system). Add a screenshot of successfully running that program. import java.util.Scanner;class Parent_Aircraft{ // Attributes int numberOfEngines; float length; float height; // Constructor Parent_Aircraft(int numberOfEngines,float length,float height) { this.numberOfEngines=numberOfEngines; this.length=length; this.height=height; } // we will override this method in child classes of this Parent_Aircraft class public void fly() { System.out.println(“All Aircrafts Fly”); }}// Child Class Helicopterclass Helicopter extends Parent_Aircraft{ // Attributes float mainRotorBladeSize; float tailRotorBladeSize; // Constructor Helicopter(int numberOfEngines,float length,float height,float mainRotorBladeSize,float tailRotorBladeSize) { super(numberOfEngines,length,height); this.mainRotorBladeSize=mainRotorBladeSize; this.tailRotorBladeSize=tailRotorBladeSize; } // we will overload this method by supplying one argument in method public void hovering(){ System.out.println(“Helicopter Hovers”); } // overloaded method // same signature different number of argument public void hovering(int n){ System.out.println(“Helicopter has “+n+” wings.”); System.out.println(“Helicopter Hovers”); } // override public void fly() { System.out.println(“Helicopter Fly”); }}// Child Class Planeclass Plane extends Parent_Aircraft{ // Attributes float wingSpan; // Constructor Plane(int numberOfEngines,float length,float height,float wingSpan) { super(numberOfEngines,length,height); this.wingSpan=wingSpan; } public void gliding(){ System.out.println(“Plane Glides”); } }public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // Creating Instance of Child Classes // create object of child class with reference to parent class Helicopter helicopter = new Helicopter(2, 50, 30, 50, 40); helicopter.fly(); // this should print overrided method in helicopter class helicopter.hovering(); helicopter.hovering(3); // this should print overloaded method in helicopter class Plane plane = new Plane(4, 100, 50, 80); plane.fly(); // this should call Parent_Aircraft’s method fly plane.gliding(); sc.close(); }} Computer Science Engineering & Technology Java Programming CMIS 242 Share QuestionEmailCopy link Comments (0)


