30.7k views
4 votes
Answer in java, without using print or println. only return

You and a group of friends are going to the movie. The movie theater has agreed to sell you tickets as a group. Given the cost and the number of people, complete the movie ticket method to determine how much each person must pay for the ticket.

buyTickets(10, 95) → 9.5

buyTickets(20, 130) → 6.5

buyTickets(4, 10) → 2.5

User Quis
by
7.8k points

1 Answer

2 votes

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)
User Lauri Lehtinen
by
8.9k points