waltermilner

Untitled

Oct 27th, 2017
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package assignment3;
  7. import java.util.Scanner;
  8.  
  9. /**
  10.  * @serial 1924-4561-2045-3250
  11.  * @since 27/10/17
  12.  * @version 1.0
  13.  * @author Callum Cameron
  14.  */
  15. public class Assignment3 {
  16.  
  17.     /**
  18.      * @param args the command line arguments
  19.      */
  20.  
  21.     public static void main(String[] args) {
  22.         // Initialize 'runningcost' variable (double)
  23.         double runningcost = 0;
  24.         // Initialize 'runningcostfamily' variable (double)
  25.         double runningcostfamily = 0;
  26.         // Initialize 'runningcostadult' variable (double)
  27.         double runningcostadult = 0;
  28.         // Initialize 'runningcostchild' variable (double)
  29.         double runningcostchild = 0;
  30.         // Initialize 'runningcostsadult' variable (double)
  31.         double runningcostsadult = 0;
  32.         // Initialize 'runningcostschild' variable (double)
  33.         double runningcostschild = 0;
  34.         // Initialize 'loopcost' variable (double)
  35.         double loopcost = 0;
  36.                // Initialize 'unlimitedfamilycost' variable (double)
  37.         double unlimitedfamilycost = 139.95;
  38.         // Initialize 'unlimitedadultcost' variable (double)
  39.         double unlimitedadultcost = 39.95;
  40.         // Initialize 'unlimitedchildcost' variable (double)
  41.         double unlimitedchildcost = 29.95;
  42.         // Initialize 'singleadultcost' variable (double)
  43.         double singleadultcost = 9.95;
  44.         // Initialize 'singlechildcost' variable (double)
  45.         double singlechildcost = 8.95;
  46.         // Initialize 'totaldiscount' variable (double)
  47.         double totaldiscount = 0;
  48.         // Initialize 'subtotal' variable (double)
  49.         double subtotal = 0;
  50.         // Initialize 'finalsubtotal' variable (double
  51.         double finalsubtotal = 0;
  52.         // Initialize 'unlimitedfamily' variable (int)
  53.         int unlimitedfamily = 0;
  54.         // Initialize 'unlimitedadult' variable (int)
  55.         int unlimitedadult = 0;
  56.         // Initialize 'unlimitedchild' variable (int)
  57.         int unlimitedchild = 0;
  58.         // Initialize 'singleadult' variable (int)
  59.         int singleadult = 0;
  60.         // Initialize 'singlechild' variable (int)
  61.         int singlechild = 0;
  62.         // Initialize 'input' variable (int)
  63.         int input = 0;
  64.         // Initialize 'input2' variable (int)
  65.         int input2 = 0;
  66.         // Initialize 'input3' variable (int)
  67.         int input3 = 0;
  68.         // Initialize 'unlimitedfamilytally'
  69.         int unlimitedfamilytally = 0;
  70.         // Initialize 'unlimitedadulttally'
  71.         int unlimitedadulttally = 0;
  72.         // Initialize 'unlimitedchildtally'
  73.         int unlimitedchildtally = 0;
  74.         // Initialize 'singleadulttally'
  75.         int singleadulttally = 0;
  76.         // Initialize 'singlechildtally'
  77.         int singlechildtally = 0;
  78.         // Initialize 'singlechildtotal'
  79.         int singlechildtotal = 0;
  80.         // Initialize 'singleadulttotal'
  81.         int singleadulttotal = 0;
  82.         // Initialize 'unlimitedadulttotal'
  83.         int unlimitedadulttotal = 0;
  84.         // Initialize 'unlimitedfamilytotal'
  85.         int unlimitedfamilytotal = 0;
  86.         // Initialize 'unlimitedchildtotal'
  87.         int unlimitedchildtotal = 0;
  88.        
  89.        
  90.        
  91.          
  92.         // Commence do loop
  93.      
  94.         // Display welcome message
  95.         System.out.println("***DISCOUNTS AVAILABLE ON UNLIMITED TICKETS***");
  96.         System.out.println("PURCHASES OVER 15 TICKETS - 90 % OFF THE REGULAR PRICE!");  
  97.         System.out.println("PURCHASES OVER 40 TICKETS - 85 % OFF THE REGULAR PRICE!");
  98.         System.out.println("");
  99.         System.out.println("Welcome to ABC theme park's ticket purchasing program");
  100.         System.out.println("");
  101.         //*****Ticket menu*****
  102.         do{
  103.         // Prompt user for input
  104.         System.out.println("Please press 1 for a daily unlimited ride menu, please press 2 for the daily single ride menu.");
  105.         // Initialize scanner
  106.         Scanner scanner = new Scanner(System.in);
  107.         // Get input from user
  108.         input = scanner.nextInt();
  109.         // Commence while statement
  110.        if (input == 1){
  111.            // If user inputs '1' display unlimited ride ticket menu
  112.             System.out.println("➢ 1) 4 people family pass costs $139.95,\n" +
  113. "➢ 2) 13+ years or Adult costs $39.95,\n" +
  114. "➢ 3) 4 -12year old’s costs $29.95 and\n" +
  115. "➢ 1-3year olds are free. ");}
  116.        System.out.println("");
  117.        // If user inputs '2' display single ride ticket menu
  118.        if (input == 2){
  119.             System.out.println ("➢ 1) 13+ years or Adult costs $9.95,\n" +
  120. "➢ 2) 4-12year old’s costs $8.95 and\n" +
  121. "➢ 1-3year olds are free.");}
  122.      // If user inputs any other number display 'Invalid entry'
  123.        if (input > 2)
  124.            System.out.println ("You have made an invalid selection.");
  125.      // Prompt user to enter choice of concession for ticket             }
  126.        System.out.println ("Please enter the number corresponding to the ticket(s) you wish to purchase");
  127.      // Initialize next scanner
  128.        Scanner scanner2 = new Scanner(System.in);
  129.      // Send input to variable 'input 2'
  130.        input2 = scanner2.nextInt();
  131.    
  132. //*****Unlimited ride menu*****
  133.        
  134.        //Display confirmation of option and current total
  135.        if (input ==1 && input2 == 1){  
  136.            System.out.println ("");
  137.            System.out.println ("You have chosen the unlimited ride 4 person family pass. How many tickets would you like to purchase?");
  138.        // Initialize next scanner
  139.               Scanner sc = new Scanner(System.in);
  140.        // Receive integer as multiple numbers on the same line
  141.         int[] numbers = new int[1];
  142.         for(int i = 0; i < 1; ++i) {
  143.        // Receive next user input at variable unlimitedfamily  
  144.             unlimitedfamily = sc.nextInt();
  145.        // Set numbers integer (local) to be equal to unlimitedfamily integer
  146.             numbers[i] = unlimitedfamily;
  147.        // Calculate the total cost of the tickets
  148.             runningcostfamily = unlimitedfamilycost * numbers[i];}
  149.        // Print the total cost of the tickets on the sceen
  150.             System.out.println ("");
  151.             System.out.println ("The total cost of the unlimited family ticket(s) is $"+runningcostfamily);
  152.               finalsubtotal = runningcostfamily + finalsubtotal;
  153.               unlimitedfamilytally = unlimitedfamilytally + unlimitedfamily;}
  154.              
  155.        //Commence menu iteration based on user input1
  156.        if (input ==1 && input2 == 2){
  157.        //Display confirmation of option and current total
  158.            System.out.println ("");
  159.            System.out.println ("You have chosen the unlimited ride adult ticket(s) How many tickets would you like to purchase?");
  160.        // Initialize next scanner
  161.               Scanner sc = new Scanner(System.in);
  162.        // Receive integer as multiple numbers on the same line
  163.         int[] numbers = new int[1];
  164.         for(int i = 0; i < 1; ++i) {
  165.        // Receive next user input at variable unlimitedadult
  166.             unlimitedadult = sc.nextInt();
  167.        // Set numbers integer (local) to be equal to unlimitedadult integer
  168.             numbers[i] = unlimitedadult;
  169.        // Calculate the total cost of the tickets
  170.             runningcostadult = unlimitedadultcost * numbers[i];
  171.        // Print the total cost of the tickets on the sceen
  172.             System.out.println ("");
  173.             System.out.println ("The total cost of the unlimited adult ticket(s) is $"+runningcostadult);
  174.          finalsubtotal = runningcostadult + finalsubtotal;
  175.          unlimitedadulttally = unlimitedadulttally + unlimitedadult;}}
  176.        
  177.         //Commence menu iteration based on user input1
  178.        if (input ==1 && input2 == 2){
  179.        //Display confirmation of option and current total
  180.            System.out.println ("");
  181.            System.out.println ("You have chosen the unlimited ride adult ticket(s) How many tickets would you like to purchase?");
  182.        // Initialize next scanner
  183.               Scanner sc = new Scanner(System.in);
  184.        // Receive integer as multiple numbers on the same line
  185.         int[] numbers = new int[1];
  186.         for(int i = 0; i < 1; ++i) {
  187.        // Receive next user input at variable unlimitedadult
  188.             unlimitedchild = sc.nextInt();
  189.        // Set numbers integer (local) to be equal to unlimitedadult integer
  190.             numbers[i] = unlimitedchild;
  191.        // Calculate the total cost of the tickets
  192.             runningcostchild = unlimitedchildcost * numbers[i];
  193.        // Print the total cost of the tickets on the sceen
  194.             System.out.println ("");
  195.             System.out.println ("The total cost of the unlimited adult ticket(s) is $"+runningcostadult);
  196.                     ;
  197.          finalsubtotal = runningcostchild + finalsubtotal;
  198.          unlimitedchildtally = unlimitedchildtally + unlimitedchild;}}
  199.        
  200.       //*****Daily single ride menu*****
  201.      
  202. //Commence menu iteration based on user input
  203.        if (input ==2 && input2 ==1){  
  204.       //Display confirmation of option and current total
  205.            System.out.println ("");
  206.            System.out.println ("You have chosen the daily single ride adult ticket. How many tickets would you like to purchase?");
  207.       // Initialize next scanner
  208.               Scanner sc = new Scanner(System.in);
  209.       // Receive integer as multiple numbers on the same line
  210.         int[] numbers = new int[1];  
  211.         for(int i = 0; i < 1; ++i) {
  212.       // Receive next user input at variable singleadult
  213.             singleadult = sc.nextInt();
  214.       // Set numbers integer (local) to be equal to singleadult integer
  215.             numbers[i] = singleadult;
  216.       // Calculate the total cost of the tickets
  217.             runningcostsadult = singleadultcost * numbers[i];
  218.       // Print the total cost of the tickets on the sceen
  219.             System.out.println ("The total cost of the ticket(s) is $"+runningcostsadult);          
  220.         finalsubtotal = runningcostsadult + finalsubtotal;
  221.         singleadulttally = singleadulttally + singleadult;}
  222.        
  223.        
  224.        }
  225.       //Commence menu iteration based on user input
  226.            if (input ==2 && input2 ==2){
  227.       //Display confirmation of option and current total
  228.                System.out.println ("");
  229.                System.out.println ("You have chosen the daily single ride child ticket. How many tickets would you like to purchase?");
  230.       // Initialize next scanner
  231.               Scanner sc = new Scanner(System.in);
  232.       // Receive integer as multiple numbers on the same line
  233.         int[] numbers = new int[1];
  234.         for(int i = 0; i < 1; ++i) {
  235.       // Receive next user input at variable singlechild
  236.             singlechild = sc.nextInt();
  237.       // Set numbers integer (local) to be equal to singlechild integer
  238.             numbers[i] = singlechild;
  239.       // Calculate the total cost of the tickets
  240.             runningcostschild = singlechildcost * numbers[i];
  241.       // Print the total cost of the tickets on the sceen
  242.             System.out.println ("");
  243.             System.out.println ("The total cost of these ticket(s) is $"+runningcostschild);
  244.             finalsubtotal = runningcostschild+ finalsubtotal;}
  245.             singlechildtally = singlechildtally + singlechild;
  246.        }    
  247.            
  248.       //Display confirmation of option and current total
  249.            if (input2 > 3){
  250.            System.out.println ("");
  251.            
  252.            System.out.println ("Invalid entry");}
  253.            
  254.       //*****Final menu*****
  255.            
  256. // Prompt the user for input, if 1 return to main menu, if 0 stop and display total
  257. subtotal = runningcostchild + runningcostadult + runningcostfamily + runningcostschild + runningcostsadult;
  258.  
  259. loopcost = loopcost + finalsubtotal;
  260. System.out.println ("Your current sub total is $" +finalsubtotal);
  261. System.out.println ("");
  262. System.out.println ("Press 1 to return to the main menu or press 0 to stop purchasing tickets and display the total");
  263.        // Initialize next scanner
  264.         Scanner scanner4 = new Scanner(System.in);
  265.        // Send input to variable 'input 2'
  266.         input3 = scanner4.nextInt();    
  267.        // Define variables before loop repeats
  268.        
  269.        
  270.        // Returns the user to the ticket menu as long as the input is 1
  271.        
  272.        
  273.        
  274.        // Commence while loop
  275.         }while(input3 != 0);
  276.        
  277.        // Checks for invalid inputs
  278.         if (input3 >1){
  279.        // Displays an error message if an invalid input is entered
  280.         System.out.println ("You have made an invalid selection.");}
  281.        // Enter if loop to calculate cost for purchases over 15 tickets
  282.             if (unlimitedchildtally + unlimitedadulttally + unlimitedfamilytally > 15 && unlimitedchildtally + unlimitedadulttally + unlimitedfamilytally < 40) {                
  283.                    totaldiscount = finalsubtotal * 0.9;
  284.         System.out.println ("You are eligible for a 90% discount!");
  285.         System.out.println ("Your final total is $"+totaldiscount); }
  286.        // Enter if loop to calculate cost for purchases over 40 tickets  
  287.             if (unlimitedfamilytally + unlimitedchildtally + unlimitedadulttally > 40) {
  288.                    totaldiscount = finalsubtotal * 0.85;
  289.                    System.out.println ("You are eligible for an 85% discount!");
  290.                    System.out.println ("Your final total is $"+totaldiscount);}
  291.          
  292.        // End if loop and display raw cost if less than 15 tickets    
  293.           if (unlimitedfamilytally + unlimitedchildtally + unlimitedadulttally < 15){
  294.                     totaldiscount = finalsubtotal;
  295.                     System.out.println ("Your final total is $"+totaldiscount);}
  296.          
  297.                    
  298.                    
  299.        // Display total cost of tickets
  300.        
  301.        // Display thankyou message
  302.        
  303.    
  304.         {
  305.     }
  306. }
Add Comment
Please, Sign In to add comment