Help needed in this intro to java code Please do not use arr
Solution
// Charges.java calculate parking charges
// input: total number of customers, hours parked by each customer
// output: parking changes for each customer
import java.text.DecimalFormat;
import java.util.Scanner;
public class Charges
{
// method to determine charges for given hours
public static double calculateCharges (double hours)
{
double totalCost = 0.0;
if(hours <= 3)
totalCost = 2.00;
else if(hours > 3 && hours <= 19)
totalCost = 2.0 + 0.5*(hours - 3);
else if (hours > 19)
totalCost = 10;
return totalCost;
}
// main method
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
DecimalFormat formatter = new DecimalFormat(\"$##.00\");
double totalHours;
double totalCost;
int total;
// input total number of customers
System.out.print(\"Enter the number of customers: \");
total = scan.nextInt();
// determine cost for each customer
for(int count = 1; count <= total; count++)
{
System.out.print(\"\ Enter hours parked for customer \" + count + \": \");
totalHours = scan.nextDouble();
// determine total cost
totalCost = calculateCharges(totalHours);
System.out.println(\"Charge for customer \" + count + \": \" + formatter.format(totalCost) + \"\ \");
}
}
}
/*
output:
Enter the number of customers: 7
Enter hours parked for customer 1: 1
Charge for customer 1: $2.00
Enter hours parked for customer 2: 2
Charge for customer 2: $2.00
Enter hours parked for customer 3: 3
Charge for customer 3: $2.00
Enter hours parked for customer 4: 4
Charge for customer 4: $2.50
Enter hours parked for customer 5: 18
Charge for customer 5: $9.50
Enter hours parked for customer 6: 19
Charge for customer 6: $10.00
Enter hours parked for customer 7: 24
Charge for customer 7: $10.00
*/

