Question
Sammys Seashore Supplies rents beach equipment to tourists. In previous chapters, you have developed a class that holds equipment rental information and an application that
Sammys Seashore Supplies rents beach equipment to tourists. In previous chapters, you have developed a class that holds equipment rental information and an application that tests the methods using four objects of the class. Now modify the Rental and RentalDemo classes as follows: Modify the method that sets the contract number in the Rental class so that if the argument passed to the method is not a four-character String that starts with a letter followed by three digits, then the contract number is forced to A000. If the initial letter in the contract number is not uppercase, force it to be so. Add a contact phone number field to the Rental class. Add a set method for the contact phone number field in the Rental class. Whether the user enters all digits or any combination of digits, spaces, dashes, dots, or parentheses for a phone number, store it as all digits. For example, if the user enters (920) 872-9182, store the phone number as 9208729182. If the user enters a number with fewer or more than 10 digits, store the number as 0000000000. Add a get method for the phone number field. The get method returns the phone number as a String constructed as follows: parentheses surround a three-digit area code, followed by a space, followed by the three-digit phone exchange, followed by a hyphen, followed by the last four digits of the phone number. Modify the RentalDemo program so that besides the contract number and minutes, the program also prompts the user for and retrieves a contact phone number for each of the sample objects. Display the phone number along with the other Rental details. Test the RentalDemo application to make sure it works correctly with valid and invalid contract and phone numbers. Save the files as Rental.java and RentalDemo.java. class Rental { public static final int MINUTES_IN_HOUR = 60; public static final double HOUR_RATE = 40.00; private String contractNumber; private int hours; private int extraMinutes; private double price; public Rental(String num, int minutes) { setContractNumber(num); setHoursAndMinutes(minutes); } public Rental() { this("A000", 0); } public void setContractNumber(String num) { contractNumber = num; } public void setHoursAndMinutes(int minutes) { hours = minutes / MINUTES_IN_HOUR; extraMinutes = minutes % MINUTES_IN_HOUR; if(extraMinutes <= HOUR_RATE) price = hours * HOUR_RATE + extraMinutes; else price = hours * HOUR_RATE + HOUR_RATE; } public String getContractNumber() { return contractNumber; } public int getHours() { return hours; } public int getExtraMinutes() { return extraMinutes; } public double getPrice() { return price; } } import java.util.Scanner; public class RentalDemo { public static void main(String[] args) { String contractNum; int minutes; contractNum = getContractNumber(); minutes = getMinutes(); while (minutes < 60 || minutes > 7200) minutes = getMinutes(); Rental r1 = new Rental(contractNum, minutes); contractNum = getContractNumber(); minutes = getMinutes(); while (minutes < 60 || minutes > 7200) minutes = getMinutes(); Rental r2 = new Rental(contractNum, minutes); contractNum = getContractNumber(); minutes = getMinutes(); while (minutes < 60 || minutes > 7200) minutes = getMinutes(); Rental r3 = new Rental(contractNum, minutes); displayCoupon(r1); displayDetails(r1); displayDetails(r2); displayDetails(r3); System.out.println("Of Contract #" + r1.getContractNumber() + " with a time of " + r1.getHours() + " hours and " + r1.getExtraMinutes() + " minutes, and Contract #" + r2.getContractNumber() + " with a time of " + r2.getHours() + " hours and " + r2.getExtraMinutes() + " minutes, the one with the longer time is Contract #" + getLongerRental(r1, r2).getContractNumber()); System.out.println("Of Contract #" + r1.getContractNumber() + " with a time of " + r1.getHours() + " hours and " + r1.getExtraMinutes() + " minutes, and Contract #" + r3.getContractNumber() + " with a time of " + r3.getHours() + " hours and " + r3.getExtraMinutes() + " minutes, the one with the longer time is Contract #" + getLongerRental(r1, r3).getContractNumber()); System.out.println("Of Contract #" + r2.getContractNumber() + " with a time of " + r2.getHours() + " hours and " + r2.getExtraMinutes() + " minutes, and Contract #" + r3.getContractNumber() + " with a time of " + r3.getHours() + " hours and " + r3.getExtraMinutes() + " minutes, the one with the longer time is Contract #" + getLongerRental(r2, r3).getContractNumber()); } public static String getContractNumber() { String num; Scanner input = new Scanner(System.in); System.out.print("Enter contract number >> "); num = input.nextLine(); return num; } public static int getMinutes() { int minutes; Scanner input = new Scanner(System.in); System.out.print("Enter minutes >> "); minutes = input.nextInt(); return minutes; } public static void displayDetails(Rental r) { System.out.println(" Contract #" + r.getContractNumber()); System.out.print("For a rental of " + r.getHours() + " hours and " + r.getExtraMinutes()); System.out.printf(" minutes, at a rate of $%.2f",r.HOUR_RATE); System.out.printf(" the price is $%.2f ",r.getPrice()); } public static Rental getLongerRental(Rental r1, Rental r2) { Rental longer = new Rental(); int minutes1; int minutes2; minutes1 = r1.getHours() * Rental.MINUTES_IN_HOUR + r1.getExtraMinutes(); minutes2 = r2.getHours() * Rental.MINUTES_IN_HOUR + r2.getExtraMinutes(); if(minutes1 >= minutes2) longer = r1; else longer = r2; return longer; } public static void displayCoupon(Rental r1) { int loopcount = r1.getHours(); for (int i = 0; i < loopcount; i++){ System.out.println("Coupon good for 10 percent off next rental with your rental of contract number " + r1.getContractNumber() + "."); } } }
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