Advertisement
binibiningtinamoran

PracticeAssignment2A

Oct 30th, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.37 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PracticeAssignment2A {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner inp = new Scanner(System.in);
  7.  
  8.         System.out.println("LTC Bus Fare Calculator");
  9.         System.out.println("-------------------------------\n");
  10.  
  11.         final double adultPrice = 1.90;
  12.         final double studentPrice = 1.54;
  13.         final double seniorPrice = 1.43;
  14.         final double childPrice = 1.10;
  15.  
  16.         int student = 0;
  17.         int senior = 0;
  18.         int adult = 0;
  19.         int child = 0;
  20.  
  21.         double totalPrice = 0;
  22.  
  23.  
  24.         System.out.print("How many riders are in your group? ");
  25.         int riderCount = inp.nextInt();
  26.         while (riderCount < 0) {
  27.             System.out.println("Invalid count of riders.");
  28.             System.out.print("How many riders are in your group? ");
  29.             riderCount = inp.nextInt();
  30.         }
  31.  
  32.         for (int i = 0; i < riderCount; i++) {
  33.             System.out.println("Enter the rider Input for rider " + i + " (A, S, R, C)");
  34.             char riderInput = inp.next().toUpperCase().charAt(0);
  35.  
  36.             switch (riderInput) {
  37.                 case 'A': {
  38.                     System.out.println("Adult. Ticket price is $" + adultPrice);
  39.                     adult++;
  40.                     totalPrice += adultPrice;
  41.                     break;
  42.                 }
  43.                 case 'S': {
  44.                     System.out.println("Student. Ticket price is $" + studentPrice);
  45.                     student++;
  46.                     totalPrice += studentPrice;
  47.                     break;
  48.                 }
  49.                 case 'R': {
  50.                     System.out.println("Senior. Ticket price is $" + seniorPrice);
  51.                     senior++;
  52.                     totalPrice += seniorPrice;
  53.                     break;
  54.                 }
  55.                 default: {
  56.                     System.out.println("Child. Ticket price is $" + childPrice);
  57.                     child++;
  58.                     totalPrice += childPrice;
  59.                     break;
  60.                 }
  61.             } // end switch
  62.         } // end for
  63.         System.out.printf("Your group consists of %,d adult(s), %,d student(s), %,d senior(s) " +
  64.                 "and %,d child(ren).\n", adult, student, senior, child);
  65.         System.out.println("The total bus fare for you group is $" + totalPrice);
  66.     }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement