static void processTicket(TicketHandler ticket)
{ // method to process route ticket
if (ticket.getNoOfRouteTickets()>=1)
{
do
{
System.out.printf("Ticket cost: £ %.2f", ticket.getCostOfRoute()); // output ticket cost
System.out.print("\nAmount of cash entered: £"); // input amount of cash entered into the ticket machine
cashEntered=keyboard.nextDouble();
remainingCost=costOfRoute-cashEntered; // calculate remaining cost
System.out.println("You have not entered enough money. Please enter £ "+Math.abs(remainingCost)); // output remaining cost owed
}
while (cashEntered<costOfRoute);
}
else
{
System.out.println("Sorry no more tickets are available. Please purchase your ticket at the counter."); // output error message
}
if (cashEntered>costOfRoute)
{
change = cashEntered-costOfRoute; // calculate customer change
System.out.println("You have £" +Math.abs(change)+" change."); // output amount of change owed to customer
}
else
{
System.out.println("You have no change."); // output message
}
}
this piece of code won't work out the remaining cost correctly. it is just outputting the cash entered. the change is doing the same. rather than calculating the change and remaining cost it is repeating the cash entered amount.
please help me if you can :S