Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a. Sammy's Seashore Supplies rents beach equipment such as kayaks, canoes, beach chairs, and umbrellas to tourists. In Chapters 3 and 4, you created a

a. Sammy's Seashore Supplies rents beach equipment such as kayaks, canoes, beach chairs, and umbrellas to tourists. In Chapters 3 and 4, you created a Rental class for the company.

Now, make the following change to the class:

  • Currently, a rental price is calculated as $40 per hour plus $1 for each minute over a full hour. This means that a customer who rents equipment for 41 or more minutes past an hour pays more than a customer who waits until the next hour to return the equipment. Change the price calculation so that a customer pays $40 for each full hour and $1 for each extra minute up to and including 40 minutes.

Save the file as Rental.java.

b. In Chapter 4, you modified the RentalDemo class to demonstrate a Rental object. Now, modify that class again as follows:

  • Instantiate three Rental objects, and prompt the user for values for each object. Display the details for each object to verify that the new price calculation works correctly.
  • Create a method that accepts two Rental objects and returns the one with the longer rental time. (If the Rentals have the same time, you can return either object.) Call this method three timesonce with each pair of instantiated Rentalsand display the contract number and time in hours and minutes for each argument as well as the contract number of the longer Rental.

Save the file as RentalDemo.java.

Rental class code:

package SammysMotto;

public class Rental {

// initializing final static variables:

public final static int numberOfMinutes = 60;

public final static int hourlyRental = 40;

// initializing private data members:

private String contractNumber = "A000";

private int numberOfHours;

private int hoursAndMinutes;

private static int price;

public static int mins = 0;

// setting the default constructor:

Rental(){

}

// setting parameterized constructor:

Rental2(String contractNumber, int hoursAndMinutes){

this.contractNumber = contractNumber;

this.hoursAndMinutes = hoursAndMinutes;

}

// Setter and getter methods:

public String getContractNumber() {

return contractNumber;

}

public void setContractNumber (String contractNumber) {

this.contractNumber= contractNumber;

}

public int getHoursAndMinutes() {

return hoursAndMinutes;

}

public int getNumberOfHours() {

return numberOfHours;

}

public int getPrice() {

return price;

}

//Calculating hours, extra minutes and total price of rental:

public static void setHoursAndMinutes (int hoursAndMinutes) {

int mins = hoursAndMinutes;

int hours = 0;

int minutes = 0;

while (mins<60) {

hours= hours + (mins/60);

minutes = mins%60;

mins = mins%60;

}

// printing the rental information and total price:

System.out.println(" Total hours of rent: " + hours);

System.out.println("Remaining minutes of rent: " + minutes);

price = hours* hourlyRental;

System.out.println("Total price of rent: "+ price);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions