Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.89 KB | None | 0 0
  1. public class SeatDiscountSytstem { //Specifies seat discount class
  2.     static Scanner console = new Scanner(System.in); //Creates a new scanner to accept inputs into the system console
  3.  
  4.     public static void main(String[] args)  
  5.     throws FileNotFoundException{ //Command given to FileNotFoundException to give an error message
  6.        
  7.         String Seats = "Seats.txt"; // //Assigns string value Seats.txt for variable Seats
  8.         FileReader file = new FileReader (Seats); //Creates FileReader for Seats
  9.         Scanner read = new Scanner(file); //Uses Scanner to separate contents of file
  10.        
  11.         String question; //States question as string
  12.         double discountRate=20; // States this and the 5 below as double data types
  13.         double percentageDiscountRate;
  14.         double seatDiscount;
  15.         double income;
  16.         double absoluteDiscount = 0;
  17.         double absoluteIncome = 0;
  18.        
  19.         System.out.println("Would you like to specify custom discount rate?"); //Outputs following message to console
  20.         question = console.nextLine(); //Accepts user input
  21.         if (question.equals("Y")) { //If statement assuming User inputs value Y
  22.             System.out.println("What should the new discount rate be?"); //Output following user input as Y
  23.             discountRate = console.nextInt(); //Reassigns value discountRate depending on User input
  24.         }
  25.         else if(question.equals("N")) { //\if statement assuming input is N
  26.             System.out.println("Alright the discount rate is" + " " + discountRate + "%"); //Print formatter used to display discount rate
  27.         }
  28.         else //Otherwise
  29.         {
  30.              
  31.     }
  32.         percentageDiscountRate = discountRate / 100; //Formula for percentage discount rate
  33.         System.out.println(percentageDiscountRate); //Prints percentageDiscountRate to console
  34.         System.out.println("       **  Seat Discount System  **     "); //Prints following to console
  35.  
  36.         for (int i = 0; i < 4; i++) { //For loop stating up to value 4 (0 1 2 3)
  37.             String seatType = read.next(); // For loop outputs this and 2 below 4 times and cycles through them in file
  38.             double seatPrice = read.nextDouble();
  39.             int bookingNo = read.nextInt();
  40.            
  41.         seatDiscount = seatPrice - (percentageDiscountRate * seatPrice); //Formula for seatDiscount variable
  42.         income = (seatDiscount) * bookingNo; //Formula for income variable
  43.         System.out.printf("\t The seat type is %s, and the number of bookings is %d the seat discount is %.2f.\n\n", seatType, bookingNo, seatDiscount ); //String formatter to used to output values including seat discount to user
  44.         absoluteDiscount += seatDiscount ; //Used to find the sum of all seatDiscounts added together
  45.         absoluteIncome += income; //Used to fund total income generated
  46.         }
  47.        
  48.         System.out.printf("\t The total discount is %.2f \n", absoluteDiscount); //Formatter used to output value for absoluteDiscount
  49.         System.out.printf("\t The total income is %.2f \n", absoluteIncome); //Formatter used to output value for absoluteIncome
  50.        
  51.         read.close(); //Closes scanner file
  52.        
  53.  
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement