Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I'm working on this problem: a. Sammy's Seashore Supplies rents beach equipment such as kayaks, canoes, beach chairs, and umbrellas to tourists. In Chapters

Hi,

I'm working on this problem:

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.

Create a zip file of the .java file(s) and submit the assignment.

I'll paste what I have for both files so far, the problem I'm having is that I can't seem to get the RentalDemo.java to compile and I'm unsure what I've done wrong.

public class Rental { public final static int minutesInHour = 60; public final static int hourlyRentalRate = 40; private String contractNumber; private int hoursRental; private int hoursAndMinutes; private static int price; public static int minutes; Rental() { } Rental(String contractNumber, int hoursAndMintes, int price) { } public String getContractNumber() { return contractNumber; } public void setPrice() { if (hoursAndMinutes > 60) price = (hoursRental * hourlyRentalRate) + 40; else price = (hoursRental * hourlyRentalRate) + hoursAndMinutes; } public void setHoursAndMinutes() { hoursRental = minutes/minutesInHour; hoursAndMinutes = minutes%minutesInHour; } public int getHoursRental() { return hoursRental; } public int getPrice() { return price; } }

import java.util.Scanner; public class RentalDemo { public static void main(String[] args) { int minutes = 0; String contractNumber; int minutes1; int minutes2; Rental rentalOne = new Rental(); Rental rentalTwo = new Rental(); Rental rentalThree = new Rental(); System.out.println("Rental One"); rentalOne.setContractNumber(getContractNumber()); rentalOne.setMinutes(getMinutes()); System.out.println("Rental Two"); rentalTwo.setContractNumber(getContractNumber()); rentalTwo.setMinutes(getMinutes()); System.out.println("Rental Three"); rentalThree.setContractNumber(getContractNumber()); rentalThree.setMinutes(getMinutes()); displayDetails(rentalOne); displayDetails(rentalTwo); displayDetails(rentalThree); Rental largerRental = new Rental(); largerRental = getLarger(rentalOne, rentalTwo); System.out.println(" " + "The larger rental contract number is " + largerRental.getContractNumber() + " with " + largerRental.getHoursAndMinutes() + " minutes."); } private static int getHoursAndMinutes() { return 0; } public static String getContractNumber() { String num; Scanner input = new Scanner(System.in); System.out.print(" Enter the contract number: "); num = input.nextLine(); return num; } public static int getMinutes() { int minutes; Scanner input = new Scanner(System.in); System.out.print("Enter the number of minutes rented: "); minutes = input.nextInt(); return minutes; } public static void displayDetails(Rental r) { System.out.println(" Contract number " + r.getContractNumber()); System.out.println("Was rented for " + r.getHoursRental() + "hours and " + r.getHoursAndMinutes() + " minutes at a rate of $40, the price is " + r.getPrice()); System.out.println("This is a large Rental: " + r.isLarger()); } public static Rental getLarger(Rental rentalOne, Rental rentalTwo) { Rental largerRental = rentalOne; if((rentalOne.getHoursRental() * 60 + rentalTwo.getHoursAndMinutes()) > (rentalOne.getHoursRental() * 60 + rentalTwo.getHoursAndMinutes())); { largerRental = rentalOne; } return largerRental; } }

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

Recommended Textbook for

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions