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

A group of friends is organizing a ski trip. Write a program CostEstimate.java t

ID: 3684958 • Letter: A

Question

   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.      
Output should be like:  
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.util.Scanner;

/**
* @author Srinivas Palli
*
*/
public class CostEstimate {

   /**
   * @param args
   */
   public static void main(String[] args) {

       Scanner scanner = null;

       try {

           do {
               scanner = new Scanner(System.in);
               System.out.print("Enter group size (-1 to quit):");
               int groupSize = scanner.nextInt();
               if (groupSize == -1)
                   break;

               else
                   System.out.printf(
                           "Cost estimate per person per day: $%.2f ",
                           splitCost(groupSize));
           } while (true);

       } catch (Exception e) {
           // TODO: handle exception
           e.printStackTrace();
       }

   }

   /**
   * method to calculates the per person price (room cost plus lift tickets
   * cost), then returns the cost per person
   *
   * @param groupSize
   * @return
   */
   public static double splitCost(int groupSize) {

       double roomCostPerPerson = 0.00d;
       double roomCost = 120;
       if (groupSize > 4) {
           if (groupSize % 4 == 0)

               roomCost = roomCost * ((groupSize / 4));
           else
               roomCost = roomCost * ((groupSize / 4) + 1);

       }

       roomCostPerPerson = roomCost / (double) groupSize;

       if (groupSize <= 5) {

           roomCostPerPerson += 90.00d;
       } else if (groupSize >= 6 && groupSize <= 10) {

           roomCostPerPerson += 80.00d;
       } else
           roomCostPerPerson += 70.00d;

       return roomCostPerPerson;

   }
}

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

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