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

JAVA Write a super class Vehicle which has the following--- Attributes: (1) whee

ID: 3690849 • Letter: J

Question

JAVA

Write a super class Vehicle which has the following--- Attributes: (1) wheel (number of wheel) and (2) seat (number of seat). Constructor: which sets the value of wheel and seat. Methods: (1) getWheel()—returns the number of wheel (2) getSeat()—returns the number of seat (3) printDetails()—This is an abstract method which prints the details of the vehicle. For example, if it is a car type vehicle, it will print number of seat, number of wheel, number of door, and number of window. In contrast, if it is a motorcycle, this method will print number of seat, number of wheel, and number of helmet. Write a subclass Car which has the following-- Attributes: (1) door (number of door) and (2) window (number of window). Constructor: which sets the value of door, window, wheel and seat. Methods: (1) getWindow()—returns the number of window (2) getDoor()—returns the number of door (3) Implementation of the printDetails() method. Write a subclass Motorcycle which has the following-- Attributes: (1) helmet (number of helmet) Constructor: which sets the value of helmet, wheel and seat. Methods: (1) getHelmet()—returns the number of helmet (2) Implementation of the printDetails() method. Write a Demo class which creates objects of Vehicle (does it work?), Car, and Motorcycle classes and call the corresponding methods.

Explanation / Answer

class Vehical
{
   public int wheel, seats;

/*   public Vehical(int w, int s)
   {
       wheel=w;
       seats=s;
   }
*/
   public int getWheel()
   {
       return wheel;
   }

   public int getseats()
   {
       return seats;
   }

   public void printDetails(){}
}

class Car extends Vehical
{
   public int door, window;
  
   public Car(int d, int w, int wh, int s)
   {
       door=d;
       window=w;
       wheel=wh;
       seats=s;
   }

   public int getDoor()
   {
       return door;
   }

   public int getWindow()
   {
       return window;
   }

   public void printDetails()
   {
       System.out.println(seats);
       System.out.println(wheel);
       System.out.println(door);
       System.out.println(window);
   }
}

class Motorcycle extends Vehical
{
   public int helmet;

   public Motorcycle(int h, int s, int w)
   {
       helmet = h;
       seats=s;
       wheel=w;
   }

   public void printDetails()
   {
       System.out.println(seats);
       System.out.println(wheel);
      
       System.out.println(helmet);
   }
}

class Demo
{
   public static void main(String args[])
   {
//       Vehical oo=new Vehical(2,2);
       Car o=new Car(4,4,4,4);
       Motorcycle o1=new Motorcycle(2, 2, 2);

       o.printDetails();
       o1.printDetails();
   }
}