Question

In: Computer Science

Write a Java program in Eclipse to calculate the total cost to enter into a waterpark...

Write a Java program in Eclipse to calculate the total cost to enter into a waterpark for a family/group

Ticket rates are listed below

kids (Age 12 and under)=$ 12.50

Regular( Age between12 -55) =$ 18.25

Seniors (55 and above) = $15.00

Tax =7%

Your program should ask the user to enter the total number of members in their group.

User needs to enter the ages for all members. Write appropriate error messages for invalid entries.

An array should be used to store the ages of the family members.

Based on the age it has to calculate the cost of each member and calculate the total cost including tax.

Your program should display

The number of tickets for each type

And the total cost for the group

After display your program should repeat the process until the user wants to stop.

Your program must use

  1. Array
  2. Do while Loop
  3. Constant variable
  4. Atleast one method

Sample run of the program:

Welcome to our WATERPARK!!!

Please enter the number of members in your group.   7

Please enter the ages for each person in your group. 15 28 11 34 26 60 58

Please pay the total of $115.50 + 7% tax = $ 123.59

And pick up

1 Kid ticket

4 Regular tickets and

2 Senior tickets

Please Press a positive number for next customer, Negative number to end. 5

Welcome to our WATERPARK!!!

Please enter the number of members in your group.  

Solutions

Expert Solution

package login;

import java.util.Scanner;
import java.io.*;
import java.text.DecimalFormat;

public class Login {

    //method to calculate total cost
    static double calculate_totalcost(double num) {
        
        //calculates 7%tax on amount
        double tax = (num * 7) / 100;
        
        //return total cost
        return (num + tax);

    }

    public static void main(String[] args) {
        
        //initialize variable
        double cost = 0.0;
        double total_cost = 0.0;
        double tax = 0.0;
        int kid_tickets = 0;
        int reglar_tickets = 0;
        int senior_tickets = 0;
        
        //this is used to format the number upto two decimal place after point
        DecimalFormat df = new DecimalFormat("#.##");
        Scanner sc = new Scanner(System.in);
        do {
            System.out.println("Welcome to our WATERPARK!!!");
            System.out.println("Please enter the number of members in your group");
            int num = sc.nextInt();
            
            //initialize array ages 
            int[] ages = new int[num];
            System.out.println("Please enter the ages for each person in your group");
            
            //takes ages enterd by user
            for (int i = 0; i < num; i++) {
                ages[i] = sc.nextInt();
            }

            for (int i = 0; i < num; i++) {
                               
                //kid_tickets is used to count no of kids in the group. 
                /* checks if age is less than 12 then apply tickets rates of kids
                and increment kid_tickets count */
                if (ages[i] <= 12) {
                    cost = cost + 12.50;
                    kid_tickets += 1;
                }
                
                //reglar_tickets is used to count no of person having age between 12 to 55 in the group. 
                /* checks if age is between 12 to 55 then apply tickets rates of regular
                and increment reglar_tickets count */
                if (ages[i] > 12 && ages[i] < 55) {
                    cost = cost + 18.25;
                    reglar_tickets += 1;
                }
                
                //senior_tickets is used to count no of seniors in the group. 
                /* checks if age is greater than 55 then apply tickets rates of senior
                and increment senior_tickets count */
                if (ages[i] > 55) {
                    cost = cost + 15.00;
                    senior_tickets += 1;
                }
            }
            
            //calculate total cost by calling calculate_totalcost method
            total_cost = calculate_totalcost(cost);
            System.out.println("Please pay the total of $" + cost + " + 7% tax = $" + df.format(total_cost));
            System.out.println("And pick up");
            
            //if no of kid in the group is greater than 1 then prints the statement inside if loop
            //otherwise prints the statement inside else loop
            if (kid_tickets > 1) {
                System.out.println(kid_tickets + " Kid tickets");
            } else {
                System.out.println(kid_tickets + " Kid ticket");
            }

            //if no of persons having age between 12 to 55 in the group is greater than 1 then prints the statement inside if loop
            //otherwise prints the statement inside else loop
            if (reglar_tickets > 1) {
                System.out.println(reglar_tickets + " Regular tickets");
            } else {
                System.out.println(reglar_tickets + " Regular ticket");
            }

             //if no of seniors in the group is greater than 1 then prints the statement inside if loop
            //otherwise prints the statement inside else loop
            if (senior_tickets > 1) {
                System.out.println(senior_tickets + " Senior tickets");
            } else {
                System.out.println(senior_tickets + " Senior ticket");
            }

            System.out.print("Please enter positive number for next customer ,Negative number to end. ");
        } 
        //while user enters positive integer program runs continuously
        while (sc.nextInt() > 0);

    }
}

Output:


Related Solutions

write on eclipse java Write a program named lab5 that will play a game of Blackjack...
write on eclipse java Write a program named lab5 that will play a game of Blackjack between the user and the computer. Create a second class named Card with the following: Define the following private instance variables: cardValue (int) & cardSuite (String) Write a constructor with no parameters that will Set cardValue to a random number between 1 and 13 Generate a second random number between 0 and 3 and assign cardSuite a string based on its value (0 –...
1. Write a Java program that prompts the user to enter three integer numbers. Calculate and...
1. Write a Java program that prompts the user to enter three integer numbers. Calculate and print the average of the numbers. 2. Write a Java program that uses a for loop to print the odd numbers from 1 to 20. Print one number per line in the command line window. 3. Write a program which asks the user to input the size of potatoe fries she would like to purchase, and based on the size, it will tell her...
In java Write a program called FileProcessor.java that reads the file numbers.txt, and: Calculate the total...
In java Write a program called FileProcessor.java that reads the file numbers.txt, and: Calculate the total number of numbers in the file, Calculate the sum of all the numbers in the file, Calculate the average of all the numbers in the file, Find the smallest value of all the numbers in the file, Find the largest value of all the numbers in the file, Calculate the standard deviation of all the numbers in the file
I need to write a java program (in eclipse) that will read my text file and...
I need to write a java program (in eclipse) that will read my text file and replace specific placeholders with information provided in a second text file. For this assignment I am given a text file and I must replace <N>, <A>, <G>, with the information in the second file. For example the information can be John 22 male, and the template will then be modified and saved into a new file or files (because there will be multiple entries...
Using Java preferably with Eclipse Task: Write a program that creates a class Apple and a...
Using Java preferably with Eclipse Task: Write a program that creates a class Apple and a tester to make sure the Apple class is crisp and delicious. Instructions: First create a class called Apple The class Apple DOES NOT HAVE a main method Some of the attributes of Apple are Type: A string that describes the apple.  It may only be of the following types:  Red Delicious  Golden Delicious  Gala  Granny Smith Weight: A decimal value representing...
Write a Java Program to determine if a candidate qualifies for a FHA Mortgage. (using eclipse...
Write a Java Program to determine if a candidate qualifies for a FHA Mortgage. (using eclipse IDE) The qualifications given are: Residence: The home must be your primary residence. Down payment: They must have a credit score of at least 563. The Java Program needs to do the following. This can all be done in the main() method. Create a boolean variable to store the Residence requirement. Prompt the user to "Enter 1 if the Home will be the primary...
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A....
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A. Two bags per person are free. B. The Excess Bag Charge is $75 per bag. The program needs to do the following: 1. In your main method(),    Create integers to store the number of Passengers and also the total number of bags    Prompt for the number of passengers on a ticket.    Prompt for the total number of bags for all passengers...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
Write a java program that does the following: a) The user will enter data such as...
Write a java program that does the following: a) The user will enter data such as client name and client balance. The user can stop inputting data by entering "stop". The program should store the user inputs as a data member of an array. The type of this array is a class named ClientData. Below the output should be displayed by the program. The parts in bold are inputs from the user and not hard coded in the program Client...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT