Question: Can anyone help me create this program? The instructions are as follow: Write a program that calculates charges for parking. import java.util.Scanner; public class Garage
Can anyone help me create this program? The instructions are as follow:
Write a program that calculates charges for parking.
import java.util.Scanner;
public class Garage {
public static void main(String[] args)
{ //retrieve user input // declare and initial double for total fee collected for the day, name your variable totalReceipts and assign a value of 0 // display the following prompt to the user stating "Enter number of hours (-1 to quit): " // declare a double variable hours to store the input entered by the user (remember to use the nextDouble method) // create a while loop that will execute as long as the hours variable is greater than or equal to 0 // calculate and print the charges // declare a double variable, name your variable fee. Call the calculateCharges(...) method below and use the hours variable as your input parameter. // calculate the totalReceipts using the follwoing formula totalReceipts+= fee; // print the fee and totalReceipts value using printf // display the following prompt to the user stating "Enter number of hours (-1 to quit): " // use the hours variable to store the input entered by the user (remember to use the nextDouble method) } // Enter the following code AS-IS. This portion of the program is used to determine fees based on time
public static double calculateCharges(double hours)
{
// apply minimum charge double charge = 2.0; // add extra fees as applicable if (hours > 3.0) { charge = 2.0 + 0.5 * Math.ceil(hours - 3.0); } // apply maximum charge if needed if (charge > 10.0) { charge = 10.0; } return charge; }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
