/**
* Charlotte Weisman
* B Block Computer Science
* 9/14/17
* Change Calculator
*/
import java.util.*;
public class changeCalculator
{
public static void main(String args[]){
int max = 1900;
int min = 100;
int randomNum = (int)(Math.random() * ((max - min) + 1)) + min; //inclusive
double myNum = randomNum/100.0; //"price"
System.out.println("Random Number: " + myNum);
double change = 20.0-myNum; //change from $20 bill
int newChange = (int)(change * 100); //newChang is change as int variable
System.out.println("change: " + (double)newChange/100);
int q = newChange / 25; //number of quarters
System.out.println("quarters: "+ q);
int change1 = newChange % 25; //remaining change after quarters
int d = change1 / 10; //number of dimes
System.out.println("dimes: " + d);
int change2 = change1 % 10; //remaining change after dimes
int n = change2 / 5; //number of nickels
System.out.println("nickels: " + n);
int change3 = change2 % 5; //remaining change after nickels
int p = change3 / 1; //number of pennies
System.out.println("pennies: " + p);
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.