Make Change

// Alex Lee //9/13/17 import java.text.DecimalFormat; public class MakeChange { public static void main(String[] args) { int max = 1900; int min = 100; int randomNum = (int)(Math.random() * ((max - min) + 1)) + min; //inclusive int change = 2000 - randomNum; //double myNum = randomNum/100.0; DecimalFormat format = new DecimalFormat("0.00"); int quarters = change/25; int dimes = change % 25/10; int nickels = change % 25 % 10/5; int pennies = change % 25 % 10 % 5/5; System.out.println("\nYour total cost is: $" + format.format(randomNum/100.0) + "."); System.out.println("\nYou payed $20."); System.out.println("\nYour total change is: $" + format.format(change/100.0) + "."); System.out.println("\nIn change you are given: "); System.out.println(quarters + " quarters "); System.out.println(dimes + " dimes "); System.out.println(nickels + " nickels "); System.out.println(pennies + " pennies "); System.out.println("This is because I do not like you particular."); //System.out.println("\nYou are given " + quarters + " quarters, " + dimes + " dimes, " + nickels + " nickels, " + pennies + " pennies in change because I don't particularly like you."); }// end of static }//end of class

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.