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

A. Create an abstract class named Rental that is to be used with a snow sports r

ID: 3571844 • Letter: A

Question

A. Create an abstract class named Rental that is to be used with a snow sports rental shop. The Rental class must have the properties of newModel which takes on the type boolean, and rentalCost which takes on the type double, and rentalNumberwhich is an identification number as an long integer.These member variables must all be private!

It also must include the following member functions:

1. equals() which returns true if two Rental objects have the same rentalNumber.

2. all of the appropriate get/set methods for each of the above member variables. Make sure to have data validation done on the set methods to prevent invalid/illegal values from being passed into the member variables. (Example: rentalCost should not be allowed to be negative).

3. include an abstract method named lateCharge, that will only be implemented in child classes that inherit the Rental class.

B. Create three children classes that inherit the Rental class, named Ski, Snowboard, and SnowMobile.

The Ski class should have one private member variable named size as an integer that will be used to store the size of the ski in centimeters. Implement the get/set method for this member variable. The abstract method in the Rental class, named lateChargemust be implemented to charge a late charge of 10% of the rental cost. Be sure to include a method named toString to output the data stored in the member variables for this class.

The Snowboard class should have two private member variable named size as an integer that will be used to store the size of the snowboard in centimeters, and another member variable named freestyle as a boolean (true if the snowboard is a freestyle/tricks board, or false if it is not a freestyle board). Implement the get/set methods for these member variables. The abstract method in the Rental class, named lateCharge must be implemented to charge a late charge of 20% of the rental cost. Be sure to include a method named toString to output the data stored in the member variables for this class.

The SnowMobile class should have two private member variable named capacity as an integer that will be used for storing the seating capacity of the snowmobile, and another member variable named vin as a string that stores the snowmobile vin number. Implement the get/set methods for these member variables. The abstract method in the Rental class, named lateCharge must be implemented to charge a late charge of (20+capacity*5)% of the rental cost. Be sure to include a method named toString to output the data stored in the member variables for this class.

C. Create JUnitTest to test each implemented method in the Ski, Snowboard, and SnowMobile classes. The list below is the minimums for the test cases for each of the child classes:

Ski:

1. equals() method

2. newModel ( test get and set )

3. rentalCost ( test get and set )

4. rentalNumber ( test get and set )

5. size ( test get and set )

6. lateCharge - make sure it adheres to the specifications above.

7. toString ( test toString method )

A total of 11 tests for Ski class ( tests 1-4 are actually for the Rental class, and will not need to be repeated for Snowboard and SnowMobile class test )

Snowboard:

1. size ( test get and set )

2. freestyle ( test get and set )

3. lateCharge - make sure it adheres to the specifications above.

4. toString ( test toString method )

A total of 6 tests for Snowboard class

SnowMobile:

1. capacity ( test get and set )

2. vin ( test get and set )

3. lateCharge - make sure it adheres to the specifications above.

4. toString ( test toString method )

A total of 6 tests for SnowMobile class

Explanation / Answer

public abstract class Rental {

   private boolean newModel;
   private double rentalCost;
   private long rentalNumber;

   /**
   * @return the newModel
   */
   public boolean isNewModel() {
       return newModel;
   }

   /**
   * @return the rentalCost
   */
   public double getRentalCost() {
       return rentalCost;
   }

   /**
   * @return the rentalNumber
   */
   public long getRentalNumber() {
       return rentalNumber;
   }

   /**
   * @param newModel
   * the newModel to set
   */
   public void setNewModel(boolean newModel) {
       this.newModel = newModel;
   }

   /**
   * @param rentalCost
   * the rentalCost to set
   */
   public void setRentalCost(double rentalCost) {
       if (rentalCost < 0)
           return;
       else
           this.rentalCost = rentalCost;
   }

   /**
   * @param rentalNumber
   * the rentalNumber to set
   */
   public void setRentalNumber(long rentalNumber) {
       if (rentalNumber < 0)
           return;
       else
           this.rentalNumber = rentalNumber;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#equals(java.lang.Object)
   */
   @Override
   public boolean equals(Object obj) {
       // TODO Auto-generated method stub
       if (obj instanceof Rental) {
           Rental rental = (Rental) obj;
           if (rental.rentalNumber == this.rentalNumber)
               return true;
           else
               return false;

       } else {

           return false;
       }

   }

   public abstract double lateCharge();

}

public class Ski extends Rental {

   private int size;

   /**
   * @return the size
   */
   public int getSize() {
       return size;
   }

   /**
   * @param size
   * the size to set
   */
   public void setSize(int size) {
       this.size = size;
   }

   @Override
   public double lateCharge() {
       // TODO Auto-generated method stub
       return getRentalCost() * 0.1;

   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Ski [getSize()=" + getSize() + ", lateCharge()=" + lateCharge()
               + ", isNewModel()=" + isNewModel() + ", getRentalCost()="
               + getRentalCost() + ", getRentalNumber()=" + getRentalNumber()
               + "]";
   }

}

public class Snowboard extends Rental {

   private int size;
   private boolean freestyle;

   /**
   * @return the size
   */
   public int getSize() {
       return size;
   }

   /**
   * @return the freestyle
   */
   public boolean isFreestyle() {
       return freestyle;
   }

   /**
   * @param size
   * the size to set
   */
   public void setSize(int size) {
       this.size = size;
   }

   /**
   * @param freestyle
   * the freestyle to set
   */
   public void setFreestyle(boolean freestyle) {
       this.freestyle = freestyle;
   }

   @Override
   public double lateCharge() {
       // TODO Auto-generated method stub
       return getRentalCost() * 0.2;

   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Snowboard [getSize()=" + getSize() + ", isFreestyle()="
               + isFreestyle() + ", lateCharge()=" + lateCharge()
               + ", isNewModel()=" + isNewModel() + ", getRentalCost()="
               + getRentalCost() + ", getRentalNumber()=" + getRentalNumber()
               + "]";
   }

}

public class SnowMobile extends Rental {

   private int capacity;
   private String vin;

   /**
   * @return the capacity
   */
   public int getCapacity() {
       return capacity;
   }

   /**
   * @return the vin
   */
   public String getVin() {
       return vin;
   }

   /**
   * @param capacity
   * the capacity to set
   */
   public void setCapacity(int capacity) {
       this.capacity = capacity;
   }

   /**
   * @param vin
   * the vin to set
   */
   public void setVin(String vin) {
       this.vin = vin;
   }

   @Override
   public double lateCharge() {
       // TODO Auto-generated method stub
       int val = 20 + capacity * 5;
       return getRentalCost() * (val / 100);

   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "SnowMobile [getCapacity()=" + getCapacity() + ", getVin()="
               + getVin() + ", lateCharge()=" + lateCharge()
               + ", isNewModel()=" + isNewModel() + ", getRentalCost()="
               + getRentalCost() + ", getRentalNumber()=" + getRentalNumber()
               + "]";
   }

}

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