A party planner is organizing a party. Write a program CostEstimate.java that pe
ID: 3857217 • Letter: A
Question
A party planner is organizing a party. Write a program CostEstimate.java that performs the following,
• Rental cost is $100. Food cost is as follows: For groups with 1-5 people, cost is $20 per person For groups with 6-10 people, cost is $18 per person For groups with 11-15 people cost is $16 per person For groups with more than 15 people, cost is $15 per person.
• Define a method called cost which takes one parameters, the number of people in the party, calculates the per person price (food cost with rental cost), then returns the cost per person.
• Call cost method in the program to produce a cost estimate table that shows the party size from 2, 4, up to 20 people. Sample output: Party Size (#people) Cost Estimate Per Person
2 $70.00
4 $45.00
6 $34.67
8 $30.50
10 $28.00
12 $24.33
….
20 $20.00
Explanation / Answer
public class HelloWorld
{
int rent_cost=100;
int food_cost;
void cost(int no_of_people)
{
if(no_of_people>=1 && no_of_people<=5)
{
food_cost=20;
double total_cost=(food_cost*no_of_people)+rent_cost;
System.out.println("Food cost is : "+food_cost);
System.out.println("Rent cost is : "+rent_cost);
System.out.println("Total cost is : "+total_cost+" for "+no_of_people+" People ");
System.out.println("Party Size "+no_of_people+" Cost Estimate Per Person: $"+total_cost/no_of_people);
}
if(no_of_people>=6 && no_of_people<=10)
{
food_cost=18;
double total_cost=(food_cost*no_of_people)+rent_cost;
System.out.println("Food cost is : "+food_cost);
System.out.println("Rent cost is : "+rent_cost);
System.out.println("Total cost is : "+total_cost+" for "+no_of_people+" People ");
System.out.println("Party Size "+no_of_people+" Cost Estimate Per Person: $"+total_cost/no_of_people);
}
if(no_of_people>=11 && no_of_people<=15)
{
food_cost=16;
double total_cost=(food_cost*no_of_people)+rent_cost;
System.out.println("Food cost is : "+food_cost);
System.out.println("Rent cost is : "+rent_cost);
System.out.println("Total cost is : "+total_cost+" for "+no_of_people+" People ");
System.out.println("Party Size "+no_of_people+" Cost Estimate Per Person: $"+total_cost/no_of_people);
}
if(no_of_people>15 )
{
food_cost=15;
double total_cost=(food_cost*no_of_people)+rent_cost;
System.out.println("Food cost is : "+food_cost);
System.out.println("Rent cost is : "+rent_cost);
System.out.println("Total cost is : "+total_cost+" for "+no_of_people+" People ");
System.out.println("Party Size "+no_of_people+" Cost Estimate Per Person: $"+total_cost/no_of_people);
}
}
public static void main(String []args)
{
int no_of_people=20;
HelloWorld h1=new HelloWorld();
System.out.println("========================================");
h1.cost(no_of_people);
System.out.println("========================================");
}
}
output:
Food cost is : 15
Rent cost is : 100
Total cost is : 400.0 for 20 People
Party Size 20 Cost Estimate Per Person: $20.0
---------------------------------------------------------------
Food cost is : 18
Rent cost is : 100
Total cost is : 208.0 for 6 People
Party Size 6 Cost Estimate Per Person: $34.666666666666664
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.