Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package assignment3;
- import java.util.Scanner;
- /**
- * @serial 1924-4561-2045-3250
- * @since 27/10/17
- * @version 1.0
- * @author Callum Cameron
- */
- public class Assignment3 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // Initialize 'runningcost' variable (double)
- double runningcost = 0;
- // Initialize 'runningcostfamily' variable (double)
- double runningcostfamily = 0;
- // Initialize 'runningcostadult' variable (double)
- double runningcostadult = 0;
- // Initialize 'runningcostchild' variable (double)
- double runningcostchild = 0;
- // Initialize 'runningcostsadult' variable (double)
- double runningcostsadult = 0;
- // Initialize 'runningcostschild' variable (double)
- double runningcostschild = 0;
- // Initialize 'loopcost' variable (double)
- double loopcost = 0;
- // Initialize 'unlimitedfamilycost' variable (double)
- double unlimitedfamilycost = 139.95;
- // Initialize 'unlimitedadultcost' variable (double)
- double unlimitedadultcost = 39.95;
- // Initialize 'unlimitedchildcost' variable (double)
- double unlimitedchildcost = 29.95;
- // Initialize 'singleadultcost' variable (double)
- double singleadultcost = 9.95;
- // Initialize 'singlechildcost' variable (double)
- double singlechildcost = 8.95;
- // Initialize 'totaldiscount' variable (double)
- double totaldiscount = 0;
- // Initialize 'subtotal' variable (double)
- double subtotal = 0;
- // Initialize 'finalsubtotal' variable (double
- double finalsubtotal = 0;
- // Initialize 'unlimitedfamily' variable (int)
- int unlimitedfamily = 0;
- // Initialize 'unlimitedadult' variable (int)
- int unlimitedadult = 0;
- // Initialize 'unlimitedchild' variable (int)
- int unlimitedchild = 0;
- // Initialize 'singleadult' variable (int)
- int singleadult = 0;
- // Initialize 'singlechild' variable (int)
- int singlechild = 0;
- // Initialize 'input' variable (int)
- int input = 0;
- // Initialize 'input2' variable (int)
- int input2 = 0;
- // Initialize 'input3' variable (int)
- int input3 = 0;
- // Initialize 'unlimitedfamilytally'
- int unlimitedfamilytally = 0;
- // Initialize 'unlimitedadulttally'
- int unlimitedadulttally = 0;
- // Initialize 'unlimitedchildtally'
- int unlimitedchildtally = 0;
- // Initialize 'singleadulttally'
- int singleadulttally = 0;
- // Initialize 'singlechildtally'
- int singlechildtally = 0;
- // Initialize 'singlechildtotal'
- int singlechildtotal = 0;
- // Initialize 'singleadulttotal'
- int singleadulttotal = 0;
- // Initialize 'unlimitedadulttotal'
- int unlimitedadulttotal = 0;
- // Initialize 'unlimitedfamilytotal'
- int unlimitedfamilytotal = 0;
- // Initialize 'unlimitedchildtotal'
- int unlimitedchildtotal = 0;
- // Commence do loop
- // Display welcome message
- System.out.println("***DISCOUNTS AVAILABLE ON UNLIMITED TICKETS***");
- System.out.println("PURCHASES OVER 15 TICKETS - 90 % OFF THE REGULAR PRICE!");
- System.out.println("PURCHASES OVER 40 TICKETS - 85 % OFF THE REGULAR PRICE!");
- System.out.println("");
- System.out.println("Welcome to ABC theme park's ticket purchasing program");
- System.out.println("");
- //*****Ticket menu*****
- do{
- // Prompt user for input
- System.out.println("Please press 1 for a daily unlimited ride menu, please press 2 for the daily single ride menu.");
- // Initialize scanner
- Scanner scanner = new Scanner(System.in);
- // Get input from user
- input = scanner.nextInt();
- // Commence while statement
- if (input == 1){
- // If user inputs '1' display unlimited ride ticket menu
- System.out.println("➢ 1) 4 people family pass costs $139.95,\n" +
- "➢ 2) 13+ years or Adult costs $39.95,\n" +
- "➢ 3) 4 -12year old’s costs $29.95 and\n" +
- "➢ 1-3year olds are free. ");}
- System.out.println("");
- // If user inputs '2' display single ride ticket menu
- if (input == 2){
- System.out.println ("➢ 1) 13+ years or Adult costs $9.95,\n" +
- "➢ 2) 4-12year old’s costs $8.95 and\n" +
- "➢ 1-3year olds are free.");}
- // If user inputs any other number display 'Invalid entry'
- if (input > 2)
- System.out.println ("You have made an invalid selection.");
- // Prompt user to enter choice of concession for ticket }
- System.out.println ("Please enter the number corresponding to the ticket(s) you wish to purchase");
- // Initialize next scanner
- Scanner scanner2 = new Scanner(System.in);
- // Send input to variable 'input 2'
- input2 = scanner2.nextInt();
- //*****Unlimited ride menu*****
- //Display confirmation of option and current total
- if (input ==1 && input2 == 1){
- System.out.println ("");
- System.out.println ("You have chosen the unlimited ride 4 person family pass. How many tickets would you like to purchase?");
- // Initialize next scanner
- Scanner sc = new Scanner(System.in);
- // Receive integer as multiple numbers on the same line
- int[] numbers = new int[1];
- for(int i = 0; i < 1; ++i) {
- // Receive next user input at variable unlimitedfamily
- unlimitedfamily = sc.nextInt();
- // Set numbers integer (local) to be equal to unlimitedfamily integer
- numbers[i] = unlimitedfamily;
- // Calculate the total cost of the tickets
- runningcostfamily = unlimitedfamilycost * numbers[i];}
- // Print the total cost of the tickets on the sceen
- System.out.println ("");
- System.out.println ("The total cost of the unlimited family ticket(s) is $"+runningcostfamily);
- finalsubtotal = runningcostfamily + finalsubtotal;
- unlimitedfamilytally = unlimitedfamilytally + unlimitedfamily;}
- //Commence menu iteration based on user input1
- if (input ==1 && input2 == 2){
- //Display confirmation of option and current total
- System.out.println ("");
- System.out.println ("You have chosen the unlimited ride adult ticket(s) How many tickets would you like to purchase?");
- // Initialize next scanner
- Scanner sc = new Scanner(System.in);
- // Receive integer as multiple numbers on the same line
- int[] numbers = new int[1];
- for(int i = 0; i < 1; ++i) {
- // Receive next user input at variable unlimitedadult
- unlimitedadult = sc.nextInt();
- // Set numbers integer (local) to be equal to unlimitedadult integer
- numbers[i] = unlimitedadult;
- // Calculate the total cost of the tickets
- runningcostadult = unlimitedadultcost * numbers[i];
- // Print the total cost of the tickets on the sceen
- System.out.println ("");
- System.out.println ("The total cost of the unlimited adult ticket(s) is $"+runningcostadult);
- finalsubtotal = runningcostadult + finalsubtotal;
- unlimitedadulttally = unlimitedadulttally + unlimitedadult;}}
- //Commence menu iteration based on user input1
- if (input ==1 && input2 == 2){
- //Display confirmation of option and current total
- System.out.println ("");
- System.out.println ("You have chosen the unlimited ride adult ticket(s) How many tickets would you like to purchase?");
- // Initialize next scanner
- Scanner sc = new Scanner(System.in);
- // Receive integer as multiple numbers on the same line
- int[] numbers = new int[1];
- for(int i = 0; i < 1; ++i) {
- // Receive next user input at variable unlimitedadult
- unlimitedchild = sc.nextInt();
- // Set numbers integer (local) to be equal to unlimitedadult integer
- numbers[i] = unlimitedchild;
- // Calculate the total cost of the tickets
- runningcostchild = unlimitedchildcost * numbers[i];
- // Print the total cost of the tickets on the sceen
- System.out.println ("");
- System.out.println ("The total cost of the unlimited adult ticket(s) is $"+runningcostadult);
- ;
- finalsubtotal = runningcostchild + finalsubtotal;
- unlimitedchildtally = unlimitedchildtally + unlimitedchild;}}
- //*****Daily single ride menu*****
- //Commence menu iteration based on user input
- if (input ==2 && input2 ==1){
- //Display confirmation of option and current total
- System.out.println ("");
- System.out.println ("You have chosen the daily single ride adult ticket. How many tickets would you like to purchase?");
- // Initialize next scanner
- Scanner sc = new Scanner(System.in);
- // Receive integer as multiple numbers on the same line
- int[] numbers = new int[1];
- for(int i = 0; i < 1; ++i) {
- // Receive next user input at variable singleadult
- singleadult = sc.nextInt();
- // Set numbers integer (local) to be equal to singleadult integer
- numbers[i] = singleadult;
- // Calculate the total cost of the tickets
- runningcostsadult = singleadultcost * numbers[i];
- // Print the total cost of the tickets on the sceen
- System.out.println ("The total cost of the ticket(s) is $"+runningcostsadult);
- finalsubtotal = runningcostsadult + finalsubtotal;
- singleadulttally = singleadulttally + singleadult;}
- }
- //Commence menu iteration based on user input
- if (input ==2 && input2 ==2){
- //Display confirmation of option and current total
- System.out.println ("");
- System.out.println ("You have chosen the daily single ride child ticket. How many tickets would you like to purchase?");
- // Initialize next scanner
- Scanner sc = new Scanner(System.in);
- // Receive integer as multiple numbers on the same line
- int[] numbers = new int[1];
- for(int i = 0; i < 1; ++i) {
- // Receive next user input at variable singlechild
- singlechild = sc.nextInt();
- // Set numbers integer (local) to be equal to singlechild integer
- numbers[i] = singlechild;
- // Calculate the total cost of the tickets
- runningcostschild = singlechildcost * numbers[i];
- // Print the total cost of the tickets on the sceen
- System.out.println ("");
- System.out.println ("The total cost of these ticket(s) is $"+runningcostschild);
- finalsubtotal = runningcostschild+ finalsubtotal;}
- singlechildtally = singlechildtally + singlechild;
- }
- //Display confirmation of option and current total
- if (input2 > 3){
- System.out.println ("");
- System.out.println ("Invalid entry");}
- //*****Final menu*****
- // Prompt the user for input, if 1 return to main menu, if 0 stop and display total
- subtotal = runningcostchild + runningcostadult + runningcostfamily + runningcostschild + runningcostsadult;
- loopcost = loopcost + finalsubtotal;
- System.out.println ("Your current sub total is $" +finalsubtotal);
- System.out.println ("");
- System.out.println ("Press 1 to return to the main menu or press 0 to stop purchasing tickets and display the total");
- // Initialize next scanner
- Scanner scanner4 = new Scanner(System.in);
- // Send input to variable 'input 2'
- input3 = scanner4.nextInt();
- // Define variables before loop repeats
- // Returns the user to the ticket menu as long as the input is 1
- // Commence while loop
- }while(input3 != 0);
- // Checks for invalid inputs
- if (input3 >1){
- // Displays an error message if an invalid input is entered
- System.out.println ("You have made an invalid selection.");}
- // Enter if loop to calculate cost for purchases over 15 tickets
- if (unlimitedchildtally + unlimitedadulttally + unlimitedfamilytally > 15 && unlimitedchildtally + unlimitedadulttally + unlimitedfamilytally < 40) {
- totaldiscount = finalsubtotal * 0.9;
- System.out.println ("You are eligible for a 90% discount!");
- System.out.println ("Your final total is $"+totaldiscount); }
- // Enter if loop to calculate cost for purchases over 40 tickets
- if (unlimitedfamilytally + unlimitedchildtally + unlimitedadulttally > 40) {
- totaldiscount = finalsubtotal * 0.85;
- System.out.println ("You are eligible for an 85% discount!");
- System.out.println ("Your final total is $"+totaldiscount);}
- // End if loop and display raw cost if less than 15 tickets
- if (unlimitedfamilytally + unlimitedchildtally + unlimitedadulttally < 15){
- totaldiscount = finalsubtotal;
- System.out.println ("Your final total is $"+totaldiscount);}
- // Display total cost of tickets
- // Display thankyou message
- {
- }
- }
Add Comment
Please, Sign In to add comment