Final answer:
The movie ticket price can be calculated by dividing the total cost by the number of people in the group.
Use the buyTickets method to calculate the cost per person.
Step-by-step explanation:
The movie ticket price can be calculated by dividing the total cost by the number of people in the group.
In this case, the buyTickets method calculates the cost per person using the cost and numberOfPeople parameters.
Java program:
public static double buyTickets(int cost, int numberOfPeople)
{
return cost / (double) numberOfPeople;
}
In the given examples:
- buyTickets(10, 95) returns 9.5 (10 / 95 = 0.105, rounded to 9.5)
- buyTickets(20, 130) returns 6.5 (20 / 130 = 0.154, rounded to 6.5)
- buyTickets(4, 10) returns 2.5 (4 / 10 = 0.4, rounded to 2.5)