SlideShare a Scribd company logo
1 of 7
Download to read offline
**Please respond only if you can answer the whole question**
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Java Programming: Ch 6 Case Problem 1
Carly’s Catering provides meals for parties and special events. In previous chapters, you
developed a class that holds catering event information and an application that tests the methods
using four objects of the class. Now modify the EventDemo class to do the following:
Continuously prompt for the number of guests for each Event until the value falls between 5 and
100 inclusive.
For one of the Event objects, create a loop that displays “Please come to my event!” as many
times as there are guests for the Event.
Save the modified file as EventDemo.java.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Please use code to answer question:
import java.util.Scanner;
public class Event {
public final static double LOWER_PRICE_PER_GUEST = 32.00;
public final static double HIGHER_PRICE_PER_GUEST = 35.00;
public final static int CUTOFF_VALUE = 50;
public boolean largeEvent;
private String eventNum;
private int numOfGuests;
private double price;
private double pricePerGuest;
public Event(String event, int guests) {
eventNum = event;
numOfGuests = guests;
}
public Event() {
this("A000", 0);
}
private Scanner input = new Scanner(System.in);
public void setEventNumber() {
System.out.print("What is the event number? ");
eventNum = input.nextLine();
}
public void setNumOfGuests() {
System.out.print("How many guests are attending the event? ");
numOfGuests = input.nextInt();
if (isLargeEvent())
pricePerGuest = LOWER_PRICE_PER_GUEST;
else
pricePerGuest = HIGHER_PRICE_PER_GUEST;
largeEvent = (numOfGuests >= CUTOFF_VALUE);
price = numOfGuests * pricePerGuest;
System.out.println("");
}
public boolean isLargeEvent(){
if(this.getNumOfGuests() >= 50)
return true;
else
return false;
}
public String getEventNumber() {
return eventNum;
}
public int getNumOfGuests() {
return numOfGuests;
}
public double getPrice() {
return price;
}
public double getPricePerGuest(){
return pricePerGuest;
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public class EventDemo {
public static void main(String[] args) {
Event event1 = new Event();
System.out.println("Event #1: ");
event1.setEventNumber();
event1.setNumOfGuests();
Event event2 = new Event();
System.out.println("Event #2: ");
event2.setEventNumber();
event2.setNumOfGuests();
Event event3 = new Event();
System.out.println("Event #3: ");
event3.setEventNumber();
event3.setNumOfGuests();
display(event1);
display(event2);
display(event3);
System.out.println("Display larger event comparing Event #1 and Event #2: ");
display(largerEvent(event1, event2));
System.out.println("Display larger event comparing Event #2 and Event #3: ");
display(largerEvent(event2, event3));
System.out.println("Display larger event comparing Event #1 and Event #3: ");
display(largerEvent(event1, event3));
}
public static void display(Event e) {
System.out.println("Event number: " + e.getEventNumber());
System.out.println("Total guests: " + e.getNumOfGuests());
System.out.println("Total price per guest: $" + String.format("%.2f",
e.getPricePerGuest()));
System.out.println("Total price: $" + String.format("%.2f", e.getPrice()));
System.out.println("Large event: " + e.isLargeEvent());
System.out.println("");
}
public static Event largerEvent (Event e1, Event e2){
if (e1.getNumOfGuests() >= e2.getNumOfGuests())
return e1;
else
return e2;
}
}
Solution
import java.util.Scanner;
public class Event {
public final static double LOWER_PER_GUEST = 32.00;
public final static double HIGHER_PER_GUEST = 35.00;
public final static int CUTOFF_VALUE = 50;
public boolean largeEvent;
private String eventNum;
private int numOfGuests;
private double price;
private double pricePerGuest;
public Event(String event, int guests) {
eventNum = event;
numOfGuests = guests;
}
public Event() {
this("A000", 0);
}
private Scanner input = new Scanner(System.in);
public void setEventNumber() {
System.out.print("What is the event number? ");
eventNum = input.nextLine();
}
public void setNumOfGuests() {
do {
System.out.print("How many guests are attending the event? ");
int guests = input.nextInt();
if (guests >= 5 && guests <= 100) {
numOfGuests = guests;
if (isLargeEvent())
pricePerGuest = LOWER_PER_GUEST;
else
pricePerGuest = HIGHER_PER_GUEST;
price = numOfGuests * pricePerGuest;
largeEvent = (numOfGuests >= CUTOFF_VALUE);
} else {
break;
}
} while (true);
// System.out.println("");
}
public boolean isLargeEvent() {
if (this.getNumOfGuests() > 50)
return true;
else
return false;
}
public String getEventNumber() {
return eventNum;
}
public int getNumOfGuests() {
return numOfGuests;
}
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.setNumOfGuests();
display(event1);
for (int i = 0; i < event1.getNumOfGuests(); i++) {
System.out.println("Please come to my event!");
}
}
public static void display(Event e) {
System.out.println("Event number: " + e.getEventNumber());
System.out.println("Total guests: " + e.getNumOfGuests());
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.getNumOfGuests() > e2.getNumOfGuests())
return e1;
else
return e2;
}
}
OUTPUT:
Enter Details of event1:
What is the event number? 58
How many guests are attending the event? 5
How many guests are attending the event? 4
Event number: 58
Total guests: 5
Total price: $175.00
Is Large event: false
Please come to my event!
Please come to my event!
Please come to my event!
Please come to my event!
Please come to my event!

