Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. import java.util.*;
  2. /**
  3. * Write a description of class Question2 here.
  4. *
  5. * @author (your name)
  6. * @version (a version number or a date)
  7. */
  8. public class Question2
  9. {
  10. public static void main(String[] args)
  11. {
  12. double hour = 0, totalCharge = 0, charge;
  13. int i = 1, carNum = 0;
  14. String carPlate = "";
  15.  
  16. Scanner scan = new Scanner(System.in); //scan numbers
  17. Scanner scanLn = new Scanner (System.in); //scan String
  18.  
  19. while(i > 0)
  20. {
  21. System.out.print("\nWant to calculate total charge of parking? [Yes(1)/No(0)]: ");
  22. i = scan.nextInt();
  23. if(i == 0)
  24. {
  25. break;
  26. }
  27.  
  28. else
  29. {
  30. carNum++;
  31. System.out.print("\nEnter the plate of Car " + carNum + ": ");
  32. carPlate = scanLn.nextLine();
  33. System.out.print("Enter the parking hour: ");
  34. hour = scan.nextDouble();
  35.  
  36. if(hour <= 2)
  37. {
  38. charge = 1.0;
  39. System.out.println("Charge for " + carPlate + ": RM" + charge);
  40. totalCharge += charge;
  41. }
  42.  
  43. else if(hour > 2 && hour <= 12)
  44. {
  45. charge = 1.0 + (0.6*(hour-2.0));
  46. System.out.println("Charge for " + carPlate + ": RM" + charge);
  47. totalCharge += charge;
  48. }
  49.  
  50. else if(hour > 12 || hour >= 24)
  51. {
  52. charge = 6.0;
  53. System.out.println("Charge for " + carPlate + ": RM" + charge);
  54. totalCharge += charge;
  55. }
  56. }
  57. }
  58.  
  59. System.out.println("\n_____________________________________\nTotal number of cars parked today: " + carNum
  60. + "\nTotal collection today: RM" + totalCharge);
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement