944,052 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1655
  • Java RSS
Feb 9th, 2006
0

java help for newbie

Expand Post »
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) );


}
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
groove04 is offline Offline
6 posts
since Oct 2005
Feb 9th, 2006
0

Re: java help for newbie

Quote originally posted by groove04 ...
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 the least number of coins when you get change from a note.

When you've got that then we shall sort out your program. :eek:
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Feb 9th, 2006
0

Re: java help for newbie

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) );


}
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
groove04 is offline Offline
6 posts
since Oct 2005
Feb 10th, 2006
0

Re: java help for newbie

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.
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: No able to set the jpanel positions
Next Thread in Java Forum Timeline: Java open internet browser





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC