473,320 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

need help with question

i need to make a java code that
makes an ammount and puts them in dollars and coins
$14.96
14 dollars(no 20 or 50 dollar bills just ones)
3 quarters
2 dimes
1 nickle
1 pennie

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. public class Lab5
  3. {
  4. public static void main(String[] args)
  5.     {
  6. double dollar_value(1.00);
  7. double quarter_value(0.25);
  8. double dime_value(0.10);
  9. double nickel_value(0.05);
  10. double pennies_value(0.01);
  11.  
  12. int num_dollars;
  13. int num_quarters;
  14. int num_dimes;
  15. int num_nickels;
  16. int num_pennies;
  17. int total_num_coins;
  18. int total_val_money = dollar_value + quarter_value + dime_value + nickel_value + pennies_value;
  19. int total_dollar_val = dollar_value * num_dollars;
  20. int total_quarter_val = quarter_value * num_quarters;
  21. int total_dime_val = dime_value * num_dimes;
  22. int total_nickel_val = nickel_value * num_nickels;
  23. int total_pennies_val = pennies_value * num_pennies;
  24.  
  25. system.out.println ammount("14.96");
  26.  if(00.)
i stopped its unfinished cause my teacher says its wrong but my speudocode is wright cant find it so i count type it here lol

i need help with this and im using
jgrasp
with jdk6 update
Feb 23 '08 #1
2 1041
sukatoa
539 512MB
import javax.swing.*;
public class Lab5
{
public static void main(String[] args)
{
double dollar_value(1.00);
double quarter_value(0.25);
double dime_value(0.10);
double nickel_value(0.05);
double pennies_value(0.01);

int num_dollars;
int num_quarters;
int num_dimes;
int num_nickels;
int num_pennies;
int total_num_coins;
int total_val_money = dollar_value + quarter_value + dime_value + nickel_value + pennies_value;
int total_dollar_val = dollar_value * num_dollars;
int total_quarter_val = quarter_value * num_quarters;
int total_dime_val = dime_value * num_dimes;
int total_nickel_val = nickel_value * num_nickels;
int total_pennies_val = pennies_value * num_pennies;

system.out.println ammount("14.96");
if(00.)


Yah, actually you forgot this....
Are you aware of assigning double values to integer values?
they are different datatypes....
double is much bigger than integer values...

The vm will really not accept the code above....
make all variables double....
Feb 24 '08 #2
JosAH
11,448 Expert 8TB
make all variables double....
I'd suggest to make the monetary unit the penny/cent, i.e. dollar= 100, quarter= 25,
dime=10, etc. and make all variables integer. Simply rely on the behaviour of
integer division and the modulo operator. Integer division simply ignores the
remainder of the division while the modulo operator returns the remainder.

$1.49 == 149 cents. 149/100 = 1 dollar and 149%100 = 49 cents left
49/25 = 1 quarter and 49%25= 24 cents left etc. etc.

kind regards,

Jos
Feb 24 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
34
by: Mark Kamoski | last post by:
Hi-- Please help. I need a code sample for bubble sort. Thank you. --Mark
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
19
by: ern | last post by:
I need a FIFO queue of size 20, to keep track of a running average. Once the queue is full with 20 values, I want to take the sum/20 = AVERAGE. Then when a new value comes in, I want: (Old Sum...
16
by: C++ Hell | last post by:
Hey everyone just designing a quiz for school and managed to write the code for the questions and answers thou i have to add scores and at the end an overall score does anyone have any idea what to...
6
by: kenshiro | last post by:
Hi All, I'm having a problem with some VBA code in one of my Access 2003 databases. I'm getting the following error when running code behind a command button on a form: "Item not found in this...
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
0
by: biganimal | last post by:
I have a program and I want the program to be able to save question/answers so the program actually gets smarter without getting amnesia everytime its started. Can anyone help??? # questor.py ...
27
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.