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

Program: Java (using eclipse) Write a program that asks the user to enter today’s sales for...
Program: Java (using eclipse) Write a program that asks the user to enter today’s sales for five stores. The program should then display a bar chart comparing each store’s sales. Create each bar in the bar chart by displaying a row or asterisks. Each asterisk should represent $100 of sales. You must use a loop to print the bar chart!!!! If the user enters a negative value for the sales amount, the program will keep asking the user to enter...
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 –...
Write a JAVA program in eclipse (write comment in every line) that asks the user to...
Write a JAVA program in eclipse (write comment in every line) that asks the user to enter two numbers and an operator (+, -, *, / or %), obtain them from the user and prints their sum, product, difference, quotient or remainder depending on the operator. You need to use OOP techniques (objects, classes, methods….). This program must be place in a loop that runs 3 times.
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...
for eclipse java Overview Write a program that translates an English phrase into a Pig Latin...
for eclipse java Overview Write a program that translates an English phrase into a Pig Latin phrase. Input a phrase from the user and translate it to pig latin. You can assume the phrase will be on a single line. Use at least the REQUIRED METHODS listed below, with the exact same SPELLING for method names and parameters. Input Specification The input will be an English phrase, with NO terminal punctuation. Read the phrase as a SINGLE STRING using the...
Write in JAVA eclipse program (comment in every line): class for calculating an area of a...
Write in JAVA eclipse program (comment in every line): class for calculating an area of a room. The program MUST ask for the length and the width of the room. Make sure you write the methods to get the width and length and print the area.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT