|
Site Index
About Me
Welcome
Definition of Program
Variable Types
Understanding Memory
Declaring Variables
Simple Commands
Concatenation and Strings
Sleep-Threads-Try
Catch
Campus Scenes
Pictures
Java simplified
Application Shell Styles
Reading Data From
File
Overview of Applets
Excellent Graphics
Applet
Online Reference
Nested
if statements
Arrays
Sorting Arrays
Using Strings
Functions
Top
20 Replies
First program 211
Important Class Example
JAVA in SDK Environment
Understanding
OOP
OOP simple example
Recursion example
Example of Inheritance
and use of JTextArea
*** Web Related **********
Build Student Web Page
?
What
is FTP
Download
WS ftp95
Download
Java Plug In
Applets
from jbuilder to sdk
Practice Problems

Programming Examples
| |
Program 1-5
//Application1 by B Cooper
//Takes an amount of money in cents and
//prints the amount of each coin needed
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Application1
{
public Application1()
{
boolean correct = false;
double num1;
int quarters;
int nickles;
int dimes;
int pennies;
int temp;
String str1 ="";
do {
str1 = JOptionPane.showInputDialog("Enter an amount of money
less than one
dollar.");//Input
num1 = Double.parseDouble(str1);//Convert String to Double
if (num1 < 1) //Test if num1 is in decimal form
correct = true;
} while(!correct);
temp = ((int) ((num1 * 100))); //Store num1 as int in temp
quarters = temp / 25; //Find the amount of quarters
temp %= 25; //Temp gets remander of money
dimes = temp / 10; //Find the amount of dimes
temp %= 10; //Temp gets remander of money
nickles = temp / 05; //Find the amount of nickles
temp %= 05; //Temp gets remander of money
pennies = temp / 01; //Find the amount of pennies
JOptionPane.showMessageDialog(null,"In " + num1 + " there are: \n" +
quarters + " Quarters \n"+ dimes + " Dimes \n" + nickles + " Nickles \n" +
pennies + " Pennies"); //Output
}
public static void main(String args[])
{
Application1 app = new Application1();
System.exit(0);
}
} |
|