MakeChange

/** * Write a description of class change here. *Finds change * @author (Rahul Khullar) * @version (9/14/17) */ public class change { // instance variables - replace the example below with your own public static void main(String args[]) { int max = 1800; int min = 100; int randomNum = (int)(Math.random() * ((max - min) + 1)) + min; //inclusive double myNum = randomNum/100.0; System.out.println("Random Number: " + myNum); double change = 20 - myNum; System.out.println("Change: " + change); int numchange = ((int)(change * 100) % 25); double quarters = ((int)(change * 100) / 25); System.out.println("Quarters: " + (int)quarters); int dimes = numchange/10; numchange = numchange % 10; System.out.println("Dimes: " + dimes); int nickels = numchange/5; numchange = numchange % 5; System.out.println("Nickels: " + nickels); int pennies = numchange/1; numchange = numchange % 1; System.out.println("Pennies: " + pennies); } }

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.