Question

In: Computer Science

Write a Java program named, TicketSale, (TicketSale.java) with the following tasks: Prompt user to input the...

Write a Java program named, TicketSale, (TicketSale.java) with the following tasks:

  • Prompt user to input the number of Adult tickets to purchase
  • Prompt user to input the number of Children tickets to purchase
  • Prompt user to input the number of Senior tickets to purchase
  • Write a method named, ticketCost(), which will be invoked by main() with statement similar to:
    • cost = ticketCost( adults, children, senior );
  • Ticket costs structure:
    • $15.00 for each adult
    • $10.00 for each child
    • $5.00 for each senior
    • Each adult ticket can purchase one child ticket for $5.00
    • If there is at least one adult ticket, all senior tickets can be purchased at $2.00
  • Must use System.out.printf() for all output functions
  • Sample output:
Please enter number of adults:1
Please enter number of kids:1
Please enter number of seniors:5
Your total cost for 1 adults, 1 children, and 5 seniors is: $30.00
  • Sample output:
Please enter number of adults:0
Please enter number of kids:2
Please enter number of seniors:10
Your total cost for 0 adults, 2 children, and 10 seniors is: $70.00

Solutions

Expert Solution

Source Code:

Output:

Code in text format (See above images of code for indentation):

import java.util.*;

/*class definition*/

public class TicketSale

{

    /*main method*/

    public static void main(String[] args)

    {

        /*Scanner object to read input from the user*/

        Scanner read=new Scanner(System.in);

        /*variables*/

        int adults,children,senior;

        float cost;

        /*read number of adults from the user*/

        System.out.printf("Enter number of adults: ");

        adults=read.nextInt();

        /*read children from the user*/

        System.out.printf("Enter number of kids: ");

        children=read.nextInt();

        /*read number of seniors from the user*/

        System.out.printf("Enter number of seniors: ");

        senior=read.nextInt();

        /*method call*/

        cost=ticketCost(adults,children,senior);

        /*print cost*/

        System.out.printf("Your total cost for %d adults, %d children, and %d seniors is: $%.2f",adults,children,senior,cost);

    }

    /*method definition*/

    public static int ticketCost(int adults,int children,int senior)

    {

        /*variables*/

        int cost=0,ch;

        /*cost for adults*/

        cost+=adults*15.00;

        /*check for atleast one adult*/

        if(adults>0)

        {

            /*cost for per senior is 2*/

            cost+=senior*2.00;

            /*calculate cost for kids*/

            if(adults>=children)

                cost+=children*5.00;

            else

            {

                /*each adult buy one children ticket for 5*/

                cost+=adults*5.00;

                ch=children-adults;

                /*remaning children tickets cost is 10*/

                cost+=ch*10.00;

            }

        }

        /*if no adults calculate cost with below prices for seniors and children*/

        else

        {

            cost+=senior*5.00;

            cost+=children*10.00;

        }  

        /*return total cost*/

        return cost;

    }

}




Related Solutions

Write a Java program named, MultiTable, (MultiTable.java), with the following tasks: Prompt user to input the...
Write a Java program named, MultiTable, (MultiTable.java), with the following tasks: Prompt user to input the maximum number (as integer) Store a multiplication table for all combinations (with some specific eliminations) of value 0 through the maximum number (being entered) into a 2-D array Write a method named printTable to print out the MulitTable, with the following header, public static void printTable(int[][] multitable) In printTable(), when the value of the MultiTable is an odd number, print out Z Must use...
Using Java, write a program named MyAngles that will prompt the user for the measure of...
Using Java, write a program named MyAngles that will prompt the user for the measure of the three sides of a triangle and then reports the measurement of each interior angle of the triangle and the area of the triangle.
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
JAVA Write a java program that will sum all positive number. Prompt the user to enter...
JAVA Write a java program that will sum all positive number. Prompt the user to enter numbers and add all positive numbers. The program will not add negative numbers and the program will stop when you enter ‘0’.   Enter a number> 25 Enter a number> 9 Enter a number> 5 Enter a number> -3 Enter a number> 0 Sum = 39
Write a complete Java program that does the following: Open an input file named data.txt that...
Write a complete Java program that does the following: Open an input file named data.txt that consists of a series of unknown number of integers. If data.txt does not exist, give an appropriate error message and terminate the program. Define a constant MAX of value 100 and create an array of size MAX to hold items from the input file. Make sure your program will not generate ArrayIndexOutOfBounds exception. Open an output file named result.txt and write the array elements...
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
Write a simple JAVA program to understand natural language. The user will enter the input following...
Write a simple JAVA program to understand natural language. The user will enter the input following the format: Name came to City, Country in Year. For example: Chris came to Bangkok, Thailand in 2009. The user will follow the exactly the same formats for the inputs. Your program should be able to analyze the key words (Name, City, Country and Year) from the inputs and reorganize the outputs following format: Name stay in City for X year(s). City is in...
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT