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

You are in the rental car business. Create a class called RentalCar that include

ID: 673136 • Letter: Y

Question

You are in the rental car business. Create a class called RentalCar that includes a string type for the car type (e.g., passenger car, van, truck, etc.) and a double field for the rental rate per day. Include get methods for these fields and a constructor that requires a string argument representing the car type. The constructor sets the room rate as follows – cars $49.99 per day, vans $69.99 per day, trucks $89.99 per day. Create an extended class, Luxury, whose constructor requires a car type and adds $20 per day to the appropriate rental rate for each type of vehicle. Write an application named UseRentalCar which creates an object of each class. Demonstrate that all methods work as they should.

Explanation / Answer

package mani;

public class UseRentalCar {

   /**
   * @param args
   */
   public static void main(String[] args) {
       RentalCar r=new RentalCar("car");
       System.out.println("Cartype: "+r.getType()+" Rentalrate: "+r.getRentalRate());
       Luxury l=new Luxury("truck");
       System.out.println("Cartype: "+l.getType()+" Rentalrate: "+l.getRentalRate());
   }

}

package mani;
public class Luxury extends RentalCar
{
public Luxury(String type){
super(type);
super.setRental(20);
}

}

package mani;

public class RentalCar {
String carType;
double rentalRate;
public RentalCar(String type){
   carType=type;
   if(carType.equalsIgnoreCase("car")){
       rentalRate=49.99;
   }else if(carType.equalsIgnoreCase("van")){
       rentalRate=69.99;
   }else if(carType.equalsIgnoreCase("truck")){
       rentalRate=89.99;
   }
  
}
public String getType(){
   return carType;
  
}   
public void setRental(double r){
   this.rentalRate=this.rentalRate+r;
}
public double getRentalRate(){
   return rentalRate;
}
}

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