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

Using java, think about the relationships among all these classes (Car companies

ID: 3682331 • Letter: U

Question

Using java, think about the relationships among all these classes (Car companies, models, cars, miles per gallon...). What methods should be common to each, and which should be different. In a hierarchy, the top classes should be more broad while child classes introduce methods and variables more specific to it. You will want to demonstrate this, rather than just having generic println methods. Could you please add methods to demonstrate the connections?

/* Aidan Acosta

* 2/20/16

* Class Hierarchy

*/

public class Ford

{

int companyValue = 0;

public static int methodFord()

{

System.out.println("Ford Motor Company");

return 1;

}

}

class Lincoln extends Ford

{

   int staffNum = 0;

public String methodLincoln()

   {

   System.out.println("Lincoln: Car company within Ford");

   return "2";

   }

}

class SUV extends Lincoln

{

   int numberOfModels = 0;

public String methodSUV()

   {

   System.out.println("SUV: Car type within Lincoln");

   return "3";

   }

}

class Navigator extends SUV

{

int weight = 0;

public static String methodNavigator()

{

System.out.println("Navigator: Model within car type");

return "4";

}

}

class MPG extends Navigator

{

int mpg = 0;

public static String methodMPG()

{

System.out.println("MPG: Characteristic of a model");

return "5";

}

}

/*

* Aidan Acosta

* 2/20/16

* Hierarchy Driver

*/

public class Driver

{

   public static void main(String args[])

   {

   try

   {

   Navigator e = new Navigator();

   e.methodFord();

   e.methodLincoln();

   e.methodSUV();

   e.methodNavigator();

   MPG.methodMPG();

   }

   catch (Exception e)

   {

   // TODO: handle exception

   }

   }

}

Explanation / Answer

public class Ford

{

   int companyValue = 0;

   public static int methodFord()

   {

       System.out.println("Ford Motor Company");

       return 1;

   }

}

class Lincoln extends Ford

{

   int staffNum = 0;

   public String methodLincoln()

   {
       methodFord(); // calling parent method
       System.out.println("Lincoln: Car company within Ford");

       return "2";

   }

}

class SUV extends Lincoln

{
   int numberOfModels = 0;

   public String methodSUV()

   {
       methodLincoln(); // calling Lincoln method, inherited by SUV
       System.out.println("SUV: Car type within Lincoln");

       return "3";

   }

}

class Navigator extends SUV

{

   int weight = 0;

   public static String methodNavigator()

   {
      
       System.out.println("Navigator: Model within car type");

       return "4";

   }

}

class MPG extends Navigator

{

   int mpg = 0;

   public static String methodMPG()

   {
       methodNavigator(); // calling Navigator method
       System.out.println("MPG: Characteristic of a model");

       return "5";

   }

}

/*
*
* Aidan Acosta
*
* 2/20/16
*
* Hierarchy Driver
*/

class Driver

{

   public static void main(String args[])

   {

       try

       {

           Navigator e = new Navigator();

           Ford.methodFord();

           e.methodLincoln();

           e.methodSUV();

           Navigator.methodNavigator();

           MPG.methodMPG();

       }

       catch (Exception e)

       {

           // TODO: handle exception

       }

   }

}

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