Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In previous chapters, you developed classes that hold rental contract information for Sammys Seashore Supplies. Now modify the Rental and RentalDemo classes as follows: Modify

In previous chapters, you developed classes that hold rental contract information for Sammys Seashore Supplies. Now modify the Rental and RentalDemo classes as follows: Modify the Rental class to include an integer field that holds an equipment type. Add a final String array that holds names of the types of equipment that Sammys rentsjet ski, pontoon boat, rowboat, canoe, kayak, beach chair, umbrella, and other. Include get and set methods for the integer equipment type field. If the argument passed to the method that sets the equipment type is larger than the size of the array of String equipment types, then set the integer to the element number occupied by other. Include a get method that returns a rentals String equipment type based on the numeric equipment type. To keep the RentalDemo class simple, remove all the statements that compare rental times and that display the coupon Strings. Modify the RentalDemo class so that instead of creating three single Rental objects, it uses an array of three Rental objects. Get data for each of the objects, and then display all the details for each object. Save the files as Rental.java and RentalDemo.java.

Old Code:

RentalDemo

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; //Phone numbers String phoneNum; String phoneNum2; String phoneNum3;

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 6 int minlim = 60; System.out.print("Enter contract number: "); Num = scan.nextLine(); System.out.print("Enter minutes: "); min = Integer.parseInt(scan.nextLine()); //Add phone number corresponding to the contract1 System.out.print("Enter Phone number: "+" "); phoneNum = scan.nextLine();

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 = Integer.parseInt(scan2.nextLine());

//Add phone number corresponding to the contract2 System.out.print("Enter Phone number: "); phoneNum2 = scan2.nextLine();

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 = Integer.parseInt(scan3.nextLine()); //Add phone number corresponding to the contract3 System.out.print("Enter Phone number: "); phoneNum3 = scan3.nextLine(); 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,phoneNum); 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() +" , the Phone Number is : " +Rent1.getPhoneNumber()+ " "); //System.out.println("The phone number for the contract is"+Rent1.getPhoneNumber());

Rental Rent2 = new Rental(Num2, min2,phoneNum2); 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()+" , the Phone Number is : " +Rent2.getPhoneNumber()+ " "); //System.out.println("The phone number for the contract is"+Rent2.getPhoneNumber());

Rental Rent3 = new Rental(Num3, min3,phoneNum3); 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() +" , the Phone Number is : " +Rent3.getPhoneNumber()+ " "); // System.out.println("The phone number for the contract is"+Rent3.getPhoneNumber()); //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:

public class Rental {

public final static int Minutes = 60;

public final static double Rate = 40;

private String contractNumber;

private String contactPhoneNumber;

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,String phoneNumber)

{

setHoursAndMinutes(mins);

setContractNumber(num);

setPhoneNumber(phoneNumber);

}

/**

* @param phonenumber

* sets phone number

*/

public void setPhoneNumber(String number)

{

//length of the phone number

int length = number.length();

String newNumber="";

//Extract only digits from the entered number and store it in a newNumber

for (int i = 0; i < length; i++) {

char c = number.charAt(i);

if (Character.isDigit(c)) {

newNumber = newNumber+c;

}

}

//if the phone number is less than 10 digits we are re setting it with 10 zero's

if(newNumber.length() < 10 || newNumber.length() > 10){

contactPhoneNumber = "0000000000";

return;

}

contactPhoneNumber = newNumber;

}

/**

* @return

* returns phone number

*/

public String getPhoneNumber()

{

String phoneNumber;

//Modify the phone number such that it holds the country code in () followed by space followed by 3 digits followed by "-" followed by 4 digits

phoneNumber = "("+contactPhoneNumber.substring(0, 3)+")"+" "+contactPhoneNumber.substring(3, 6)+"-"+contactPhoneNumber.substring(6);

return phoneNumber;

}

/**

* @param number

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

*/

public void setContractNumber(String number)

{

//char c = contractNumber.charAt(0);

char c;

//Declare a Character to store the upperCase letter

char C;

//length of the input string

int length = number.length();

//checking whether the contractnumber is of length 4

if(length == 4){

c = number.charAt(0);

//Check whether the first charcater is of Alphabet

if(Character.isLetter(c)){

//checking remaining 3 characters are of digits

if(number.substring(1).matches("\\d+")){

//Checking whether the first charcater is of Uppercase letter

if (Character.isUpperCase(c)){

contractNumber = number;

}else{

C = Character.toUpperCase(c);

contractNumber = C+number.substring(1);

}

}else{

contractNumber="A000";

}

}else{

contractNumber="A000";

}

}else{

contractNumber="A000";

}

}

public void setContractNumber2(String number)

{

//char c = contractNumber.charAt(0);

char c;

//Declare a Character to store the upperCase letter

char C;

//length of the input string

int length = number.length();

//checking whether the contractnumber is of length 4

if(length == 4){

c = number.charAt(0);

//Check whether the first charcater is of Alphabet

if(Character.isLetter(c)){

//checking remaining 3 characters are of digits

if(number.substring(1).matches("\\d+")){

//Checking whether the first charcater is of Uppercase letter

if (Character.isUpperCase(c)){

contractNumber = number;

}else{

C = Character.toUpperCase(c);

contractNumber = C+number.substring(1);

}

}else{

contractNumber="A000";

}

}else{

contractNumber="A000";

}

}else{

contractNumber="A000";

}

}

public void setContractNumber3(String number)

{

//char c = contractNumber.charAt(0);

char c;

//Declare a Character to store the upperCase letter

char C;

//length of the input string

int length = number.length();

//checking whether the contractnumber is of length 4

if(length == 4){

c = number.charAt(0);

//Check whether the first charcater is of Alphabet

if(Character.isLetter(c)){

//checking remaining 3 characters are of digits

if(number.substring(1).matches("\\d+")){

//Checking whether the first charcater is of Uppercase letter

if (Character.isUpperCase(c)){

contractNumber = number;

}else{

C = Character.toUpperCase(c);

contractNumber = C+number.substring(1);

}

}else{

contractNumber="A000";

}

}else{

contractNumber="A000";

}

}else{

contractNumber="A000";

}

}

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

Real Time Database And Information Systems Research Advances

Authors: Azer Bestavros ,Victor Fay-Wolfe

1st Edition

1461377803, 978-1461377801

More Books

Students also viewed these Databases questions

Question

b. Where did they come from?

Answered: 1 week ago