Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Please help :S

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please help :S

    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

  2. #2
    Member Zyrion's Avatar
    Join Date
    Feb 2013
    Location
    Iowa
    Posts
    106
    My Mood
    Angelic
    Thanks
    2
    Thanked 8 Times in 8 Posts

    Default Re: Please help :S

    Format your code with code tags for readability. Is there more to your code than what you have posted?

    [C0DE=java]
    <code>
    [/CODE]

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: Please help :S

    It's hard to figure out what's wrong with just a snippet of the code. We don't know what type TicketHandler is for instance.