Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

8. [10] Interfaces. There is an abstract class named Jet. This will be the paren

ID: 3904850 • Letter: 8

Question

8. [10] Interfaces. There is an abstract class named Jet. This will be the parent class of a number of child classes describing different types of Jets. The declaration for Jet is: public abstract class Jet f For consistency, all of the child classes of Jet must have the same interface. The interface will include 4 methods: 1. setHeading which takes a double parameter called newHeading and has no return value 2. setPower which takes an integer parameter named engine and a double parameter named powerlevel. It also returns nothing. 3. readAltimeter which takes no parameters but returns an integer. 4. readHeading which takes no parameters and returns an integer The interface is named FlightControls. Write the FlightControls interface below. Rewrite the declaration for Jet above to use the new FlightControls interface. Write a declaration for the class Falcon50 that inherits from Jet.

Explanation / Answer

Following is the detail implementation. For example purpose, child1 and child2 class contain only 2/2 methods. One can implement all four methods.

interface FlightControls
{
/* compiler will treat them as:
* public abstract void method1();
* public abstract void method2();
*/
public void setHeading(double newHeading);
   public void setPower(int engine, double powerLevel);
   public int readAltimeter();
   public int readHeading();
}


public abstract class jet implements FlightControls
{

//for Example one method is declared, you can add methods from interface
public void setHeading(double newHeading)
{
   System.out.println("Implementation of SetHeading");
   }
}

class Child1 extends jet
{

   public void setHeading(double newHeading)
{
   System.out.println("Implementation of SetHeading");
   }
      
       public void setPower(int engine, double powerLevel)
{
   System.out.println("Implementation of setPower");
   }
  
}
class Child2 extends jet
{

public void readAltimeter()
{
int a;
   System.out.println("Implementation of readAltimeter");
   return a;
   }
  
   public void readHeading()
{
int a;
   System.out.println("Implementation of readHeading");
   return a;
   }

}


class Falcon extends jet
{

jet j;

j=new Child1();
j.setHeading(180.00);


j=new Child2();
System.out.println("Altimetere Reading: "+j.readAltimeter()+" %");

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote