Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SeatDiscountSytstem { //Specifies seat discount class
- static Scanner console = new Scanner(System.in); //Creates a new scanner to accept inputs into the system console
- public static void main(String[] args)
- throws FileNotFoundException{ //Command given to FileNotFoundException to give an error message
- String Seats = "Seats.txt"; // //Assigns string value Seats.txt for variable Seats
- FileReader file = new FileReader (Seats); //Creates FileReader for Seats
- Scanner read = new Scanner(file); //Uses Scanner to separate contents of file
- String question; //States question as string
- double discountRate=20; // States this and the 5 below as double data types
- double percentageDiscountRate;
- double seatDiscount;
- double income;
- double absoluteDiscount = 0;
- double absoluteIncome = 0;
- System.out.println("Would you like to specify custom discount rate?"); //Outputs following message to console
- question = console.nextLine(); //Accepts user input
- if (question.equals("Y")) { //If statement assuming User inputs value Y
- System.out.println("What should the new discount rate be?"); //Output following user input as Y
- discountRate = console.nextInt(); //Reassigns value discountRate depending on User input
- }
- else if(question.equals("N")) { //\if statement assuming input is N
- System.out.println("Alright the discount rate is" + " " + discountRate + "%"); //Print formatter used to display discount rate
- }
- else //Otherwise
- {
- }
- percentageDiscountRate = discountRate / 100; //Formula for percentage discount rate
- System.out.println(percentageDiscountRate); //Prints percentageDiscountRate to console
- System.out.println(" ** Seat Discount System ** "); //Prints following to console
- for (int i = 0; i < 4; i++) { //For loop stating up to value 4 (0 1 2 3)
- String seatType = read.next(); // For loop outputs this and 2 below 4 times and cycles through them in file
- double seatPrice = read.nextDouble();
- int bookingNo = read.nextInt();
- seatDiscount = seatPrice - (percentageDiscountRate * seatPrice); //Formula for seatDiscount variable
- income = (seatDiscount) * bookingNo; //Formula for income variable
- 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
- absoluteDiscount += seatDiscount ; //Used to find the sum of all seatDiscounts added together
- absoluteIncome += income; //Used to fund total income generated
- }
- System.out.printf("\t The total discount is %.2f \n", absoluteDiscount); //Formatter used to output value for absoluteDiscount
- System.out.printf("\t The total income is %.2f \n", absoluteIncome); //Formatter used to output value for absoluteIncome
- read.close(); //Closes scanner file
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement