Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- /**
- * Write a description of class Question2 here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class Question2
- {
- public static void main(String[] args)
- {
- double hour = 0, totalCharge = 0, charge;
- int i = 1, carNum = 0;
- String carPlate = "";
- Scanner scan = new Scanner(System.in); //scan numbers
- Scanner scanLn = new Scanner (System.in); //scan String
- while(i > 0)
- {
- System.out.print("\nWant to calculate total charge of parking? [Yes(1)/No(0)]: ");
- i = scan.nextInt();
- if(i == 0)
- {
- break;
- }
- else
- {
- carNum++;
- System.out.print("\nEnter the plate of Car " + carNum + ": ");
- carPlate = scanLn.nextLine();
- System.out.print("Enter the parking hour: ");
- hour = scan.nextDouble();
- if(hour <= 2)
- {
- charge = 1.0;
- System.out.println("Charge for " + carPlate + ": RM" + charge);
- totalCharge += charge;
- }
- else if(hour > 2 && hour <= 12)
- {
- charge = 1.0 + (0.6*(hour-2.0));
- System.out.println("Charge for " + carPlate + ": RM" + charge);
- totalCharge += charge;
- }
- else if(hour > 12 || hour >= 24)
- {
- charge = 6.0;
- System.out.println("Charge for " + carPlate + ": RM" + charge);
- totalCharge += charge;
- }
- }
- }
- System.out.println("\n_____________________________________\nTotal number of cars parked today: " + carNum
- + "\nTotal collection today: RM" + totalCharge);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement