[highlight = java]
public class FuelPump
{
//Text file
private boolean poweredOn; // 1 premium 2.34 100
private FuelDispenser activeDispenser; //2 regular 2.10 100
private double currentSalePrice; // 3 midgrade 2.78 100
private int gallonsPumped; // 4 diesel 2,78 100
private ArrayList<FuelDispenser> dispensers;
private Payment payment;
public FuelPump() throws Exception
{
dispensers = new ArrayList<FuelDispenser>();
Scanner input = new Scanner(new File("FuelDispenser_config.txt"));
int IndexValue ;
String FuelType ;
double Price ;
int Amount ;
while(input.hasNext())
{
IndexValue = input.nextInt();
FuelType = input.next();
Price = input.nextDouble();
Amount = input.nextInt();
dispensers.add(new FuelDispenser(IndexValue, FuelType, Price, Amount));
}
input.close();
currentSalePrice = 0.0;
gallonsPumped = 0;
payment = new Payment();
turnOff();
}
public void welcome()
{
System.out.println("Welcome to CSE Gas Station");
}
public void askForPaymentType()
{
int response = 0;
System.out.println("Select Payment Method");
do{
System.out.println("1. Credit");
System.out.println("2. Cash");
System.out.println("3. Shutdown/Exit Processing");
Scanner sc = new Scanner(System.in);
response = sc.nextInt();
}while( response < 0 || response > 4 );
if(response == 1)
payment = new CreditCardPayment();
if(response == 2)
payment = new CashPayment();
if(response == 3)
System.exit(0);
}
public void askForFuelType()
{ int input = 0;
int j = 0; double b = 0.0; String s = "";
Scanner sc = new Scanner(System.in);
System.out.println("Select Fuel Type:");
do{
for(int i = 0; i < dispensers.size(); i++)
{
j = dispensers.get(i).getFuelIndex();
System.out.print(j);
System.out.print(".");
s = dispensers.get(i).getGrade();
System.out.print(s);
System.out.print(" :");
b = dispensers.get(i).getPrice();
System.out.println(b);
}
input = sc.nextInt();
}while(input < 1 || input > 4);
activeDispenser = dispensers.get(input);
}
public void processPayment()
{
payment.processPayment();
}
public void pump()
{
int gallonsPumped;
double d = payment.getAmount();
double b = activeDispenser.getPrice();
int gallonsRequested = 0;
if(poweredOn == true && b != 0.0 && d != 0.0)
gallonsRequested = (int)(payment.getAmount()/b);
gallonsPumped = activeDispenser.pumpFuel(gallonsRequested);
currentSalePrice = gallonsPumped * activeDispenser.getPrice();
payment.setAmount(currentSalePrice);
}
public void printReceipt()
{
payment.printReceipt(activeDispenser.getGrade(), gallonsPumped, activeDispenser.getPrice());
}
public void thankYouForYourBusiness()
{
System.out.println("Thank you for your business");
}
public void turnOn()
{
poweredOn = true;
}
public void turnOff()
{
poweredOn = false;
}
public String toString()
{
return "hello";
}
}
[/highlight]