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

i need 3rd answer 1)For main class of car has attributes fuel tank capacity, whe

ID: 3823557 • Letter: I

Question

i need 3rd answer

1)For main class of car has attributes fuel tank capacity, whether the car has 4 wheels or not, no of doors create sub class called small car with attributes miles driven, make, model using getters and setters must have two constructors apply exception handling write test cases happy and worst path with UML diagram representation.

2)Write abstract class for question1

3)Write polymorphism using for loop for question 2 implement getters and setters where write entire code in main method but not in car or small car.

Explanation / Answer

//Find here for Car class

package com.car;

/**
*
* @author Niraj Kumar
*
*This is abstract class so can't be instantiated
*/
public abstract class Car {
  
   int fuelCapacity;
   boolean isFourWheeler;
   int numOfDoors;
  
   Car(){
       this.fuelCapacity=10;//default value
       this.isFourWheeler=true;//default value
       this.numOfDoors=4;//default value
   }
  
   Car(int fuelCapacity,boolean isFourWheeler,int numOfDoors){
       this.fuelCapacity=fuelCapacity;
       this.isFourWheeler=isFourWheeler;
       this.numOfDoors=numOfDoors;
   }
  
  
   //This method used to display car features
   public void carDescription(){
       System.out.println("This is big card with below features....");
      
       System.out.println("fuelCapacity: "+fuelCapacity);
       System.out.println("isFourWheeler: "+isFourWheeler);
       System.out.println("numOfDoors: "+numOfDoors);
   }
  

}

//Find here for SmallCar class

package com.car;

/**
*
* @author Niraj Kumar
*
* This class is sub class of Car inherits parent feature of super class Car and overrided method carDescription
*
*/
public class SmallCar extends Car{
  
   int milesDriven;
   String model;
  
   SmallCar(String model, int milesDriven,int fuelCapacity,boolean isFourWheeler,int numOfDoors){
       super(fuelCapacity,isFourWheeler,numOfDoors);
       this.milesDriven = milesDriven;
       this.model = model;
   }
  
SmallCar(String model, int milesDriven){
       this.model=model;
       this.milesDriven=milesDriven;
   }
   public int getMilesDriven() {
       return milesDriven;
   }
   public void setMilesDriven(int milesDriven) {
       this.milesDriven = milesDriven;
   }
   public String getModel() {
       return model;
   }
   public void setModel(String model) {
       this.model = model;
   }
  
   //This is overrided method from Car used to display car fetures
   @Override
   public void carDescription(){
       System.out.println("This is Small card with below features....");
      
       System.out.println("fuelCapacity: "+fuelCapacity);
       System.out.println("isFourWheeler: "+isFourWheeler);
       System.out.println("numOfDoors: "+numOfDoors);
       System.out.println("milesDriven: "+milesDriven);
       System.out.println("model: "+model);
  
   }

}


//Find here for TestCar class

package com.car;

public class TestCar {

   public static void main(String[] args) {
      
       //creates instance of SmallCar and setting the properties of SmallCar only
       SmallCar car1 = new SmallCar("BMW",6000);
      
       //creates instance of SmallCar and setting properies of both class Car and SmallCar
       SmallCar car2 = new SmallCar("Mercedeze",10000,70,true,4);
      
       //creates instance of SmallCar and setting the properties of SmallCar only in instance variable of Car
       //Here polymorphism takes place
       Car car3 = new SmallCar("Toyota",5000);
      
       //creates instance of SmallCar and setting properies of both class Car and SmallCar in instance variable of Car
       //Here polymorphism takes place
       Car car4 = new SmallCar("Ferari",20000,80,true,4);
      
       car1.carDescription();
       car2.carDescription();
       car3.carDescription();
       car4.carDescription();
   }
  
}


//Find here for outputs

This is Small card with below features....
fuelCapacity: 10
isFourWheeler: true
numOfDoors: 4
milesDriven: 6000
model: BMW
This is Small card with below features....
fuelCapacity: 70
isFourWheeler: true
numOfDoors: 4
milesDriven: 10000
model: Mercedeze
This is Small card with below features....
fuelCapacity: 10
isFourWheeler: true
numOfDoors: 4
milesDriven: 5000
model: Toyota
This is Small card with below features....
fuelCapacity: 80
isFourWheeler: true
numOfDoors: 4
milesDriven: 20000
model: Ferari