Question

In: Computer Science

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 the event number is forced to A000. If the initial letter in the event number is not uppercase, force it to be so. • Add a contact phone number field to the Event class. • Add a set method for the contact phone number field in the Event 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 EventDemo program so that besides the event number and guests, 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 Event details. Test the EventDemo application to make sure it works correctly with valid and invalid event and phone numbers. Save the files as Event.java and EventDemo.java

Solutions

Expert Solution

package string;

// Defines a class Event

class Event

{

// Instance variables to store event and phone number

String eventNumber;

String phoneNumber;

// Method to validate and set event number

void setEventNumber(String en)

{

// Checks if the length of the parameter event number length is 4

if(en.length() == 4)

{

// Checks if the first character of the parameter event number

// is an alphabet

if( (en.charAt(0) >= 'a' && en.charAt(0) <= 'z') ||

(en.charAt(0) >= 'A' && en.charAt(0) <= 'Z'))

{

// Checks rest 3 character of parameter event number is digit

if( (en.charAt(1) >= '0' && en.charAt(1) <= '9') &&

(en.charAt(2) >= '0' && en.charAt(2) <= '9') &&

(en.charAt(3) >= '0' && en.charAt(3) <= '9'))

{

// Converts to upper chase

en = en.toUpperCase();

// Assigns parameter event number to instance variable

eventNumber = en;

}// End of if condition

}// End of if condition

}// End of if condition

// Otherwise assigns default value

else

eventNumber = "A000";

}// End of method

// Method to validate and set phone number

void setPhoneNumber(String pn)

{

// To store number of digits. Initially zero

int countDigit = 0;

// Assigns left parenthesis for formated phone number

String phone = "(";

// To store only digits from the parameter phone number

String number = "";

// Loops till end of the parameter phone number

for(int c = 0; c < pn.length(); c++)

{

// Checks if current character is a digit

if(pn.charAt(c) >= '0' && pn.charAt(c) <= '9')

{

// Increase the digit counter

countDigit++;

// Concatenates the current digit to number

number += pn.charAt(c);

}// End of if condition

}// End of for loop

// Checks if number of digits is not equals to 10 assigns default value

if(countDigit != 10)

number = "0000000000";

// Loops 3 times to concatenate digits for area code

for(int c = 0; c < 3; c++)

phone += number.charAt(c);

// Concatenates right parenthesis

phone += ") ";

// Loops 3 times to concatenate digits for phone exchange

for(int c = 3; c < 6; c++)

phone += number.charAt(c);

// Concatenates hyphen character

phone += "-";

// Loops 4 times to concatenate digits for phone number

for(int c = 6; c < 10; c++)

phone += number.charAt(c);

// Assigns the formated phone number to instance variable

phoneNumber = phone;

}// End of method

// Method to return event number

String getEventNumber()

{

return eventNumber;

}// End of method

// Method to return phone number

String getPhoneNumber()

{

return phoneNumber;

}// End of method

}// End of class Event

// Driver class definition

public class EventDemo

{

// main method definition

public static void main(String []ss)

{

// Declares an object of class Event

Event e1 = new Event();

System.out.print("\n\n Test Event Number (P1111): ");

// Calls the method to validate and set event number

e1.setEventNumber("P1111");

// Calls the method to display event number

System.out.print("\n Event Number: " + e1.getEventNumber());

System.out.print("\n\n Test Event Number (PA111): ");

// Calls the method to validate and set event number

e1.setEventNumber("PA11");

// Calls the method to display event number

System.out.print("\n Event Number: " + e1.getEventNumber());

System.out.print("\n\n Test Event Number (1A11): ");

// Calls the method to validate and set event number

e1.setEventNumber("1A11");

// Calls the method to display event number

System.out.print("\n Event Number: " + e1.getEventNumber());

System.out.print("\n\n Test Event Number (p111): ");

// Calls the method to validate and set event number

e1.setEventNumber("P111");

// Calls the method to display event number

System.out.print("\n Event Number: " + e1.getEventNumber());

System.out.print("\n\n Test Phone Number (111-2222): ");

// Calls the method to validate and set phone number

e1.setPhoneNumber("111-2222");

// Calls the method to display event number

System.out.print("\n Phone Number: " + e1.getPhoneNumber());

System.out.print("\n\n Test Phone Number (111(2222)3359): ");

// Calls the method to validate and set phone number

e1.setPhoneNumber("111(2222)3359");

// Calls the method to display event number

System.out.print("\n Phone Number: " + e1.getPhoneNumber());

System.out.print("\n\n Test Phone Number (111(222)3359): ");

// Calls the method to validate and set phone number

e1.setPhoneNumber("111(222)3359");

// Calls the method to display event number

System.out.print("\n Phone Number: " + e1.getPhoneNumber());

}// End of method

}// End of driver class

Sample Output:

Test Event Number (P1111):
Event Number: A000

Test Event Number (PA111):
Event Number: A000

Test Event Number (1A11):
Event Number: A000

Test Event Number (p111):
Event Number: P111

Test Phone Number (111-2222):
Phone Number: (000) 000-0000

Test Phone Number (111(2222)3359):
Phone Number: (000) 000-0000

Test Phone Number (111(222)3359):
Phone Number: (111) 222-3359


Related Solutions

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 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...
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...
Anthony Bourdain owns an international catering service that provides food and beverages at exclusive parties and...
Anthony Bourdain owns an international catering service that provides food and beverages at exclusive parties and business events. Bourdain’s business is seasonal, with a heavy schedule during the summer months and holidays and a lighter schedule at other times. One of the major events that Bourdain’s customers request is a cocktail party. He offers a standard cocktail party and has estimated the cost per quest for this party as follows: Food and beverages $17.00 Labor (.50 hours @ $10.00/hour)     5.00...
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...
As assistant coordinator of special events for salk pharmaceuticals Inc, you have been asked by the...
As assistant coordinator of special events for salk pharmaceuticals Inc, you have been asked by the coordinator of special events, Tom Byington, to investigate three different models of General Models Radio Service two way radios with which to equip the five team leaders during your annual three day team building wilderness retreat. The radios must be able work within a range of 8 to 13 kilometers, the distance of many treks and canoe trips. Because teams may be outdoors and...
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...
1. Describe any of your special interests and how you have developed knowledge in these areas...
1. Describe any of your special interests and how you have developed knowledge in these areas and how you have used these. Give examples of your creativity: the ability to see alternatives; take diverse perspectives; come up with new ideas; or willingness to try new things. (250-300 words) 2. Describe examples of your leadership experience in which you have helped others, resolved disputes, or contributed to group efforts over time. You may include experiences in school as well as in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT