Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Sammys Seashore Supplies rents beach equipment to tourists. In previous chapters, you have developed a class that holds equipment rental information and an application

2. 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.

Code Before Modification

RentalDemo :

package edu.snhu.it145;

import java.util.Scanner;

public class RentalDemo

{

/**

* @param args

* asks for user input, scans input, sets variable = to input, prints input

* two objects are created

*/

public static void main(String args[])

{

int min;

int min2;

int min3;

int min4 = 0;

int min5 = 0;

int min6 = 0;

String Num;

String Num2;

String Num3;

Scanner scan = new Scanner(System.in);

Scanner scan2 = new Scanner(System.in);

Scanner scan3 = new Scanner(System.in);

Scanner scan4 = new Scanner(System.in);

Scanner scan5 = new Scanner(System.in);//scanner 5

Scanner scan6 = new Scanner(System.in);//scanner 5

int minlim = 60;

System.out.print("Enter contract number: ");

Num = scan.nextLine();

System.out.print("Enter minutes: ");

min = scan.nextInt();

if (min < minlim )

{

System.out.print("Please enter additional minutes to reach at least 1 hour: " + " ");

min4 = scan4.nextInt();

}

if (min + min4 < minlim)

{

System.out.print("Please enter additional minutes to reach at least 1 hour: " + " ");

}

else

{

}

System.out.print("Enter contract number: ");

Num2 = scan2.nextLine();

System.out.print("Enter minutes: ");

min2 = scan2.nextInt();

if (min2 < minlim )

{

System.out.print("Please enter additional minutes to reach at least 1 hour: " + " ");

min5 = scan5.nextInt();

}

if (min2 + min5 < minlim)

{

System.out.print("Please enter additional minutes to reach at least 1 hour: " + " ");

}

else

{

}

System.out.print("Enter contract number: ");

Num3 = scan3.nextLine();

System.out.print("Enter minutes: ");

min3 = scan3.nextInt();

if (min3 < minlim )

{

System.out.print("Please enter additional minutes to reach at least 1 hour: " + " ");

min6 = scan6.nextInt();

}

if (min3 + min6 < minlim)

{

System.out.print("Please enter additional minutes to reach at least 1 hour: " + " ");

}

else

{

}

Rental Rent1 = new Rental(Num, min);

System.out.println("Contract # : " + Rent1.getContractNumber());

System.out.println("For a rental of " + Rent1.getHours() + " hours and " + Rent1.getMinutes() + " minutes, the total price is $" + Rent1.getPrice() + " ");

Rental Rent2 = new Rental(Num2, min2);

System.out.println("Contract # : " + Rent2.getContractNumber());

System.out.println("For a rental of " + Rent2.getHours() + " hours and " + Rent2.getMinutes() + " minutes, the total price is $" + Rent2.getPrice() + " ");

Rental Rent3 = new Rental(Num3, min3);

System.out.println("Contract # : " + Rent3.getContractNumber());

System.out.println("For a rental of " + Rent3.getHours() + " hours and " + Rent3.getMinutes() + " minutes, the total price is $" + Rent3.getPrice() + " ");

//compares 1 and 2

if (Rent1.getPrice() > Rent2.getPrice())

{

System.out.println("Of Contract #" + Rent1.getContractNumber() + " with a time of " + Rent1.getHours() + " hours and " + Rent1.getMinutes() + " minutes, and Contract #" + Rent2.getContractNumber2() + " with a time of " + Rent2.getHours() + " hours and " + Rent2.getMinutes() + " minutes, the one with the longer time is Contract #" + Rent1.getContractNumber() + " ");

}

else

{

System.out.println("Of Contract #" + Rent1.getContractNumber() + " with a time of " + Rent1.getHours() + " hours and " + Rent1.getMinutes() + " minutes, and Contract #" + Rent2.getContractNumber2() + " with a time of " + Rent2.getHours() + " hours and " + Rent2.getMinutes() + " minutes, the one with the longer time is Contract #" + Rent2.getContractNumber() + " ");

}

//compares 1 and 3

if (Rent1.getPrice() > Rent3.getPrice())

{

System.out.println("Of Contract #" + Rent1.getContractNumber() + " with a time of " + Rent1.getHours() + " hours and " + Rent1.getMinutes() + " minutes, and Contract #" + Rent3.getContractNumber2() + " with a time of " + Rent3.getHours() + " hours and " + Rent3.getMinutes() + " minutes, the one with the longer time is Contract #" + Rent1.getContractNumber() + " ");

}

else

{

System.out.println("Of Contract #" + Rent1.getContractNumber() + " with a time of " + Rent1.getHours() + " hours and " + Rent1.getMinutes() + " minutes, and Contract #" + Rent3.getContractNumber2() + " with a time of " + Rent3.getHours() + " hours and " + Rent3.getMinutes() + " minutes, the one with the longer time is Contract #" + Rent3.getContractNumber() + " ");

}

if (Rent2.getPrice() > Rent3.getPrice())

{

System.out.println("Of Contract #" + Rent2.getContractNumber() + " with a time of " + Rent2.getHours() + " hours and " + Rent2.getMinutes() + " minutes, and Contract #" + Rent3.getContractNumber2() + " with a time of " + Rent3.getHours() + " hours and " + Rent3.getMinutes() + " minutes, the one with the longer time is Contract #" + Rent2.getContractNumber() + " ");

}

else

{

System.out.println("Of Contract #" + Rent2.getContractNumber() + " with a time of " + Rent2.getHours() + " hours and " + Rent2.getMinutes() + " minutes, and Contract #" + Rent3.getContractNumber2() + " with a time of " + Rent3.getHours() + " hours and " + Rent3.getMinutes() + " minutes, the one with the longer time is Contract #" + Rent3.getContractNumber() + " ");

}

if (min + min4 >= 60)

{

System.out.print("Coupon good for 10% off next rental ");

}

if (min + min4 >= 120)

{

System.out.print("Coupon good for 10% off next rental ");

}

if (min + min4 >= 180)

{

System.out.print("Coupon good for 10% off next rental ");

}

if (min + min4 >= 240)

{

System.out.print("Coupon good for 10% off next rental ");

}

if (min + min4 >= 300)

{

System.out.print("Coupon good for 10% off next rental ");

}

if (min + min4 >= 360)

{

System.out.print("Coupon good for 10% off next rental ");

}

if (min + min4 >= 420)

{

System.out.print("Coupon good for 10% off next rental ");

}

if (min + min4 >= 480)

{

System.out.print("Coupon good for 10% off next rental ");

}

if (min + min4 >= 540)

{

System.out.print("Coupon good for 10% off next rental ");

}

if (min + min4 >= 600)

{

System.out.print("Coupon good for 10% off next rental ");

}

scan.close();

scan2.close();

scan3.close();

}

}

Rental:

package edu.snhu.it145;

public class Rental {

public final static int Minutes = 60;

public final static double Rate = 40;

private String contractNumber;

private int rentalHours;

private int rentalMinutes;

private double price;

/**

* @param num

* @param mins

* sets the values of string and int

*/

public Rental(String num, int mins)

{

setHoursAndMinutes(mins);

setContractNumber(num);

}

/**

* @param number

* sets contract number also does the Hours and mins UR MOM LOL

*/

public void setContractNumber(String number)

{

contractNumber = number;

}

public void setContractNumber2(String number)

{

contractNumber = number;

}

public void setContractNumber3(String number)

{

contractNumber = number;

}

public void setHoursAndMinutes(int minutes)

{

rentalHours = minutes / Minutes; //hours

rentalMinutes = minutes % Minutes; // minutes

price = rentalHours * Rate + rentalMinutes; //price

}

/**

* @return

* returns contract number

*/

public String getContractNumber()

{

return contractNumber;

}

public String getContractNumber2()

{

return contractNumber;

}

public String getContractNumber3()

{

return contractNumber;

}

/**

* @return

* returns hours

*/

public int getHours()

{

return rentalHours;

}

/**

* @return

* returns minutes

*/

public int getMinutes()

{

return rentalMinutes;

}

/**

* @return

* returns Price

*/

public double getPrice()

{

return 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

Recommended Textbook for

More Books

Students also viewed these Databases questions