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

I\'m stuck on this java assignment. How should I start this problem? Can this be

ID: 3857030 • Letter: I

Question

I'm stuck on this java assignment. How should I start this problem? Can this be done in cases?

Anything help. Thanks!

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 Pe rson $70.00 $45.00 $34.67 $30.50 $28.00 $24.33 4 10 12 20 $20.00|

Explanation / Answer

Hi,

There are multiple ways to go about this problem - you can maintain a MAP of the food costs, but a simple switch case shall suffice too :)

public class CostEstimate {

public int cost (int numberOfPersons) {

final int RENTAL_COST = 100;

int foodCost = 0;

if (numberOfPersons >=1 && numberOfPersons <=5) {foodCost = 20;}
else if (numberOfPersons >=6 && numberOfPersons <=10) {foodCost = 18;}
else if (numberOfPersons >=11&& numberOfPersons <=15) {foodCost = 16;}
else if (numberOfPersons >15) {foodCost = 15;}
int cost_per_person = (RENTAL_COST) + (foodCost * numberOfPersons);

return cost_per_person;
}


public static void main (String args[]) {

System.out.println("Party Size" + " " + "Cost Estimate per person");
for (int i=2; i<=20; i=i+2){

System.out.println( i + " " + cost(i));

}

}

}