Question: We have the following Java code, and I need to run a few test inputs.. What do I need to write to a Main.java file

We have the following Java code, and I need to run a few test inputs.. What do I need to write to a Main.java file to put test inputs through ParkingCharge.java and ParkingChargeDriver.java?

// ParkingCharge.java

/* * Author ......: *****, * Level .......: Intermediate * Target ......: Java Console Application * Description..: Driver for Parking Garage * */ public class ParkingCharge {

// set final variables private static final double MINCHAEGE = 2.0; private static final double MAXCHARGE = 10.0; private static final double INCCHARGE = 0.50;

// Set min and max hours private static final double MINHOURS = 3.0; private static final double MAXHOURS = 24;

// Set variable to keeping track of daily charges private double runTotal;

// constructor public ParkingCharge(double runTotal) { // Assign instance variables. this.runTotal = runTotal;

}

/** @return runTotal returns running total of charges */ public double getRunTotal() { return runTotal; }

/** @param runTotal sets running total of charges */ public void setRunTotal(double runTotal) { this.runTotal = getRunTotal() + runTotal; }

/** Calculate Charges - calculate customer and total running charges */ public static double calculateCharges(double customerHours) { // Set variable for customer hours double customerCharge = 0.0;

// If customerHours are < 3 first, set MINCHAEGE if (customerHours <= MINHOURS) { customerCharge = MINCHAEGE; }

// If customerHours greater than MINHOURS and less than MAXHOURS // calculate the charge if((customerHours > MINHOURS) && (customerHours < MAXHOURS)) { customerCharge = INCCHARGE * (Math.ceil(customerHours) - MINHOURS) + MINCHAEGE;

if (customerCharge > MAXCHARGE) { customerCharge = MAXCHARGE; } // If customerHours are greater than MAXHOURS, set MAXCHARGE if(customerHours > MAXHOURS) { customerCharge = MAXCHARGE; }

// Return customer parking charge return customerCharge;

} // END - Calculate Charges method.

} /* END - ParkingCharge class */

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// ParkingChargeDriver.java

import java.util.Scanner;

public class ParkingChargeDriver {

public static void main(String[] args) { // Initialize the Scanner Scanner input = new Scanner(System.in);

// Initialize loop control and counter variables. double hours = 0.0; double charges;

// Set the input objects to 0 initially. ParkingCharge costs = new ParkingCharge(0.0);

// Start while loop for customer hour entry. while (hours != -1) { System.out.printf("Enter Hours (-1 to quit)..: "); hours = input.nextDouble();

// Only allow entry if hours are greater than zero if(hours > 0) { charges = ParkingCharge.calculateCharges(hours); costs.setRunTotal(charges); System.out.printf("Customer charge is........: " + "$%.2f ", charges); System.out.print(" "); System.out.printf("Running Daily Total.......: " + "$%.2f%n", costs.getRunTotal()); } System.out.print(" "); } // END - Customer Hours Entry.

// Close the input scanner ( prevent resource leaks ) input.close();

// END - Customer Hour Entry. System.out.printf("Total Daily Reciepts = $%.2f%n", costs.getRunTotal()); } // END - Main Method. } /* END - ParkingChangeDriver class */

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 Databases Questions!