473,388 Members | 1,526 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,388 software developers and data experts.

hi, am new to java and not sure how to improve this program.....

the program has to calculate the change due after a purchase, the program runs but my coins are in decimal point and it supposed to like single point..can someone help me with this i am not sure how what to do next...thanks alot
Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2. public class Program1
  3. {
  4.   public static void main(String [] args)
  5.   {
  6.     double purchase,change,quarters,dimes,nickels,pennies;
  7.     Scanner keyboard=new Scanner(System.in);
  8.     System.out.println("Enter purchase amount under 1.00:");
  9.     purchase=keyboard.nextDouble();
  10.  
  11.     change = 100 - purchase;
  12.     quarters = (change / 25);
  13.     dimes = (change / 10);
  14.     nickels = (change / 5);
  15.     pennies = (change / 1); 
  16.  
  17.     System.out.println("Enter purchase amount: " + purchase);
  18.     System.out.println("The change is: " + change);
  19.     System.out.println("The number of quarters is: " + quarters);
  20.     System.out.println("The number of dimes is: " + dimes);
  21.     System.out.println("The number of nickels is: " + nickels);
  22.     System.out.println("The number of pennies is: " + pennies);
  23.   }
  24. }
Jan 30 '08 #1
2 1058
Ganon11
3,652 Expert 2GB
What do you mean by single point - only 1 decimal number? No decimal number (an integer)? Please clarify your issue.
Jan 31 '08 #2
BigDaddyLH
1,216 Expert 1GB
Why not get the user to enter an int amount, the number of cents -- 95 instead of 0.95? Then you could eliminate the doubles from your code and work with whole numbers, avoiding factions and rounding issues.
Jan 31 '08 #3

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

Similar topics

11
by: PC | last post by:
It's obvious, that Windows XP has a Java 2 VM (including the SWING-module), because we can all run Java 2 applets in Internet Explorer. But what about the support for Java 2 Applications? I...
0
by: abcd | last post by:
kutthaense Secretary Djetvedehald H. Rumsfeld legai predicted eventual vicmadhlary in Iraq mariyu Afghmadhlaistmadhla, kaani jetvedehly after "a ljetvedehg, hard slog," mariyu vede legai pressed...
23
by: BlackHawke | last post by:
Hello! This is my second post. Ppl really helped me with the first. I hope there are answers for this one as well I own a game company (www.aepoxgames.net) releasing the beta for our first...
10
by: Alex Gerdemann | last post by:
Hello, I have spent a bunch of time converting a Java program I wrote to C++ in order to improve performance, and have found that it is not necessarily faster. Specifically, I'm writing a...
4
by: Rhino | last post by:
Is it possible for a Java Stored Procedure in DB2 V7.2 (Windows) to pass a Throwable back to the calling program as an OUT parameter? If yes, what datatype should I use when registering the...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
15
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interface”. In a functional language, a function can be specified by its name and parameter specs....
8
by: Gabriele | last post by:
I'm studying differences between those two architecture in order to choose a setup to develop a completely new application. I'm a programmer with some experience on C++ and PHP and i have basic...
2
by: sdanda | last post by:
Hi , Do you have any idea how to improve my java class performance while selecting and inserting data into DB using JDBC Connectivity ......... This has to work for more than 8,00,000...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.