Question

In: Computer Science

Sammy’s Seashore Supplies rents beach equipment to tourists. In previous chapters, you have developed a class...

Sammy’s 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.

Solutions

Expert Solution

Please include the modified changes to exisitng rental class. Giving u code for additional requirement.

COPY TO CODE:

package staticClass2;

//rental class with additional fields

class Rental {

private String phoneNumber;

private String contractNumber;

public String getContractNumber() {

return contractNumber;

}

//set contract number

public void setContractNumber(String contractNumber) {

//get the contract number and upper case it

contractNumber = contractNumber.toUpperCase();

//if it is of 4 digit

if(contractNumber.length()==4){

//then check if first character is alphabet and remaining digit

String firstChar = contractNumber.charAt(0)+"";

String remaining = contractNumber.substring(1);

if((firstChar.matches("[a-zA-Z]+") && remaining.matches("^\\d+$"))){

this.contractNumber = contractNumber;

}else{

this.contractNumber="A000";

}

}else{

this.contractNumber="A000";

}

}

public String getPhoneNumber() {

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

}

public void setPhoneNumber(String phoneNumber) {

//replace all non numeric from phone number

phoneNumber = phoneNumber.replaceAll("[^0-9]", "");

//now check the length

if(phoneNumber.length()==10){

this.phoneNumber= phoneNumber;

}else{

this.phoneNumber = "0000000000";

}

}

}

public class RentalDemo {

public static void main(String[] args) {

Rental rent = new Rental() ;

System.out.println("First details");

rent.setContractNumber("W111");

rent.setPhoneNumber("1234567890");

System.out.println(rent.getPhoneNumber());

System.out.println(rent.getContractNumber());

System.out.println("\n\n\nSecond details");

Rental rent2 = new Rental();

rent2.setContractNumber("2343");

rent2.setPhoneNumber("3439 09");

System.out.println(rent2.getPhoneNumber());

System.out.println(rent2.getContractNumber());

}

}

OUTPUT:


Related Solutions

Sammy's Seashore Supplies rents beach equipment to tourists. Inprevious chapters, you have developed a class...
Sammy's 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...
Carly's Catering provides meals for parties and special events. In previous chapters, you developed a class...
Carly's Catering provides meals for parties and special events. In previous chapters, you developed a class that holds catering event information and an application that tests the methods using three objects of the class. Now modify the EventDemo class to do the following: Continuously prompt for the number of guests for each Event until the value falls between 5 and 100 inclusive. For one of the Event objects, create a loop that displays Please come to my event! as many...
Carly's Catering provides meals for parties and special events. In previous chapters, you have developed a...
Carly's Catering provides meals for parties and special events. In previous chapters, you have developed a class that holds catering event information and an application that tests the methods using four objects of the class. Now modify the Event and EventDemo classes as follows: Modify the method that sets the event number in the Event 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...
Carly’s Catering provides meals for parties and special events. In previous chapters, you have developed a...
Carly’s Catering provides meals for parties and special events. In previous chapters, you have developed a class that holds catering event information and an application that tests the methods using four objects of the class. Now modify the Event and EventDemo classes as follows: • Modify the method that sets the event number in the Event 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,...
Carly’s Catering provides meals for parties and special events. In previous chapters, you have developed a...
Carly’s Catering provides meals for parties and special events. In previous chapters, you have developed a class that holds catering event information and an application that tests the methods using four objects of the class. Now modify the Event and EventDemo classes as follows: • Modify the method that sets the event number in the Event 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,...
Now that we have completed Chapters 1 through 6 and have developed an understanding of assets,...
Now that we have completed Chapters 1 through 6 and have developed an understanding of assets, both short-term and long-term, apply your understanding of what you have learned to the following questions. Part 1 – Current and long-term assets From the perspective of a potential long-term investor, describe what you might look for when examining the assets of a corporation. Include in your answer an understanding of how short-term assets and long-term operating assets are different and what role they...
Chapter 5 Discussion No unread replies. No replies. In previous chapters, we have learned about the...
Chapter 5 Discussion No unread replies. No replies. In previous chapters, we have learned about the role of public health, social determinants and behavior and social theories related to health. This week, we are broadening our discussion to include how law, health policy and ethics impact health, quality of life and health outcomes. In this context, you will gain a better perspective of the role of public health and the overall goal of improving health, including the importance of multi-sectoral...
In the previous lab you created a Car class and a Dealership class. Now, in this...
In the previous lab you created a Car class and a Dealership class. Now, in this activity change the design of the Dealership class, in which the list of the cars inside a dealership will be stored in an ArrayList. Then, provide required getter and setter methods to keep the records of all its cars. In your tester class, test your class and also printout the list of all cars of a given dealership object. // Java program import java.util.ArrayList;...
I. You have studied the chapters on unemployment and business cycles. Please review those chapters before...
I. You have studied the chapters on unemployment and business cycles. Please review those chapters before you answer this question a) Find the time series data (quarterly or monthly) on the unemployment rate, inflation rate and real GDP growth in the U.S. from 1980 to 2005, and discuss whether the Okun’s Law is valid or not. Then, discuss whether the Phillips curve exists in the U.S. economy( you have to report your data source and or the website). b) Which...
When you decide to go and have a dinner with your friends in a world class hotel such as the Langham hotel or Coronado Beach
  When you decide to go and have a dinner with your friends in a world class hotel such as the Langham hotel or Coronado Beach, perhaps you would be horrified by the high price you would have to pay for a bottle of soft drink such as Coca Cola or Pepsi Cola or wine or even bottled water. Perhaps you begin to ponder why the same commodity that you can get at a supermarket at one tenth the hotel...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT