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...
Write a program that uses input to prompt a user for their name and then welcomes...
Write a program that uses input to prompt a user for their name and then welcomes them. Note that input will pop up a dialog box. Enter Sarah in the pop-up box when you are prompted so your output will match the desired output.(In Python)
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write by hand a full java program that will prompt the user for the length and...
Write by hand a full java program that will prompt the user for the length and width of a square, calculate and display the area of that square rounded to the nearest tenth with an appropriate message.
Write a java program. The program requirements are: the program will let the user input a...
Write a java program. The program requirements are: the program will let the user input a starting number, such as 2.  It will generate ten multiplication problems ranging from 2x1 to 2x10.  For each problem, the user will be prompted to enter the correct answer. The program should check the answer and should not let the user advance to the next question until the correct answer is given to the question being asked currently. After testing a total of 10 multiplication problems,...
Write a program that will input the information for 2 different employees. Prompt the user for...
Write a program that will input the information for 2 different employees. Prompt the user for the first employee’s name, hours worked and rate. Compute the salary and display it. Do the same for the second and third employees. Then, display a message to the effect that the highest salary is whatever and the lowest salary is whatever. When the program runs, the following should display information should line up just as I have it below. E:\> java Quiz4 Name:...
Answer in JAVA Write a program that would prompt the user to enter an integer. The...
Answer in JAVA Write a program that would prompt the user to enter an integer. The program then would displays a table of squares and cubes from 1 to the value entered by the user. The program should prompt the user to continue if they wish. Name your class NumberPowers.java, add header and sample output as block comments and uploaded it to this link. Use these formulas for calculating squares and cubes are: square = x * x cube =...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code. Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT