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

2. (14 points) A group of friends is organizing a ski trip. Write a program Cost

ID: 3605951 • Letter: 2

Question

2. (14 points) A group of friends is organizing a ski trip. Write a program CostEstimate.java that performs the following, Hotel room cost is $120 per day and is limited to 4 people. Lift ticket costs as follows: For a group with 1-5 people, cost is $90 per person per day For a group with 6-10 people, cost is $80 per person per day For a group with more than 10 people cost is $70 per person. People in the group will split the total cost evenly. Define a method called splitCost which takes one parameter, the number of people, calculates the per person price (room cost plus lift tickets cost), then returns the cost per person. Call splitCost method in the program to take user input of the size of the group, then estimate the trip cost per person per day. Program should be able to do multiple estimates until user enters -1 to quit. Sample output: Enter group size (-1 to quit): 2 Cost estimate per person per day: $150.00 Enter group size (-1 to quit): 3 Cost estimate per person per day: $130.00 Enter group size (-1 to quit): 5 Cost estimate per person per day: $138.00 Enter group size (-1 to quit): 7 Cost estimate per person per day: $114.29 Enter group size (-1 to quit): 12 Cost estimate per person per day: $100.00 Enter group size (-1 to quit):-1

Explanation / Answer

import java.io.*;
import java.util.*;

public class CostEstimate {

public static double splitCost(int n){

     double hotel_cost = 0;
     double lift_ticket_cost = 0;

     if (n <= 4 && n >= 1)
        hotel_cost = 120;
     else
        hotel_cost = 120 + 120 * (n/4);
    if (n <= 5 && n >= 1)
        lift_ticket_cost = n * 90;

    if (n <= 10 && n >= 6)
        lift_ticket_cost = n * 80;
    if (n > 10)
        lift_ticket_cost = n * 70;

    return (hotel_cost + lift_ticket_cost)/n;

       

    
}

   public static void main(String[] args){

       Scanner sc = new Scanner(System.in);

       while(true){
          System.out.print("Enter group size(-1 to quit):");
          int n = sc.nextInt();
          if (n == -1)
             break;
          System.out.println("Cost estimate per person per day: $" + String.format("%.2f",splitCost(n)));
      }
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote