Make Change

// Sebastian Garrubbo // 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; DecimalFormat format = new DecimalFormat("0.00"); int q = change/25; int d = change%25/10; int n = change%25%10/5; int p = change%25%10%5/5; System.out.println("\nYour total cost is $" + format.format(randomNum/100.0) + "."); System.out.println("You payed $20"); System.out.println("Your change is $" + format.format(change/100.0) + "."); System.out.println("You are given " + q + " quarters, " + d + " dimes, " + n + " nickels, " + p + " pennies in change"); } }

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.