Java Programming
Java Programming
9th Edition
ISBN: 9780357238530
Author: Joyce Farrell
Publisher: Cengage Limited
Expert Solution & Answer
Book Icon
Chapter 3, Problem 1CP

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...

Blurred answer
Students have asked these similar questions
This is a question that I have and would like someone who has experiences with scene graphs and entity component systems to answer.For context, I am currently implementing a game engine and currently I am debating on our current design.Our current design is we have a singular game component class that every component inherits from. Where we have components like SpriteRendererComponent, Mehs Component, etc. They inherit from this GameComponent class. The point of this is being able to have O(1) access to the scene to being able to modify components to attach more components with the idea of accessing those components to specific scene objects in a scene.Now, my question is what kinds of caveauts can this cause in terms of cache coherence? I am well aware that yes its O(1) and that is great but cache coherence is going to be really bad, but would like to know more explicit details and real-life examples such as write in RAM examples on how this is bad. A follow-up question that is part…
Q4: Consider the following MAILORDER relational schema describing the data for a mail order company. (Choose five only). PARTS(Pno, Pname, Qoh, Price, Olevel) CUSTOMERS(Cno, Cname, Street, Zip, Phone) EMPLOYEES(Eno, Ename, Zip, Hdate) ZIP CODES(Zip, City) ORDERS(Ono, Cno, Eno, Received, Shipped) ODETAILS(Ono, Pno, Qty) (10 Marks) I want a detailed explanation to understand the mechanism how it is Qoh stands for quantity on hand: the other attribute names are self-explanatory. Specify and execute the following queries using the RA interpreter on the MAILORDER database schema. a. Retrieve the names of parts that cost less than $20.00. b. Retrieve the names and cities of employees who have taken orders for parts costing more than $50.00. c. Retrieve the pairs of customer number values of customers who live in the same ZIP Code. d. Retrieve the names of customers who have ordered parts from employees living in Wichita. e. Retrieve the names of customers who have ordered parts costing less…
Q4: Consider the following MAILORDER relational schema describing the data for a mail order company. (Choose five only). (10 Marks) PARTS(Pno, Pname, Qoh, Price, Olevel) CUSTOMERS(Cno, Cname, Street, Zip, Phone) EMPLOYEES(Eno, Ename, Zip, Hdate) ZIP CODES(Zip, City) ORDERS(Ono, Cno, Eno, Received, Shipped) ODETAILS(Ono, Pno, Qty) Qoh stands for quantity on hand: the other attribute names are self-explanatory. Specify and execute the following queries using the RA interpreter on the MAILORDER database schema. a. Retrieve the names of parts that cost less than $20.00. b. Retrieve the names and cities of employees who have taken orders for parts costing more than $50.00. c. Retrieve the pairs of customer number values of customers who live in the same ZIP Code. d. Retrieve the names of customers who have ordered parts from employees living in Wichita. e. Retrieve the names of customers who have ordered parts costing less than$20.00. f. Retrieve the names of customers who have not placed…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,