More Related Content

Similar to Please respond only if you can answer the whole question ~~~~~.pdf

TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
Logic Equations Resolver J Script
Logic Equations Resolver   J ScriptLogic Equations Resolver   J Script
Logic Equations Resolver J ScriptRoman Agaev
 
ECMAScript 6 new features
ECMAScript 6 new featuresECMAScript 6 new features
ECMAScript 6 new featuresGephenSG
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxwhitneyleman54422
 
Symfony (Unit, Functional) Testing.
Symfony (Unit, Functional) Testing.Symfony (Unit, Functional) Testing.
Symfony (Unit, Functional) Testing.Basel Issmail
 
Please find my solution.Please let me know in case of any issue..pdf
Please find my solution.Please let me know in case of any issue..pdfPlease find my solution.Please let me know in case of any issue..pdf
Please find my solution.Please let me know in case of any issue..pdfpremkhatri99
 
Kotlin : Advanced Tricks - Ubiratan Soares
Kotlin : Advanced Tricks - Ubiratan SoaresKotlin : Advanced Tricks - Ubiratan Soares
Kotlin : Advanced Tricks - Ubiratan SoaresiMasters
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsSam Hennessy
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesEric Poe
 
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにPHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにYuya Takeyama
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleHugo Hamon
 
PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021Ayesh Karunaratne
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testingVisual Engineering
 
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfcalderoncasto9163
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologyDaniel Knell
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
 
JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)Anders Jönsson
 
From typing the test to testing the type
From typing the test to testing the typeFrom typing the test to testing the type
From typing the test to testing the typeWim Godden
 

Similar to Please respond only if you can answer the whole question ~~~~~.pdf (20)

TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Logic Equations Resolver J Script
Logic Equations Resolver   J ScriptLogic Equations Resolver   J Script
Logic Equations Resolver J Script
 
An intro to cqrs
An intro to cqrsAn intro to cqrs
An intro to cqrs
 
ECMAScript 6 new features
ECMAScript 6 new featuresECMAScript 6 new features
ECMAScript 6 new features
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
 
Symfony (Unit, Functional) Testing.
Symfony (Unit, Functional) Testing.Symfony (Unit, Functional) Testing.
Symfony (Unit, Functional) Testing.
 
Please find my solution.Please let me know in case of any issue..pdf
Please find my solution.Please let me know in case of any issue..pdfPlease find my solution.Please let me know in case of any issue..pdf
Please find my solution.Please let me know in case of any issue..pdf
 
Kotlin : Advanced Tricks - Ubiratan Soares
Kotlin : Advanced Tricks - Ubiratan SoaresKotlin : Advanced Tricks - Ubiratan Soares
Kotlin : Advanced Tricks - Ubiratan Soares
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
 
PHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return TypesPHP7 - Scalar Type Hints & Return Types
PHP7 - Scalar Type Hints & Return Types
 
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにPHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くために
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
 
ES6 generators
ES6 generatorsES6 generators
ES6 generators
 
PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testing
 
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)
 
From typing the test to testing the type
From typing the test to testing the typeFrom typing the test to testing the type
From typing the test to testing the type
 

More from hadpadrrajeshh

Given a newly created Binary Search Tree with the following numerica.pdf
Given a newly created Binary Search Tree with the following numerica.pdfGiven a newly created Binary Search Tree with the following numerica.pdf
Given a newly created Binary Search Tree with the following numerica.pdfhadpadrrajeshh
 
Gather information on the following two disasters Space shuttle Ch.pdf
Gather information on the following two disasters Space shuttle Ch.pdfGather information on the following two disasters Space shuttle Ch.pdf
Gather information on the following two disasters Space shuttle Ch.pdfhadpadrrajeshh
 
Determine the Laplace transform, F(s), of the following time signal..pdf
Determine the Laplace transform, F(s), of the following time signal..pdfDetermine the Laplace transform, F(s), of the following time signal..pdf
Determine the Laplace transform, F(s), of the following time signal..pdfhadpadrrajeshh
 
Describe the difference between a monitor and a semaphoreSolutio.pdf
Describe the difference between a monitor and a semaphoreSolutio.pdfDescribe the difference between a monitor and a semaphoreSolutio.pdf
Describe the difference between a monitor and a semaphoreSolutio.pdfhadpadrrajeshh
 
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfCreate a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfhadpadrrajeshh
 
A speedometer is a measuring instrument. What are the independent and.pdf
A speedometer is a measuring instrument. What are the independent and.pdfA speedometer is a measuring instrument. What are the independent and.pdf
A speedometer is a measuring instrument. What are the independent and.pdfhadpadrrajeshh
 
A recent study by the EPA has determined that the amount of contamin.pdf
A recent study by the EPA has determined that the amount of contamin.pdfA recent study by the EPA has determined that the amount of contamin.pdf
A recent study by the EPA has determined that the amount of contamin.pdfhadpadrrajeshh
 
choice one correct answerRocks containing iron, calcium, magnesium.pdf
choice one correct answerRocks containing iron, calcium, magnesium.pdfchoice one correct answerRocks containing iron, calcium, magnesium.pdf
choice one correct answerRocks containing iron, calcium, magnesium.pdfhadpadrrajeshh
 
1.write down the RTL for the SUBT instructions. 2.Draw a flowchart.pdf
1.write down the RTL for the SUBT instructions. 2.Draw a flowchart.pdf1.write down the RTL for the SUBT instructions. 2.Draw a flowchart.pdf
1.write down the RTL for the SUBT instructions. 2.Draw a flowchart.pdfhadpadrrajeshh
 
Write a Java application that asks for an integer and returns its fac.pdf
Write a Java application that asks for an integer and returns its fac.pdfWrite a Java application that asks for an integer and returns its fac.pdf
Write a Java application that asks for an integer and returns its fac.pdfhadpadrrajeshh
 
Where should seaweeds and kelps be classified Give characteristics .pdf
Where should seaweeds and kelps be classified Give characteristics .pdfWhere should seaweeds and kelps be classified Give characteristics .pdf
Where should seaweeds and kelps be classified Give characteristics .pdfhadpadrrajeshh
 
What is the name of the connective tissue that divides the se.pdf
What is the name of the connective tissue that divides the se.pdfWhat is the name of the connective tissue that divides the se.pdf
What is the name of the connective tissue that divides the se.pdfhadpadrrajeshh
 
What is the current ratio of Chester Use the results of the Balance.pdf
What is the current ratio of Chester Use the results of the Balance.pdfWhat is the current ratio of Chester Use the results of the Balance.pdf
What is the current ratio of Chester Use the results of the Balance.pdfhadpadrrajeshh
 
