a. Sammy’s Seashore Supplies rents beach equipment such as kayaks, canoes, beach
ID: 3723494 • Letter: A
Question
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.
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. InChapter4,youmodifiedtheRentalDemoclasstodemonstrateaRentalobject.
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 times—once with each pair of instan- tiated Rentals—and 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.
Explanation / Answer
Answer :
a) For the given Task,
Rental.Java. :
import java.util.*;
public class Rental{
// utility function to calculate price for renting an
// equipment for 'time_in_minutes' minutes
public static int calculatePrice(int time_in_minutes){
int hours = time_in_minutes/60;
int price = hours * 40;
int minutes_past_lastHour = time_in_minutes%60;
int max_overHour_charges = Math.min(40, minutes_past_lastHour);
price = price + max_overHour_charges;
return price;
}
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the time(in minutes) for which you want to rent an equipment : ");
int min = keyboard.nextInt();
int price = calculatePrice(min);
System.out.println("You should pay $"+price);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.