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

Since your previously written class Event and class EventDemo is not provided so i have only written the portions which were asked to be added / modified in the program such that this code yields all required output based on the data/instructions provided. The other details that were to be taken from your previous chapters or programs can be combined with this code.

CODE:

import java.util.Arrays;

import java.util.Scanner;

class Event {

    String eventNumber;

    String phoneNumber;

    // setEventNumber() method sets the event number entered by user which is then passed as an argument to this method as per the requirments

    void setEventNumber(String x) {

        // if length of srting entered ny user is 4 then the string is further tested to satisfy other conditions

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

            // check if the first character of string x is a digit and the other 3 characters are digits

            // Character.isLetter(x.charAt(0)) returns true if character at index 0 of string x is a letter and Character.isDigit(x.charAt(i)) returns true if character at index 'i'=1,2,3 of string x is a digit

            // when all 4 conditions return true then proceed further to check other conditions

            if (Character.isLetter(x.charAt(0)) && Character.isDigit(x.charAt(1)) && Character.isDigit(x.charAt(2)) && Character.isDigit(x.charAt(3))) {

                //check if first charater of string x is in uppercase

                if (!Character.isUpperCase(x.charAt(0))) { //when this condition returns false convert it to uppercase using toUpperCase()

                    Character.toUpperCase(x.charAt(0));

                }

                this.eventNumber = x; //the eventNumber is set to x when x satisfies all conditions

            }

            else {  //eventNumber set to "A000" when charactres of x do not satisfy the conditions

                this.eventNumber = "A000";

            }

        }

        // if length of srting entered ny user is not = 4 then the event number is set to A000

        else {

            this.eventNumber = "A000";

        }

    }

    // this sets phone number to desired format by taking string n as a parameter which is a string entered by user

    void setPhoneNumber(String n) {

        String num ="" ; //an empty string used  to store resulting phone number

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

            if (Character.isDigit(n.charAt(i))) {  //if character is a digit then add/concatenate it to string num

                num = num + n.charAt(i);

            }

        }

        if (num.length() == 10) //check if phone number has 10 digits else set phone number to 0000000000

            this.phoneNumber = num;

        else

            this.phoneNumber = "0000000000";

    }

    String getPhoneNumber() {

        String phone;

        phone = "(" + this.phoneNumber.substring(0, 3) + ") " + this.phoneNumber.substring(3, 6) + "-"

                + phoneNumber.substring(6);

        return phone; // returns phone number in desired format

    }

}

class EventDemo {

    public static void main(String[] args)throws Exception {

        Scanner sc = new Scanner(System.in);

        Event e1 = new Event();

        System.out.println("Enter Event number");

        String eventNum = sc.nextLine();

        System.out.println("Enter Phone number");

        String phoneNum = sc.nextLine();

        e1.setEventNumber(eventNum);

        e1.setPhoneNumber(phoneNum);

        String phno = e1.getPhoneNumber();

        System.out.println("EVENT DETAILS of event e1");

        System.out.println("Event NUmber: "+e1.eventNumber);

        System.out.println("Phone NUmber: "+phno);

        sc.close();

    }

}

SCREENSHOT OF CODE:-

OUTPUT:


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