Please respond only if you can answer the whole question Ja

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

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

Java Programming: Ch 8 Case Problem 1

In previous chapters, you developed classes that work with catering event

information for Carly’s Catering. Now modify the Event and EventDemo classes

as follows:

Modify the Event class to include an integer field that holds an event type. Add a

final String array that holds names of the types of events that Carly’s caters—

wedding, baptism, birthday, corporate, and other. Include get and set methods

for the integer event type field. If the argument passed to the method that sets

the event type is larger than the size of the array of String event types, then

set the integer to the element number occupied by “other”. Include a getmethod

that returns an event’s String event type based on the numeric event type.

To keep the EventDemo class simple, remove all the statements that compare

event sizes and that display the invitation Strings.

Modify the EventDemo class so that instead of creating three single Event

objects, it uses an array of three Event objects. Get data for each of the objects,

and then display all the details for each object.

Save the files as Event.java and EventDemo.java.

Please use code below 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;
    private String contact;
    private Scanner input = new Scanner(System.in);

    public Event(String event, int guests) {
        eventNum = event;
        numOfGuests = guests;
    }

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


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

        if (eventNum.length() != 4)
            eventNum=\"A000\";

             if (eventNum.length() == 4
                     && Character.isLetter(eventNum.charAt(0))
                     && Character.isDigit(eventNum.charAt(1))
                     && Character.isDigit(eventNum.charAt(2))
                     && Character.isDigit(eventNum.charAt(3))){
        }else{
            eventNum = \"A000\";
         }
        eventNum = eventNum.toUpperCase();
    }

    public void setNumOfGuests() {

        do {
            System.out.print(\"How many guests are attending the event? \");
            numOfGuests = input.nextInt();
            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;
    }

    public void setContactPhone() {
        System.out.print(\"What is the contact phone number? \");
        contact = input.nextLine();
        contact = contact.replaceAll(\"[^0-9]\", \"\");
        if (contact.length() != 10)
            contact = \"0000000000\";
    }

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

    public String getEventNumber() {
        return eventNum;
    }

    public String getContactPhone(){
        return \"(\" + contact.substring(0, 3) + \")\" + \" \"
                + contact.substring(3, 6) + \"-\"
                + contact.substring(6);
    }


    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.setContactPhone();
        System.out.println(\"\");

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

        Event event3 = new Event();
        System.out.println(\"Event #3: \");
        event3.setEventNumber();
        event3.setNumOfGuests();
        event3.setContactPhone();
        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 number: \" + e.getContactPhone());
        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;

public final String EVENT_TYPES[] = {
\"wedding\", \"beptism\", \"birthday\", \"corporate\" , \"other\"
};
  
public int eventType;
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);

public Event(String event, int guests) {
eventNum = event;
numOfGuests = guests;
}

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


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

if (eventNum.length() != 4)
eventNum=\"A000\";

if (eventNum.length() == 4
&& Character.isLetter(eventNum.charAt(0))
&& Character.isDigit(eventNum.charAt(1))
&& Character.isDigit(eventNum.charAt(2))
&& Character.isDigit(eventNum.charAt(3))){
}else{
eventNum = \"A000\";
}
eventNum = eventNum.toUpperCase();
}

public void setNumOfGuests() {

do {
System.out.print(\"How many guests are attending the event? \");
numOfGuests = input.nextInt();
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;
}

public void setContactPhone() {
System.out.print(\"What is the contact phone number? \");
contact = input.nextLine();
contact = contact.replaceAll(\"[^0-9]\", \"\");
if (contact.length() != 10)
contact = \"0000000000\";
}

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

public String getEventNumber() {
return eventNum;
}

public String getContactPhone(){
return \"(\" + contact.substring(0, 3) + \")\" + \" \"
+ contact.substring(3, 6) + \"-\"
+ contact.substring(6);
}


public int getNumOfGuests() {
return numOfGuests;
}

public double getPrice() {
return price;
}

public double getPricePerGuest(){
return pricePerGuest;
}
  
public void setEventType(int i){
if(i < EVENT_TYPES.length)
eventType = i;
else
eventType = EVENT_TYPES.length - 1;
}
  
public String getEventType(){
return EVENT_TYPES[eventType];
}
}

class EventDemo {

public static void main(String[] args) {
Event events[] = new Event[3];
for(int i=1;i<4;i++){
Event e = new Event();
System.out.println(\"Event #\"+i+\": \");
e.setEventNumber();
e.setNumOfGuests();
e.setContactPhone();
System.out.println(\"\");
events[i] = e;
}
  
for(Event e:events){
display(e);
}

}

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 number: \" + e.getContactPhone());
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;
}
}

**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 8 Case Problem 1 In previous chapter
**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 8 Case Problem 1 In previous chapter
**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 8 Case Problem 1 In previous chapter
**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 8 Case Problem 1 In previous chapter
**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 8 Case Problem 1 In previous chapter
**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 8 Case Problem 1 In previous chapter

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site