What is glass-transition temperature Give a material example. How ma.pdf
What is glass-transition temperature Give a material example. How ma.pdfWhat is glass-transition temperature Give a material example. How ma.pdf
What is glass-transition temperature Give a material example. How ma.pdfhadpadrrajeshh
 
What are some contributions to the development of industrializat.pdf
What are some contributions to the development of industrializat.pdfWhat are some contributions to the development of industrializat.pdf
What are some contributions to the development of industrializat.pdfhadpadrrajeshh
 
The “creative revolution” that handed more authority to agency art d.pdf
The “creative revolution” that handed more authority to agency art d.pdfThe “creative revolution” that handed more authority to agency art d.pdf
The “creative revolution” that handed more authority to agency art d.pdfhadpadrrajeshh
 
The three main coefficients (not properties or dimensionless numbers).pdf
The three main coefficients (not properties or dimensionless numbers).pdfThe three main coefficients (not properties or dimensionless numbers).pdf
The three main coefficients (not properties or dimensionless numbers).pdfhadpadrrajeshh
 
The project will study the coordination of multiple threads using se.pdf
The project will study the coordination of multiple threads using se.pdfThe project will study the coordination of multiple threads using se.pdf
The project will study the coordination of multiple threads using se.pdfhadpadrrajeshh
 
The positive selection process for T lymphocytes that occurs In the t.pdf
The positive selection process for T lymphocytes that occurs In the t.pdfThe positive selection process for T lymphocytes that occurs In the t.pdf
The positive selection process for T lymphocytes that occurs In the t.pdfhadpadrrajeshh
 
The local public health agency has received reports of an outbreak o.pdf
The local public health agency has received reports of an outbreak o.pdfThe local public health agency has received reports of an outbreak o.pdf
The local public health agency has received reports of an outbreak o.pdfhadpadrrajeshh
 

More from hadpadrrajeshh (20)

Given a newly created Binary Search Tree with the following numerica.pdf
Given a newly created Binary Search Tree with the following numerica.pdfGiven a newly created Binary Search Tree with the following numerica.pdf
Given a newly created Binary Search Tree with the following numerica.pdf
 
Gather information on the following two disasters Space shuttle Ch.pdf
Gather information on the following two disasters Space shuttle Ch.pdfGather information on the following two disasters Space shuttle Ch.pdf
Gather information on the following two disasters Space shuttle Ch.pdf
 
Determine the Laplace transform, F(s), of the following time signal..pdf
Determine the Laplace transform, F(s), of the following time signal..pdfDetermine the Laplace transform, F(s), of the following time signal..pdf
Determine the Laplace transform, F(s), of the following time signal..pdf
 
Describe the difference between a monitor and a semaphoreSolutio.pdf
Describe the difference between a monitor and a semaphoreSolutio.pdfDescribe the difference between a monitor and a semaphoreSolutio.pdf
Describe the difference between a monitor and a semaphoreSolutio.pdf
 
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdfCreate a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
 
A speedometer is a measuring instrument. What are the independent and.pdf
A speedometer is a measuring instrument. What are the independent and.pdfA speedometer is a measuring instrument. What are the independent and.pdf
A speedometer is a measuring instrument. What are the independent and.pdf
 
A recent study by the EPA has determined that the amount of contamin.pdf
A recent study by the EPA has determined that the amount of contamin.pdfA recent study by the EPA has determined that the amount of contamin.pdf
A recent study by the EPA has determined that the amount of contamin.pdf
 
choice one correct answerRocks containing iron, calcium, magnesium.pdf
choice one correct answerRocks containing iron, calcium, magnesium.pdfchoice one correct answerRocks containing iron, calcium, magnesium.pdf
choice one correct answerRocks containing iron, calcium, magnesium.pdf
 
1.write down the RTL for the SUBT instructions. 2.Draw a flowchart.pdf
1.write down the RTL for the SUBT instructions. 2.Draw a flowchart.pdf1.write down the RTL for the SUBT instructions. 2.Draw a flowchart.pdf
1.write down the RTL for the SUBT instructions. 2.Draw a flowchart.pdf
 
Write a Java application that asks for an integer and returns its fac.pdf
Write a Java application that asks for an integer and returns its fac.pdfWrite a Java application that asks for an integer and returns its fac.pdf
Write a Java application that asks for an integer and returns its fac.pdf
 
Where should seaweeds and kelps be classified Give characteristics .pdf
Where should seaweeds and kelps be classified Give characteristics .pdfWhere should seaweeds and kelps be classified Give characteristics .pdf
Where should seaweeds and kelps be classified Give characteristics .pdf
 
What is the name of the connective tissue that divides the se.pdf
What is the name of the connective tissue that divides the se.pdfWhat is the name of the connective tissue that divides the se.pdf
What is the name of the connective tissue that divides the se.pdf
 
What is the current ratio of Chester Use the results of the Balance.pdf
What is the current ratio of Chester Use the results of the Balance.pdfWhat is the current ratio of Chester Use the results of the Balance.pdf
What is the current ratio of Chester Use the results of the Balance.pdf
 
What is glass-transition temperature Give a material example. How ma.pdf
What is glass-transition temperature Give a material example. How ma.pdfWhat is glass-transition temperature Give a material example. How ma.pdf
What is glass-transition temperature Give a material example. How ma.pdf
 
What are some contributions to the development of industrializat.pdf
What are some contributions to the development of industrializat.pdfWhat are some contributions to the development of industrializat.pdf
What are some contributions to the development of industrializat.pdf
 
The “creative revolution” that handed more authority to agency art d.pdf
The “creative revolution” that handed more authority to agency art d.pdfThe “creative revolution” that handed more authority to agency art d.pdf
The “creative revolution” that handed more authority to agency art d.pdf
 
The three main coefficients (not properties or dimensionless numbers).pdf
The three main coefficients (not properties or dimensionless numbers).pdfThe three main coefficients (not properties or dimensionless numbers).pdf
The three main coefficients (not properties or dimensionless numbers).pdf
 
The project will study the coordination of multiple threads using se.pdf
The project will study the coordination of multiple threads using se.pdfThe project will study the coordination of multiple threads using se.pdf
The project will study the coordination of multiple threads using se.pdf
 
The positive selection process for T lymphocytes that occurs In the t.pdf
The positive selection process for T lymphocytes that occurs In the t.pdfThe positive selection process for T lymphocytes that occurs In the t.pdf
The positive selection process for T lymphocytes that occurs In the t.pdf
 
The local public health agency has received reports of an outbreak o.pdf
The local public health agency has received reports of an outbreak o.pdfThe local public health agency has received reports of an outbreak o.pdf
The local public health agency has received reports of an outbreak o.pdf
 

Recently uploaded

Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 

Recently uploaded (20)

Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 

