Respuesta :
Answer:
import java.util.Scanner;
public class Event {
public final static double LOWER = 32.00;
public final static double HIGHER = 35.00;
public final static int CUTOFF_VALUE = 50;
public boolean largeEvent;
private String eventNum;
private int totalGuests;
private double price;
private double pricePerGuest;
public Event(String event, int guests) {
eventNum = event;
totalGuests = guests;
}
public Event() {
this("A000", 0);
}
private Scanner input = new Scanner(System.in);
public void setEventNumber() {
System.out.print("Enter the event number? ");
eventNum = input.nextLine();
}
public void settotalGuests() {
System.out.print("Enter total guests that are attending the event? ");
totalGuests = input.nextInt();
if (isLargeEvent())
pricePerGuest = LOWER;
else
pricePerGuest = HIGHER;
price = totalGuests * pricePerGuest;
largeEvent = (totalGuests >= CUTOFF_VALUE);
System.out.println("");
}
public boolean isLargeEvent() {
if (this.gettotalGuests() > 50)
return true;
else
return false;
}
public String getEventNumber() {
return eventNum;
}
public int gettotalGuests() {
return totalGuests;
}
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.settotalGuests();
System.out.println("Enter Details of event2:");
event2.setEventNumber();
event2.settotalGuests();
System.out.println("Enter Details of event3:");
event3.setEventNumber();
event3.settotalGuests();
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.gettotalGuests());
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.gettotalGuests() > e2.gettotalGuests())
return e1;
else
return e2;
}
}
Explanation:
- Call isLargeEvent() method to check whether to set pricePerGuest as Lower or Higher.
- Calculate the price by multiplying the total guests with price per guest.
- Call gettotalGuests() method to check if the event is large or small.