Question
Sammys Seashore Supplies rents beach equipment such as kayaks, canoes, beach chairs, and umbrellas to tourists. In Chapters 3 and 4, you created a Rental
Sammys 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.
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 instan- tiated 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.
--------------------------------------------------------------------------------------------------------------------------------
/*Sammys Rental Price With Methods*/
import java.util.*;
public class SammyRentalPriceWithMethods
{
public static void main(String args[]){
int rentalTime = RentalTimeInput();
Motto();
computeTime(rentalTime);
}
//rental time computation
public static int RentalTimeInput(){
int time;
Scanner scanner = new Scanner(System.in);
System.out.println("Please enter the rental time (in minutes): ");
time = scanner.nextInt();
return time;
}
//motto
public static void Motto(){
System.out.println("*************************************************");
System.out.println("*Sammys makes it fun in the sun.*");
System.out.println("*************************************************");
}
//compute hours, minutes, and display details
public static void computeTime(int rentalTime){
int hoursRented = rentalTime/60;
int minutesRented = rentalTime - hoursRented*60;
final int HOURLY_RATE = 40;
double price;
if (minutesRented>=40){
price= hoursRented*HOURLY_RATE+40;
System.out.println("Hours: " + hoursRented);
System.out.println("Minutes: " + minutesRented);
System.out.println("Total Price: $" + price);
}
else if(minutesRented<40){
price = hoursRented * HOURLY_RATE + minutesRented;
System.out.println("Hours: " + hoursRented);
System.out.println("Minutes: " + minutesRented);
System.out.println("Total Price: $" + price);
}
}
}
--------------------------------------------------------------------------------------------------------------------------
/*Rental*/
import java.util.*;
public class Rental{
public final static int MINUTES_IN_HOUR = 60;
public final static int HOURLY_RATE = 40;
private int hoursRented, minutesRented, price;
private String contractNumber="A001";
private int hoursAndMinutes;
public void setContractNumber(String number){
contractNumber = number;
}
//default constructor
Rental(){
}
//parameterized constructor
Rental (String contractNumber, int hoursAndMinutes){
this.contractNumber=contractNumber;
this.hoursAndMinutes=hoursAndMinutes;
}
//set methods
public void setHoursandMinutes(int rentalTime){
hoursRented = rentalTime/MINUTES_IN_HOUR;
minutesRented = rentalTime - hoursRented * MINUTES_IN_HOUR;
price = hoursRented * HOURLY_RATE + minutesRented;
}
//get methods
public String getContractNumber(){
return contractNumber;
}
public int getPrice(){
return price;
}
public int gethoursRented(){
return hoursRented;
}
public int getminutesRented(){
return minutesRented;
}
}
--------------------------------------------------------------------------------------
/* Rental Demo*/
import java.util.*;
public class RentalDemo{
public static String getContractNumber(){
String contractNum;
Scanner scan = new Scanner(System.in);
System.out.println("Please enter contract number:");
contractNum = scan.nextLine();
return contractNum;
}
public static void main(String args[]){
String contractNumber = getContractNumber();
int numberMinutes = SammyRentalPriceWithMethods.RentalTimeInput();
SammyRentalPriceWithMethods.Motto();
SammyRentalPriceWithMethods.computeTime(numberMinutes);
Rental.setContractNumber(contractNumber);
Rental.setHoursandMinutes(numberMinutes);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started