Explanation of Solution
a.
CarlysEventPriceWithMethods.java
//import the required packages
import java.util.Scanner;
//define a method CarlysEventPriceWithMethods
public class CarlysEventPriceWithMethods
{
//Scanner object
private static Scanner sc = new Scanner(System.in);
//define a method getEventNum()
public static String getEventNum()
{
//print the statement
System.out.println("Enter event number: ");
//scan the values
return sc.next();
}
//define the method getNoGuests
public static int getNoOfGuests()
{
//print the statement
System.out.println("Enter no of guests: ");
//return the value scanned
return sc.nextInt();
}
//define the method displayMotto()
public static void displayMotto(Event e)
{
//prin the values
System.out.println(String.format("%26s", " ").replace(" ", "*"));
System.out.printf("* %22s *", " ");
System.out.println("\n* Carly’s Catering *");
System.out.printf("* %22s *\n", " ");
System.out.println(String.format("%26s", " ").replace(" ", "*"));
System.out.println("Event No: " + e.getEventNum());
System.out.println("No. of guests:" + e.getNoOfGuest());
System.out.println("Price per guest: $" + Event.PRICE_PER_GUEST);
//call the method computePrice
computePrice(e);
}
//define the method computePrice
public static void computePrice(Event e)
{
//print the values
System.out.println("Price: $" + e.getPrice());
System.out.println("Large event: " + ((e.getNoOfGuest() > Event.CUT_OFF) ? "Yes" : "No"));
}
//define the main method
public static void main(String[] args)
{
//Close scanner
sc.close();
}
}
Explanation:
The above snippet of code is used to create a class “CarlysEventPriceWithMethods”. In the code,
- Import the required header files.
- Define a class “CarlysEventPriceWithMethods”
- Declare the object of “Scanner” class.
- Define the “getEventNum()” method.
- Prompt the user to enter the event number.
- Return the value of “name”.
- Define the “getNoGuests()” method.
- Return the scanned value.
- Define the “displayMotto()” method.
- Print the values.
- Call the method “computePrice()”.
- Define the “computePrice()” method.
- Print the values.
- Define the “main()” method.
- Close the scanner.
b.
Event.java
//define a class Event
public class Event
{
//declare the class members
public final static int PRICE_PER_GUEST = 35;
public final static int CUT_OFF = 50;
private String eventNum;
private int noOfGuest;
private int price;
//define a method setEventNum()
public void setEventNum(String eventNum)
{
//set the value of eventNum
this.eventNum = eventNum;
}
//define a method setNoOfGuest()
public void setNoOfGuest(int noOfGuest)
{
//set the values of noOfGuest
this.noOfGuest = noOfGuest;
//set the values of price
this...
Trending nowThis is a popular solution!
Chapter 3 Solutions
EBK JAVA PROGRAMMING
- 2. Case Problems 1 (three parts) - 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 CarlysEventPriceWithMethods.java. b. Create a class to…arrow_forwardThis C# program assignment requires that you write and call two programmer defined methods as described below: Method #1 (MyAddress) – this programmer defined method should output your name and address in a mailing label format. This method does not require any parameters, and will not return any value. Method #2 (AddressOut) – this programmer defined method should have three string parameters (name, address, and city‐state‐zip) and should output the passed parameters in mailing label format. This method will not return any value. Your Main() method for this program should consist of two lines of code – calls to each of the methods. Here is an example of the code in my Main() method MyAddress(); AddressOut(“Tim Jones”, “123 Main St.”, “East Brunswick, NJ 08816”);arrow_forwardThe program must include two classesclGradesGraph and GradesGrapghDemo. GradesGraphDemo (one method)- Main method only GradesGraph- Include at least 4 methods (No credits without at least 4 methods!!!) Create a class that represents the grade distribution for a given course. In this class you should write methods to perform the following tasks: Read the number of each of the letter grades A, B, C D and F Set the number of letter grades A, B, C, D and F Return the total number of grades Return the percentage of each letter grade as a whole number between 0 and 100 inclusive Draw a bar graph of the grade distributionThe graph should have five bars, one per grade. Each bar can be a horizontal row of asterisks, such that the number of asterisks in a row is proportionate to the percentage of grades in each category. For example, let on asterisk represent 2%, so 50 asterisks correspond to 100%. Mark the horizontal axis at 10% increments from 0 to 100% and label each line with a letter…arrow_forward
- True or False: When passing multiple arguments to a method, the order in which the arguments are passed is not important.arrow_forwardDon't use AI.arrow_forwardTravel Tickets Company sells tickets for airlines, tours, and other travel-related services. Because ticket agents frequently mistype long ticket numbers, Travel Tickets has asked you to write an application that indicates invalid ticket number entries. The class prompts a ticket agent to enter a six-digit ticket number. Ticket numbers are designed so that if you drop the last digit of the number, then divide the number by 7, the remainder of the division will be identical to the last dropped digit. Accept the ticket number from the agent and verify whether it is a valid number. Test the application with the following ticket numbers: . 123454; the comparison should evaluate to true . 147103; the comparison should evaluate to true . 154123; the comparison should evaluate to false Save the program as TicketNumber.java.arrow_forward
- c# uppose there is a method called Current Deposit is your project class. The method header is as below: public static decimal Current Deposit( in years , decimal future, double rate) This method will return the current amount of money in an account if you pass the future amount, the annual interest rate, and years number. Write one statement to declare a decimal variable myMoney, call the method with the future amount $50,000.00, interest rate 8%, and 15 years, and assign the returned value to myMoney.arrow_forwardTrue or False: During method calls, the value of a local variable is preserved.arrow_forwardDiscount Insurance provides motor vehicle insurance to its customers. The company is introducing a new discount program for its customers. You have been hired by the insurance company to create a java application to calculate policy discounts for all customers. Not all customers are eligible for a discount. Only customers who have held a policy longer than 3 years are eligible. In addition, a customer must have a driver rating of “Excellent”, “Above Average”, or “Average”. Customers with a rating of “Below Average” are not eligible for a discount. The discount amount is calculated based on the driver’s rating and percentages of current yearly premium as shown below: Rating Percent Discount Excellent 15% Above Average 10% Average 5% For example: A customer holding a policy for 5 years with an “Excellent” rating and current yearly premium of $450, will get a discount calculated as: $450 * .15 = $67.50 Your goal is to create an application to allow a user…arrow_forward
- A(n) __________ is a special variable that receives an argument when a method is called. a. reference variable b. argument variable c. parameter variable d. method variablearrow_forwardRetail StoreSuppose you have been consulted by a retail shop around your area to build a simple calculator. The calculator must be able to perform arithmetic operations (+, -, *, /) on integers. The program receives an expression from the user. The expression is structured as follows: integer input followed by an operator and another integer input from user prior to displaying the final result. Write a Java application that can perform the above expression. Create a method that takes two parameters and performs an arithmetic operation on the passed values. Your final output should consist of the expression and the result.arrow_forwardC# Languagearrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage