Please respond only if you can answer the whole question Ja

**Please respond only if you can answer the whole question**

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Java Programming: Ch 7 Case Problem 1

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.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Please use code to answer question:

import java.util.Scanner;

public class Event {

    public final static double LOWER_PRICE_PER_GUEST = 32.00;
    public final static double HIGHER_PRICE_PER_GUEST = 35.00;
    public final static int CUTOFF_VALUE = 50;

    public boolean largeEvent;

    private String eventNum;
    private int numOfGuests;
    private double price;
    private double pricePerGuest;

    public Event(String event, int guests) {

        eventNum = event;
        numOfGuests = guests;
    }

    public Event() {
        this(\"A000\", 0);
    }


    private Scanner input = new Scanner(System.in);

    public void setEventNumber() {
        System.out.print(\"What is the event number? \");
        eventNum = input.nextLine();
    }

    public void setNumOfGuests() {

        do {
            System.out.print(\"How many guests are attending the event? \");
            numOfGuests = input.nextInt();
            if (numOfGuests < 5 || numOfGuests > 100) {
                System.out.println(\"The number of guests must be between 5 and 100 \");
            }else{
                break;
            }
        }while (true);

            if (isLargeEvent()) {
                pricePerGuest = LOWER_PRICE_PER_GUEST;
            }else{
                pricePerGuest = HIGHER_PRICE_PER_GUEST;
            }
                largeEvent = (numOfGuests >= CUTOFF_VALUE);
                price = numOfGuests * pricePerGuest;
                System.out.println(\"\");
    }

    public boolean isLargeEvent(){
        if(this.getNumOfGuests() >= 50)
            return true;
        else
            return false;
    }

    public String getEventNumber() {
        return eventNum;
    }

    public int getNumOfGuests() {
        return numOfGuests;
    }

    public double getPrice() {
        return price;
    }

    public double getPricePerGuest(){
        return pricePerGuest;
    }

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public class EventDemo {

    public static void main(String[] args) {

        Event event1 = new Event();
        System.out.println(\"Event #1: \");
        event1.setEventNumber();
        event1.setNumOfGuests();

        Event event2 = new Event();
        System.out.println(\"Event #2: \");
        event2.setEventNumber();
        event2.setNumOfGuests();

        Event event3 = new Event();
        System.out.println(\"Event #3: \");
       event3.setEventNumber();
        event3.setNumOfGuests();

        display(event1);
        display(event2);
        display(event3);

        System.out.println(\"Display larger event comparing Event #1 and Event #2: \");
        display(largerEvent(event1, event2));
        System.out.println(\"Display larger event comparing Event #2 and Event #3: \");
        display(largerEvent(event2, event3));
        System.out.println(\"Display larger event comparing Event #1 and Event #3: \");
        display(largerEvent(event1, event3));

        for (int i = 0; i < event1.getNumOfGuests(); i++){
            System.out.println(\"Please come to my event!\");
        }
    }

    public static void display(Event e) {
        System.out.println(\"Event number: \" + e.getEventNumber());
        System.out.println(\"Total guests: \" + e.getNumOfGuests());
        System.out.println(\"Total price per guest: $\" + String.format(\"%.2f\", e.getPricePerGuest()));
        System.out.println(\"Total price: $\" + String.format(\"%.2f\", e.getPrice()));
        System.out.println(\"Large event: \" + e.isLargeEvent());
        System.out.println(\"\");
    }

    public static Event largerEvent (Event e1, Event e2){
        if (e1.getNumOfGuests() >= e2.getNumOfGuests())
            return e1;
        else
            return e2;
    }
}

Solution

import java.util.Scanner;

public class Event {

   public final static double LOWER_PRICE_PER_GUEST = 32.00;
   public final static double HIGHER_PRICE_PER_GUEST = 35.00;
   public final static int CUTOFF_VALUE = 50;

   // Attributes
   public boolean largeEvent;
   private String eventNum;
   private int numOfGuests;
   private double price;
   private double pricePerGuest;
   private String contact;
   private Scanner input = new Scanner(System.in);

   /**
   * Constructor
   * @param event
   * @param guests
   */
   public Event(String event, int guests) {
       eventNum = event;
       numOfGuests = guests;
   }

   /**
   * Constructor
   */
   public Event() {
       this(\"A000\", 0);
   }

   /**
   * Sets the event number
   */
   public void setEventNumber() {
       System.out.println(\"What is the event number? \");
       eventNum = input.nextLine();
      
       // Check if event number is a four-character String that starts with a letter followed by three digits
       if (!eventNum.matches(\"[A-Za-z]{1}[0-9]{3}\")) {
           eventNum = \"A000\";
       }
       eventNum = eventNum.toUpperCase();
   }
  
   /**
   * Sets the number of guests
   */
   public void setNumOfGuests() {

       do {
           System.out.println(\"How many guests are attending the event? \");
           numOfGuests = input.nextInt();
           // Clear keyboard buffer
           input.nextLine();
          
           if (numOfGuests < 5 || numOfGuests > 100) {
               System.out.println(\"The number of guests must be between 5 and 100 \");
           } else {
               break;
           }
       } while (true);

       if (isLargeEvent()) {
           pricePerGuest = LOWER_PRICE_PER_GUEST;
       } else {
           pricePerGuest = HIGHER_PRICE_PER_GUEST;
       }
       largeEvent = (numOfGuests >= CUTOFF_VALUE);
       price = numOfGuests * pricePerGuest;
   }
  
   /**
   * @param contact the contact to set
   */
   public void setContact() {
       System.out.println(\"What is the contact number? \");
       contact = input.nextLine();
      
       // Keep all digits from input
       contact = contact.replaceAll(\"\\\\D+\", \"\");
      
       // If user enters fewer or more than 10 digits
       if (contact.length() != 10)
           contact = \"0000000000\";
   }
  
   /**
   * @return the contact
   */
   public String getContact() {
       String phonePattern = \"(#1) #2-#3\";
       return phonePattern.replace(\"#1\", contact.subSequence(0, 3))
               .replace(\"#2\", contact.substring(3, 6))
               .replace(\"#3\", contact.substring(6));
   }

   /**
   * Checks if this is a large event
   * @return
   */
   public boolean isLargeEvent() {
       if (this.getNumOfGuests() >= 50)
           return true;
       else
           return false;
   }

   public String getEventNumber() {
       return eventNum;
   }

   public int getNumOfGuests() {
       return numOfGuests;
   }

   public double getPrice() {
       return price;
   }

   public double getPricePerGuest() {
       return pricePerGuest;
   }
}

public class EventDemo {

   public static void main(String[] args) {

       Event event1 = new Event();
       System.out.println(\"Event #1: \");
       event1.setEventNumber();
       event1.setNumOfGuests();
       event1.setContact();
       System.out.println();
      
       Event event2 = new Event();
       System.out.println(\"Event #2: \");
       event2.setEventNumber();
       event2.setNumOfGuests();
       event2.setContact();
       System.out.println();

       Event event3 = new Event();
       System.out.println(\"Event #3: \");
       event3.setEventNumber();
       event3.setNumOfGuests();
       event3.setContact();
       System.out.println();

       display(event1);
       display(event2);
       display(event3);

       System.out.println(\"Display larger event comparing Event #1 and Event #2: \");
       display(largerEvent(event1, event2));
       System.out.println(\"Display larger event comparing Event #2 and Event #3: \");
       display(largerEvent(event2, event3));
       System.out.println(\"Display larger event comparing Event #1 and Event #3: \");
       display(largerEvent(event1, event3));

       for (int i = 0; i < event1.getNumOfGuests(); i++) {
           System.out.println(\"Please come to my event!\");
       }
   }

   public static void display(Event e) {
       System.out.println(\"Event number: \" + e.getEventNumber());
       System.out.println(\"Total guests: \" + e.getNumOfGuests());
       System.out.println(\"Contact phone: \" + e.getContact());
       System.out.println(\"Total price per guest: $\" + String.format(\"%.2f\", e.getPricePerGuest()));
       System.out.println(\"Total price: $\" + String.format(\"%.2f\", e.getPrice()));
       System.out.println(\"Large event: \" + e.isLargeEvent());
       System.out.println(\"\");
   }

   /**
   * Returns the largest of the two events
   *
   * @param e1
   * @param e2
   * @return
   */
   public static Event largerEvent(Event e1, Event e2) {
       if (e1.getNumOfGuests() >= e2.getNumOfGuests())
           return e1;
       else
           return e2;
   }
}

SAMPLE OUTPUT:

Event #1:
What is the event number?
event1
How many guests are attending the event?
10
What is the contact number?
1234

Event #2:
What is the event number?
a002
How many guests are attending the event?
20
What is the contact number?
9208729182

Event #3:
What is the event number?
a003
How many guests are attending the event?
30
What is the contact number?
(123) 456-7890

Event number: A000
Total guests: 10
Contact phone: (000) 000-0000
Total price per guest: $35.00
Total price: $350.00
Large event: false

Event number: A002
Total guests: 20
Contact phone: (920) 872-9182
Total price per guest: $35.00
Total price: $700.00
Large event: false

Event number: A003
Total guests: 30
Contact phone: (123) 456-7890
Total price per guest: $35.00
Total price: $1050.00
Large event: false

Display larger event comparing Event #1 and Event #2:
Event number: A002
Total guests: 20
Contact phone: (920) 872-9182
Total price per guest: $35.00
Total price: $700.00
Large event: false

Display larger event comparing Event #2 and Event #3:
Event number: A003
Total guests: 30
Contact phone: (123) 456-7890
Total price per guest: $35.00
Total price: $1050.00
Large event: false

Display larger event comparing Event #1 and Event #3:
Event number: A003
Total guests: 30
Contact phone: (123) 456-7890
Total price per guest: $35.00
Total price: $1050.00
Large event: false

Please come to my event!
Please come to my event!
Please come to my event!
Please come to my event!
Please come to my event!
Please come to my event!
Please come to my event!
Please come to my event!
Please come to my event!
Please come to my event!

**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 7 Case Problem 1 Carly’s Catering pr
**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 7 Case Problem 1 Carly’s Catering pr
**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 7 Case Problem 1 Carly’s Catering pr
**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 7 Case Problem 1 Carly’s Catering pr
**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 7 Case Problem 1 Carly’s Catering pr
**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 7 Case Problem 1 Carly’s Catering pr
**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 7 Case Problem 1 Carly’s Catering pr
**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 7 Case Problem 1 Carly’s Catering pr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site