SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Java Program
Hybrid View
-
Sep 1, 2001, 23:33 #1
- Join Date
- Aug 2001
- Location
- London
- Posts
- 2,475
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Java Program
I know this is a little of the topic,
But could Ne one help me with this,
I have just started college, and the teachers told us
F-all on how to write a Java program,
as far as I know,
is out to writeln and readln,
A Console Application.
The Problem.
IE.
I need to make an out put look like this:
_________________________________________
Purchase Price: $ 34.50
Amount Tendered: $ 40.00
Your Change is: $ 5.50
5 one-dollar Bill(s)
2 quatre(s)
Thank you for your business.
__________________________________________
So far I can work out the sums, but i only get to 1 decimal place, and the next is how do i get the worded example?
My source code so far:
___________________________________________
import ccj.*;
public class Class1
{
public static void main (String[] args)
{
float Purchase;
float Tender;
float Change;
float Amount;
//Linebreak
System.out.println ("");
//Purchase Price
System.out.println ("Purchase Price? ");
Purchase = Console.in.readInt();
System.out.print ("Purchase Price: " + '$');
System.out.println (Purchase);
//Linebreak
System.out.println ("");
//Amount Tendered
System.out.println ("Tender? ");
Tender = Console.in.readInt();
System.out.print ("Amount Tendered: " + '$');
System.out.println (Tender);
//Linebreak
System.out.println ("");
System.out.println ("Change");
//Linebreak
System.out.println ("");
System.out.println ("_____________");
//Linebreak
System.out.println ("");
//Check Sum
System.out.println (Tender-Purchase);
//Linebreak
System.out.println ("");
//Check Sum
System.out.println ("Thank You For our Business. Come Back Soon.");
float x ;
x = Console.in.readInt();
}
}
_________________________________________
Cheers,
-
Sep 16, 2001, 02:38 #2
- Join Date
- Aug 2000
- Location
- Singapore
- Posts
- 411
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You can use DecimalFormat.
Include the following imports.
import java.text.DecimalFormat;
add this in your body:
DecimalFormat df2 = new DecimalFormat("0.00");
then for every variable that you need it to be displayed as 2 decimal places, do this:
system.out.println(df2.format(variable));First Million Challenge - Blog Challenge To Make My First Million
Active-Income.com | Active Jokes | Active-Freebies.com | Active Free Stuff
-
Sep 16, 2001, 04:51 #3
- Join Date
- Aug 2001
- Location
- London
- Posts
- 2,475
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
TY Are there Ne good Resource Sites
For complete beginners in Java
Bookmarks