Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I wrote this program in NetBeans and I do not know how to get it so the fee\'s c

ID: 3624110 • Letter: I

Question

I wrote this program in NetBeans and I do not know how to get it so the fee's come out correctly.Please Help!!!!!!!!!!!!!!
___________________________________________________________________________
Your challenge is to write a program to simulate a parking garage fee collection system using varying fee calculation algorithms. Every parking garage business has a cash register that calculates the fee for each car that parks there. But the actual formula used for this calculation will vary with the garage business. We need to be able to plug in different fee calculation components into the cash register without the need to modify the cash register source code.

Here are the fee calculation components you must support. You should be able to switch from one to the other without breaking code, and you should assume other components like this will be needed in the future.

BestValue Fee Calculator
This fee is based on a $2.00 minimum fee to park for up to three hours. After that there is an additional $0.50 per hour charge for each hour or part of an hour parked. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours.

Thrifty Fee Calculator
This fee is based on a $1.50 minimum fee to park for up to two hours. After that there is an additional $0.75 per hour for each hour or part of an hour parked. There is no maximum charge. Assume that no car parks for longer than 24 hours.

Input and Output
The INPUT will be the hours parked for a single car. You must enter this input using the Scanner object or the JOptionPane object (your choice). Once the input is provided, the cash register should automatically calculate the fee to be paid by that car using the provided calculator component. Remember, you should be able to switch calculators at any time without changing the cash register code. The OUTPUT will be the hours parked and fee for that car, plus the running totals for the garage while the program is running (total hours parked and total fees collected). You may display this output at the console or in a JOptionPane (your choice).
Don’t over-engineer your solution. You goal is to demonstrate the principles and practices learned to date – especially Encapsulation and the DIP.



_______________________________________________________________________________________________________________________

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ParkingGarageFeeCollectionSystem;


Your challenge is to write a program to simulate a parking garage fee collection system using varying fee calculation algorithms. Every parking garage business has a cash register that calculates the fee for each car that parks there. But the actual formula used for this calculation will vary with the garage business. We need to be able to plug in different fee calculation components into the cash register without the need to modify the cash register source code.

Here are the fee calculation components you must support. You should be able to switch from one to the other without breaking code, and you should assume other components like this will be needed in the future.

BestValue Fee Calculator
This fee is based on a $2.00 minimum fee to park for up to three hours. After that there is an additional $0.50 per hour charge for each hour or part of an hour parked. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours.

Thrifty Fee Calculator
This fee is based on a $1.50 minimum fee to park for up to two hours. After that there is an additional $0.75 per hour for each hour or part of an hour parked. There is no maximum charge. Assume that no car parks for longer than 24 hours.

Input and Output
The INPUT will be the hours parked for a single car. You must enter this input using the Scanner object or the JOptionPane object (your choice). Once the input is provided, the cash register should automatically calculate the fee to be paid by that car using the provided calculator component. Remember, you should be able to switch calculators at any time without changing the cash register code. The OUTPUT will be the hours parked and fee for that car, plus the running totals for the garage while the program is running (total hours parked and total fees collected). You may display this output at the console or in a JOptionPane (your choice).
Don’t over-engineer your solution. You goal is to demonstrate the principles and practices learned to date – especially Encapsulation and the DIP.


/**
*
* @author
*/
public class BestValueFeeCalculator implements FeeCalculator {

private static final double MIN_DOLLARS = 02.00;
private static final double MAX_DOLLARS = 10.00;
private static final int MIN_HOURS = 3;
private static final int MAX_HOURS = 24;
private static final String HOUR_FEE_ERR =
"Error: baseFeePerHour must be greater than " + MIN_HOURS;
private static final String HOUR_AMT_ERR =
"Error: hours must be between " + MIN_HOURS + " and " + MAX_HOURS;
private double dollars;
private int hours;

public BestValueFeeCalculator(int hours, double dollars ){
setHours(hours);
setDollars(dollars);

}

BestValueFeeCalculator(double d, double d0) {
if (hours < MIN_HOURS || hours > MAX_HOURS) {
throw new IllegalArgumentException(HOUR_AMT_ERR);
}
}


public double getFee(){
double fee = 0.00;

if (hours <= 3)
fee = hours * dollars;

else {
fee = hours * dollars + hours * 0.50;
}
return fee;
}

public void setHours(int hours) {

this.hours = hours;
}

public void setDollars(double dollars) {
this.dollars = dollars;
}
}

_______________________________________________________________________________________________________________
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package ParkingGarageFeeCollectionSystem;

/**
*
* @author
*/
public interface FeeCalculator {
public double getFee();


}

_______________________________________________________________________________________________________________

* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package ParkingGarageFeeCollectionSystem;

/**
*
* @author
*/
public class FeeManager {

public double getFee(FeeCalculator e) {
return e.getFee();
}
}

______________________________________________________________________________________________________________________

* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package ParkingGarageFeeCollectionSystem;
import java.text.NumberFormat;

import javax.swing.JOptionPane;
/**
*
* @author /*


*/
public class Startup {
public static void main(String[] args) {

FeeCalculator calc1 = new BestValueFeeCalculator(5,10);
FeeCalculator calc2 = new ThriftyFeeCalculator(3,5);

FeeManager tm = new FeeManager();

NumberFormat nf = NumberFormat.getCurrencyInstance();

System.out.println("Best Value amount: " + nf.format(tm.getFee(calc1)));
System.out.println("Thrifty amount: " + nf.format(tm.getFee(calc2)));
}
}

_____________________________________________________________________________________________________________________
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package ParkingGarageFeeCollectionSystem;

/**
*
* @author
*/
public class ThriftyFeeCalculator implements FeeCalculator{
private static final double MIN_DOLLARS = 01.50;
private static final double MAX_DOLLARS = 18.00;
private static final int MIN_HOURS = 3;
private static final int MAX_HOURS = 24;
private static final String HOUR_FEE_ERR =
"Error: baseFeePerHour must be greater than " + MIN_HOURS;
private static final String HOUR_AMT_ERR =
"Error: hours must be between " + MIN_HOURS + " and " + MAX_HOURS;
private double dollars;
private int hours;

public ThriftyFeeCalculator(int hours, double dollars ){
setHours(hours);
setDollars(dollars);

}

ThriftyFeeCalculator(int i, double d, double d0) {
if (hours < MIN_HOURS || hours > MAX_HOURS) {
throw new IllegalArgumentException(HOUR_AMT_ERR);
}
}


public double getFee(){
double fee = 0.00;

if (hours <= 3)
fee = hours * dollars;

else {
fee = hours * dollars + hours * 0.75;
}
return fee;
}

public void setHours(int hours) {
if (hours < MIN_HOURS || hours > MAX_HOURS) {
throw new IllegalArgumentException(HOUR_AMT_ERR);
}
this.hours = hours;
}

public void setDollars(double dollars) {
this.dollars = dollars;
}
}

Explanation / Answer

There is some code here that works: http://dl.dropbox.com/u/3994611/Cramster/feecalculator.zip