Please respond only if you can answer the whole question ~~~~~.pdf

  • 1. **Please respond only if you can answer the whole question** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Java Programming: Ch 6 Case Problem 1 Carly’s Catering provides meals for parties and special events. In previous chapters, you developed a class that holds catering event information and an application that tests the methods using four objects of the class. Now modify the EventDemo class to do the following: Continuously prompt for the number of guests for each Event until the value falls between 5 and 100 inclusive. For one of the Event objects, create a loop that displays “Please come to my event!” as many times as there are guests for the Event. Save the modified file as EventDemo.java. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Please use code to answer question: import java.util.Scanner; public class Event { public final static double LOWER_PRICE_PER_GUEST = 32.00; public final static double HIGHER_PRICE_PER_GUEST = 35.00; public final static int CUTOFF_VALUE = 50; public boolean largeEvent; private String eventNum; private int numOfGuests; private double price; private double pricePerGuest; public Event(String event, int guests) { eventNum = event; numOfGuests = guests; } public Event() {
  • 2. this("A000", 0); } private Scanner input = new Scanner(System.in); public void setEventNumber() { System.out.print("What is the event number? "); eventNum = input.nextLine(); } public void setNumOfGuests() { System.out.print("How many guests are attending the event? "); numOfGuests = input.nextInt(); if (isLargeEvent()) pricePerGuest = LOWER_PRICE_PER_GUEST; else pricePerGuest = HIGHER_PRICE_PER_GUEST; largeEvent = (numOfGuests >= CUTOFF_VALUE); price = numOfGuests * pricePerGuest; System.out.println(""); } public boolean isLargeEvent(){ if(this.getNumOfGuests() >= 50) return true; else return false; } public String getEventNumber() { return eventNum; }
  • 3. public int getNumOfGuests() { return numOfGuests; } public double getPrice() { return price; } public double getPricePerGuest(){ return pricePerGuest; } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public class EventDemo { public static void main(String[] args) { Event event1 = new Event(); System.out.println("Event #1: "); event1.setEventNumber(); event1.setNumOfGuests(); Event event2 = new Event(); System.out.println("Event #2: "); event2.setEventNumber(); event2.setNumOfGuests(); Event event3 = new Event(); System.out.println("Event #3: "); event3.setEventNumber(); event3.setNumOfGuests(); display(event1); display(event2);
  • 4. display(event3); System.out.println("Display larger event comparing Event #1 and Event #2: "); display(largerEvent(event1, event2)); System.out.println("Display larger event comparing Event #2 and Event #3: "); display(largerEvent(event2, event3)); System.out.println("Display larger event comparing Event #1 and Event #3: "); display(largerEvent(event1, event3)); } public static void display(Event e) { System.out.println("Event number: " + e.getEventNumber()); System.out.println("Total guests: " + e.getNumOfGuests()); System.out.println("Total price per guest: $" + String.format("%.2f", e.getPricePerGuest())); System.out.println("Total price: $" + String.format("%.2f", e.getPrice())); System.out.println("Large event: " + e.isLargeEvent()); System.out.println(""); } public static Event largerEvent (Event e1, Event e2){ if (e1.getNumOfGuests() >= e2.getNumOfGuests()) return e1; else return e2; } } Solution import java.util.Scanner; public class Event { public final static double LOWER_PER_GUEST = 32.00; public final static double HIGHER_PER_GUEST = 35.00; public final static int CUTOFF_VALUE = 50; public boolean largeEvent;
  • 5. private String eventNum; private int numOfGuests; private double price; private double pricePerGuest; public Event(String event, int guests) { eventNum = event; numOfGuests = guests; } public Event() { this("A000", 0); } private Scanner input = new Scanner(System.in); public void setEventNumber() { System.out.print("What is the event number? "); eventNum = input.nextLine(); } public void setNumOfGuests() { do { System.out.print("How many guests are attending the event? "); int guests = input.nextInt(); if (guests >= 5 && guests <= 100) { numOfGuests = guests; if (isLargeEvent()) pricePerGuest = LOWER_PER_GUEST; else pricePerGuest = HIGHER_PER_GUEST; price = numOfGuests * pricePerGuest; largeEvent = (numOfGuests >= CUTOFF_VALUE); } else { break; } } while (true); // System.out.println(""); } public boolean isLargeEvent() { if (this.getNumOfGuests() > 50)
  • 6. return true; else return false; } public String getEventNumber() { return eventNum; } public int getNumOfGuests() { return numOfGuests; } 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.setNumOfGuests(); display(event1); for (int i = 0; i < event1.getNumOfGuests(); i++) { System.out.println("Please come to my event!"); } } public static void display(Event e) { System.out.println("Event number: " + e.getEventNumber()); System.out.println("Total guests: " + e.getNumOfGuests()); 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) {
  • 7. if (e1.getNumOfGuests() > e2.getNumOfGuests()) return e1; else return e2; } } OUTPUT: Enter Details of event1: What is the event number? 58 How many guests are attending the event? 5 How many guests are attending the event? 4 Event number: 58 Total guests: 5 Total price: $175.00 Is Large event: false Please come to my event! Please come to my event! Please come to my event! Please come to my event! Please come to my event!