Please respond only if you can answer the whole question Ja

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

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

Java Programming: Ch 5 Case Problem 1

1. a. Carly’s Catering provides meals for parties and special events. In Chapters 3 and 4, you created an Event class for the company. Now, make the following changes to the class:

Currently, the class contains a field that holds the price for an Event. Now add another field that holds the price per guest, and add a public method to return its value.

Currently, the class contains a constant for the price per guest. Replace that field with two fields—a lower price per guest that is $32, and a higher price per guest that is $35.

Add a new method named isLargeEvent() that returns true if the number of guests is 50 or greater and otherwise returns false.

Modify the method that sets the number of guests so that a large Event (over

50 guests) uses the lower price per guest to set the new pricePerGuest field and calculate the total Event price. A small Event uses the higher price.

Save the file as Event.java.

b. In Chapter 4, you modified the EventDemo class to demonstrate two Event

objects. Now, modify that class again as follows:

Instantiate three Event objects, and prompt the user for values for each object.

Change the method that displays Event details to use the new isLargeEvent() method and the new price per guest value. Use the display method with all three objects.

Create a method that accepts two Event objects and returns the larger one based on number of guests. (If the Events have the same number of guests, you can return either object.) Call this method three times—once with each pair of instantiated Events—and display the event number and number of guests for each argument as well as the event number and number of guests for the larger Event.

Save the file as EventDemo.java.

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

Please use code to answer question:

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

Solution

import java.util.Scanner;

public class Event {

   public final static double LOWER_PER_GUEST = 32.00;
   public final static double HIGHER_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() {
       System.out.print(\"How many guests are attending the event? \");
       numOfGuests = input.nextInt();
       if (isLargeEvent())
           pricePerGuest = LOWER_PER_GUEST;
       else
           pricePerGuest = HIGHER_PER_GUEST;

       price = numOfGuests * pricePerGuest;
       largeEvent = (numOfGuests >= CUTOFF_VALUE);
       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 class EventDemo {

   public static void main(String[] args) {

       Event event1 = new Event();
       Event event2 = new Event();
       Event event3 = new Event();
       System.out.println(\"Enter Details of event1:\");
       event1.setEventNumber();
       event1.setNumOfGuests();
       System.out.println(\"Enter Details of event2:\");
       event2.setEventNumber();
       event2.setNumOfGuests();
       System.out.println(\"Enter Details of event3:\");
       event3.setEventNumber();
       event3.setNumOfGuests();

       display(event1);
       display(event2);
       display(event3);
       System.out.println(\"Get largest event from event1 and event2 is :\");
       display(getLargestEvent(event1, event2));

       System.out.println(\"Get largest event from event2 and event3 is :\");
       display(getLargestEvent(event2, event3));

       System.out.println(\"Get largest event from event1 and event3 is :\");
       display(getLargestEvent(event1, event3));

   }

   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: $\"
               + String.format(\"%.2f\", e.getPrice()));
       System.out.println(\"Is Large event: \" + e.isLargeEvent());
       System.out.println(\"\");

   }

   public static Event getLargestEvent(Event e1, Event e2) {

       if (e1.getNumOfGuests() > e2.getNumOfGuests())
           return e1;
       else
           return e2;

   }
}
OUTPUT:
Enter Details of event1:
What is the event number? A0001
How many guests are attending the event? 58

Enter Details of event2:
What is the event number? A0002
How many guests are attending the event? 40

Enter Details of event3:
What is the event number? A0003
How many guests are attending the event? 88

Event number: A0001
Total guests: 58
Total price: $1856.00
Is Large event: true

Event number: A0002
Total guests: 40
Total price: $1400.00
Is Large event: false

Event number: A0003
Total guests: 88
Total price: $2816.00
Is Large event: true

Get largest event from event1 and event2 is :
Event number: A0001
Total guests: 58
Total price: $1856.00
Is Large event: true

Get largest event from event2 and event3 is :
Event number: A0003
Total guests: 88
Total price: $2816.00
Is Large event: true

Get largest event from event1 and event3 is :
Event number: A0003
Total guests: 88
Total price: $2816.00
Is Large event: true

**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 5 Case Problem 1 1. a. Carly’s Cater
**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 5 Case Problem 1 1. a. Carly’s Cater
**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 5 Case Problem 1 1. a. Carly’s Cater
**Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 5 Case Problem 1 1. a. Carly’s Cater

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site