java help for newbie

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2005
Posts: 6
Reputation: groove04 is an unknown quantity at this point 
Solved Threads: 0
groove04 groove04 is offline Offline
Newbie Poster

java help for newbie

 
0
  #1
Feb 9th, 2006
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) );


}
}
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: java help for newbie

 
0
  #2
Feb 9th, 2006
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:
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 6
Reputation: groove04 is an unknown quantity at this point 
Solved Threads: 0
groove04 groove04 is offline Offline
Newbie Poster

Re: java help for newbie

 
0
  #3
Feb 9th, 2006
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) );


}
}
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 802
Reputation: Phaelax is on a distinguished road 
Solved Threads: 40
Phaelax Phaelax is offline Offline
Practically a Posting Shark

Re: java help for newbie

 
0
  #4
Feb 10th, 2006
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1569 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC