1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vlada-n [284]
3 years ago
5

A. Carly’s Catering provides meals for parties and special events. In Chapter 3, you created an Event class for the company. The

Event class contains two public final static fields that hold the price per guest ($35) and the cutoff value for a large event (50 guests), and three private fields that hold an event number, number of guests for the event, and the price. It also contains two public set methods and three public get methods.
Now, modify the Event class to contain two overloaded constructors

∎ One constructor accepts an event number and number of guests as parameters. Pass these values to the setEventNumber() and setGuests() methods, respectively. The setGuests() method will automatically calculate the event price.

∎ The other constructor is a default constructor that passes "A000" and 0 to the two-parameter constructor.

Save the file as Event.java

b. In Chapter 3, you also created an EventDemo class to demonstrate using two Event objects. Now, modify that class to instantiate two Event objects, and include the following new methods in the class:

∎ Instantiate one object to retain the constructor default values

∎ Accept user data for the event number and guests fields, and use this data set to instantiate the second object. Display all the details for both objects.

Save the file as EventDemo.java.
Computers and Technology
1 answer:
Tpy6a [65]3 years ago
5 0

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.
You might be interested in
Assuming deq is a deque object, the expression deq.push_front(elem) deletes the first element from deq.
horrorfan [7]

Answer: False

Explanation:

This code code not deletes element from deq. This insert element at the beginning of deq. if it was deq.pop_front(elem) then it would have deleted the first element.

Therefore, it is false.

4 0
3 years ago
Difference between ancient and modern mode of information <br> transmission
ELEN [110]
Ancient mode of transmission are used by people in the past while modern mode of transmission are used by present people
4 0
3 years ago
This device is used to connect sections of large networks?
ryzh [129]
Monster energy boissss
6 0
3 years ago
Read 2 more answers
Convert each of the following base 10 &amp; base 2 numbers in signed magnitude, one’s complement and two’s complement. Each of t
asambeis [7]

011110 is the following base 10 & base 2 numbers in signed magnitude, one’s complement and two’s complement.

c)011110

<u>Explanation:</u>

Converting 10 base signed number as two complements. In computer signed is maintain in registered.

But computer needs all values in bits. In hardware it is considered as on or off methods. ASCII values are converted into bits and executed by CPU.

All values which been entered in computer are taken respective ASCII values and converted to bits. Normally sign symbol are maintained as registered flag which can be know if end user knows assembly programming languages.

Assembly language by which direct interacted with machine languages and faster in executions.

7 0
3 years ago
Suppose you were assigned to develop a logical model of the registration system at a school or college. would you be better off
Valentin [98]
<span>Top-down approaches are most often useful when solving problems such as these. Since all the data is already available, taking the overall problem and breaking it down into smaller parts (with more detail as each level is attained) helps to make the overall task easier.</span>
5 0
3 years ago
Other questions:
  • In pre-shared key mode, a passphrase should be at least ________ characters long.
    15·1 answer
  • A ______________ is a document created when planning resource management to help promote teamwork and clarify team communication
    13·1 answer
  • What statement would you use to print the phrase Hello, world and then start a new line?
    8·1 answer
  • The part of a computer that provides access to the internet
    6·1 answer
  • The first thing you should select if you're using an Address Block or Greeting Line is
    11·1 answer
  • Online arguments that progressively escalate into insults and harsh language where the bully threatens and tries to intimidate a
    11·2 answers
  • Select the correct answer from each drop down menu
    8·2 answers
  • Kali, a Python programmer, is using the turtle module to write the word "hello." Which code should she use to indicate the locat
    9·2 answers
  • The D:\ drive in your computer has been formatted with NTFS. The Mary user account has been assigned the following permissions:
    10·1 answer
  • you're troubleshooting an ip addressing issue, and you issue a command to view the system's tcp/ip configuration. the command yo
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!