954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

java help for newbie

need to have an input of money to pay for an item and amount given.

to return change due with denomination format:

_ 20 dollar bills
_ 10 dollar bills
_ 5 dollar bills
_ 1 dollar bills
_ quarters
_ nickels, dimes, pennies, etc.


so far i got this:


import java.util.Scanner;


public class Cashier
{

//*****************************************************************
// Creates change to be given to customer from cashier.
//*****************************************************************

public static void main(String[] args)
{
double a;
double b;

Scanner scan = new Scanner (System.in);
System.out.print ("Enter total amount:$ ");
a = scan.nextDouble();

System.out.print ("Enter amount given:$ ");
b = scan.nextDouble();

System.out.print ("Change:$" + (b - a) );

}
}

groove04
Newbie Poster
6 posts since Oct 2005
Reputation Points: 10
Solved Threads: 0
 

need to have an input of money to pay for an item and amount given.

to return change due with denomination format:

_ 20 dollar bills _ 10 dollar bills _ 5 dollar bills _ 1 dollar bills _ quarters _ nickels, dimes, pennies, etc.

so far i got this:

import java.util.Scanner;

public class Cashier { //***************************************************************** // Creates change to be given to customer from cashier. //***************************************************************** public static void main(String[] args) { double a; double b;

Scanner scan = new Scanner (System.in); System.out.print ("Enter total amount:$ "); a = scan.nextDouble();

System.out.print ("Enter amount given:$ "); b = scan.nextDouble();

System.out.print ("Change:$" + (b - a) );

} }

First, before you do any programming, grab a piece of paper and plan what you think should happen.

You need to devise an algorithm to give theleast number of coins when you get change from a note.

When you've got that then we shall sort out your program. :eek:

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

import java.util.Scanner;


public class Cashier
{

//*****************************************************************
// Creates change to be given to customer from cashier.
//*****************************************************************

public static void main(String[] args)
{
double a;
double b;

Scanner scan = new Scanner (System.in);
System.out.print ("Enter Total Price: $");
a = scan.nextDouble();

System.out.print ("Enter Payment: $");
b = scan.nextDouble();
System.out.println();
System.out.println ();
System.out.println ("Total Price: $" + a);
System.out.println ("Your Payment: $" + b);

System.out.print ("Change: $" + (b - a) );

}
}

groove04
Newbie Poster
6 posts since Oct 2005
Reputation Points: 10
Solved Threads: 0
 

Here's some tips. Represent the total amount of money in cents. Represent the $20,$5,$10,$1 in cents as well. Start with the largest denomination you need to find, $20, and work down from there. Use modulus.

$20 = 2,000 cents

$56.73 = 5,673 cents

It'll be easier working with the whole numbers.

Phaelax
Practically a Posting Shark
858 posts since Mar 2004
Reputation Points: 92
Solved Threads: 51
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You