Question: In java please 1 . Use your own methods. 2 . Minimize the main ( ) as much as possible. ` ` ` import java.util.Scanner;

In java please
1. Use your own methods.
2. Minimize the main() as much as possible. ```
import java.util.Scanner;
public class J1mp_3{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
double totalReceipts =0.0;
// loop continuosly get input from hours parked
while (true){
System.out.println("Enter hours parked (or -1 to end):");
int hoursParked = scanner.nextInt();
// If the input is -1, end the loop
if (hoursParked ==-1){
break;
}
// function to print out charge for customers
double charge = calculateCharge(hoursParked);
totalReceipts += charge;
// prints a float in two decimal places
System.out.printf("Charge for current customer: $%.2f
", charge);
}
System.out.printf("Total receipts for yesterday: $%.2f
", totalReceipts);
scanner.close();
}
// calculate the amount of money charged per hour
public static double calculateCharge(int hours){
double charge =2.0; // Minimum charge for up to 3 hours
if (hours >3){
charge +=0.5*(hours -3);
}
if (charge >10.0){
charge =10.0; // Maximum charge for 24 hours
}
return charge;
}
}
```
In java please 1 . Use your own methods. 2 .

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!