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 2 of 2

Thread: New to this, is my code right???

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default New to this, is my code right???

    new at this does my code work out to display this output....

    Output:

    Enter the amount of the purchases: (user enters 44.28)
    Enter the cash tendered: (user enters 50)

    Your change is equal to 5.71999999999 which is...
    5 dollars 72 cents
    2 quarter (s)
    2 dime(s)
    0 nickel (s)
    2 pennie (s)
    __________________________________________________ _
    package lab02;

    /**
    * Purpose: Compute the amount of change a customer should
    * receive (in terms of dollars, quarters, dimes, nickels, and
    * pennies) given the amount of the purchase and the cash tendered.
    *
    * @author jdoe
    *
    */

    import java.util.Scanner;

    public class Change
    {

    /**
    * @param args
    */
    public static void main(String[] args)
    {
    double purchaseAmt;
    double cashTendered;
    double totalChange;
    int dollars, cents;

    // Create a Scanner object to read from standard input
    Scanner scan = new Scanner(System.in);

    // Prompt the user and read in amount of purchase and
    // cash tendered.
    System.out.print("Enter the amount of the purchase: ");
    purchaseAmt = scan.nextDouble();
    System.out.print("Enter the cash tendered: ");
    cashTendered = scan.nextDouble();

    totalChange = cashTendered - purchaseAmt;
    dollars = (int) totalChange;

    System.out.println();
    System.out.println ("Your change is $" + totalChange
    + " which is ...");
    System.out.println(dollars + " dollars");

    System.out.println();
    int quarters, pennies, dimes ,nickels;
    quarters = (totalChange-dollars)/.25;
    System.out.println(quarters + "quarter (s)");
    dimes= (totalChange-dollars-(.25*quarters))/.10;
    System.out.println(dimes + "dime (s)");
    pennies= (totalChange-dollars-(.25*quarters)-(.10*dimes)/.01);
    System.out.println(pennies + "pennies");




    }

    }


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: New to this, is my code right???

    Double post of
    http://www.javaprogrammingforums.com...ing-learn.html

    ryan1234 also started three threads with the same question at the Sun/Oracle forums. The threads have been removed and the user blocked for multiposting.

    db