Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Case problem 1 (a) and (b) on Chapter 3 page 176 and 177 of Java Programming Tex

ID: 643774 • Letter: C

Question

Case problem 1 (a) and (b) on Chapter 3 page 176 and 177 of Java Programming Textbook edition 7 by Farrell. Case problem 1 (a) and (b) on Chapter 3 page 176 and 177 of Java Programming Textbook edition 7 by Farrell. Points will be awarded once I run the code. 1. a. Carly's Catering provides meals for parties and special events. In Chapter 2, you wrote an application that prompts the user for the number of guests attending an event, displays the company motto with a border, and then displays the price of the event and whether the event is a large one. Now modify the program so that the main() method contains only three executable statements that each call a method as follows: The first executable statement calls a public static int method that prompts the user for the number of guests and returns the value to the main() method. The second executable statement calls a public static void method that displays the company motto with the border. The last executable statement passes the number of guests to a public static void method that computes the price of the event, displays the price, and displays whether the event is a large event. Save the file as CarlysEventPriceWithMethodsjava. b. Create a class to hold Event data for Carly's Catering. The class contains: Two public final static fields that hold the price per guest (dollar35) and the cutoff value for a large event (50 guests) Three private fields that hold an event number, number of guests for the event, and the price. The evens number is stored as a String because Carly plans to assign event numbers such as M312. Two public set methods that set the event number (setEventNumberO) and the number of guests (setGuests()). The price does not have a set method because the setGuests() method will calculate the price as the number of guests multiplied by the price per guest every time the number of guests is set. Three public get methods that return the values in the three nonstatic fields Save the file as Eventjava.

Explanation / Answer

import java.util.Scanner;
class Event{
public final static int pricePerGuest=35;
public final static int threshold=50;
private int eventNumber;
private int numGuest;
private int price;
public void setEventNumber(int n){eventNumber=n;}
public void setGuests(int n){numGuest=n;}
public int getEventNumber(){return eventNumber;}
public int getGuests(){return numGuest;}
public int getPrice(){price=pricePerGuest*numGuest;return price;}
}

public class CarlysEventPriceWithMethods {
public static int GetNumGuests()
{
Scanner in=new Scanner(System.in);
System.out.print("Enter number of Guests:");
int n=in.nextInt();
return n;
}
public static void PrintMotto()
{
System.out.println("----------------------------");
System.out.println("|We want whats best for you|");
System.out.println("----------------------------");
}
  
public static void PartySize(int numG)
{
Event a=new Event();
a.setGuests(numG);
a.setEventNumber(1);
System.out.println("Price of the event:"+a.getPrice());
if(numG>=Event.threshold)
System.out.println("The event is large");
else
System.out.println("The event is not large");
}
  
public static void main(String arg[])
{
int n=GetNumGuests();
PrintMotto();
PartySize(n);
}
}