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

/***************************************************
Event Class
*************************************************/

import java.util.Scanner;

public class Event {
  
   //Initialize the variables
       public static double pricePerGuestHigh = 35.00;
       public static double pricePerGuestLow = 32.00;
       public static final int
       LARGE_EVENT_MAX = 50;
       public String phnum="";
       public String eventNumber="";
       private int guests;
       private double pricePerEvent;
       //Method definition of setPhoneNumber
       public void setPhoneNumber()
       {
           //Create a Scanner class's object
           Scanner s = new Scanner(System.in);
           int count=0;
           //Prompt and read the input from the user
           System.out.println("Enter Phone Number:");
           String pnumb=s.nextLine();
           int len=pnumb.length();
           for(int i=0;i<len;i++)
           {
               char c=pnumb.charAt(i);
               if(Character.isDigit(c))
               {
                   count++;
                   String ss=Character.toString(c);
                   phnum=phnum.concat(ss);
               }
           }
           if(count!=10)
           {
               phnum="";
               phnum=phnum.concat("0000000000");
           }
       }
       public String getPhoneNumber()
       {
           String ret="("+this.phnum.charAt(0)

           +""+this.phnum.charAt(1)+""+this.phnum.charAt(2)

           +")"+this.phnum.charAt(3)+""+this.phnum.charAt(4)

           +""+this.phnum.charAt(5)+""+this.phnum.charAt(6)

           +""+this.phnum.charAt(7)+""+this.phnum.charAt(8)
           +""+this.phnum.charAt(9);
           return ret;
       }
       //prompts user to enter event number
       public void setEventNumber()
       {
           Scanner scanner = new Scanner(System.in);
           int len;
           System.out.println("Enter 4 digit event number: ");
           String enumb = scanner.nextLine();
           len=enumb.length();
           char c1,c2,c3,c4;
           String defv="A000";
           c1=enumb.charAt(0);
           c2=enumb.charAt(1);
           c3=enumb.charAt(2);
           c4=enumb.charAt(3);
           if(Character.isLetter(c1) &&
           Character.isDigit(c2) &&
           Character.isDigit(c3) &&
           Character.isDigit(c4))
           {
               enumb=enumb.toUpperCase();
               eventNumber=eventNumber.concat(enumb);
           }
           {
               eventNumber=eventNumber.concat(defv);
           }
       }
       //Method to set number of guest
       public void setGuests(int guests)
       {
           this.guests = guests;
           if(isLargeEvent())
           pricePerEvent=pricePerGuestHigh;
           else
           pricePerEvent=pricePerGuestLow;
       }
       //Returns the number of guests of event
       public int getGuestsCount()
       {
           return guests;
       }
       //Returns true if event is large otherwise false
       public boolean isLargeEvent()
       {
           if (guests >= LARGE_EVENT_MAX)
           {
               return true;
           }
           else if (guests < LARGE_EVENT_MAX)
           {
               return false;
           }
           return isLargeEvent();
       }
       //Returns the event number
       public String getEventNumber()
       {
           String ret1="Event Number :"
           +this.eventNumber;
           return ret1;
       }
       public int getGuests(boolean largeEvent)
       {
           return guests;
       }
   }//end of the class Event

/***************************************************
EventDemo Class
***************************************************/

import java.util.Scanner;

public class EventDemo {

   public static void main(String[] args)
   {
       //Set size
       final int SIZE=4;
       //Create an array of Event type
       Event[] eventObjects = new Event[SIZE];
       //declare an integer variable
       int numGuests;
       //Create a Scanner class
       Scanner scanner = new Scanner(System.in);
       //run for loop for 4 times
       for (int i = 0; i < eventObjects.length;i++)
       {
           eventObjects[i]=new Event();
           eventObjects[i].setEventNumber();
           eventObjects[i].setPhoneNumber();
           /*prompt user to enter number of guests
           until the user enters in a range of 5
           to 100*/
           do
           {
               System.out.println("Enter number of guests : ");
               numGuests=scanner.nextInt();
               if(numGuests<5 ||numGuests>100)
               System.out.println("Number of guests must be in 5 to 100");
           }
           while(numGuests<5 ||numGuests>100);
           //set number of guests
           eventObjects[i].setGuests(numGuests);
       }

       //Select first object of Event from eventObjects array
       Event oneEvent=eventObjects[0];
       Event twoEvent=eventObjects[1];
       Event threeEvent=eventObjects[2];
       Event fourEvent=eventObjects[3];
       for(int i=0;i<4;i++)
       {
           System.out.println(" "
       +eventObjects[i].getEventNumber()
       +""
       + " contact number:"
       +eventObjects[i].getPhoneNumber()
       +""
       + " printing message "+eventObjects[i].getGuestsCount()+" times");
           /*printing message "Please come to my event!"
           to console */
           for (int j = 0; j < eventObjects[i].getGuestsCount(); j++)
           {
               System.out.println("Please come to event!");
           }
       }
   }//end of the main method
}//end of the class EventDemo


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