Last active
August 29, 2015 14:22
-
-
Save itsJarrett/3de0ec3860478e71c0c8 to your computer and use it in GitHub Desktop.
Change Machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String args[]) { | |
Scanner s = new Scanner(System.in); | |
System.out.println("Enter the amount you want change for."); | |
System.out.print("$"); | |
double change = s.nextDouble(); | |
int onehundred = (int) (change / 100); | |
int lo = (int) (change % 100); | |
int fiftydollar = lo / 50; | |
lo = lo % 50; | |
int twentydollar = lo / 20; | |
lo = lo % 20; | |
int tendollar = lo / 10; | |
lo = lo % 10; | |
int fivedollar = lo / 5; | |
lo = lo % 5; | |
int onedollar = lo / 1; | |
String n = "" + change; | |
String[] nums = n.split("\\."); | |
int change1 = Integer.parseInt(nums[1]); | |
int quarter = change1 / 25; | |
lo = change1 % 25; | |
int dime = lo / 10; | |
lo = lo % 10; | |
int nickle = lo / 5; | |
lo = lo % 5; | |
int penny = lo; | |
System.out.println("-=-=-=-=-=-=-=-=-=-"); | |
System.out.println(onehundred + " One Hundred dollar bill(s)."); | |
System.out.println(fiftydollar + " Fifty dollar bill(s)."); | |
System.out.println(twentydollar + " Twenty dollar bill(s)."); | |
System.out.println(tendollar + " Ten dollar bill(s)."); | |
System.out.println(fivedollar + " Five dollar bill(s)."); | |
System.out.println(onedollar + " One dollar bill(s)."); | |
System.out.println(quarter + " Quarter(s)."); | |
System.out.println(dime + " Dime(s)."); | |
System.out.println(nickle + " Nickle(s)."); | |
System.out.println(penny + " Penny / Pennies"); | |
System.out.println("-=-=-=-=-=-=-=-=-=-"); | |
if (lo == 0) { | |
System.out.println("That change does not need any pennies!"); | |
} else { | |
System.out.println("That change needs pennies!"); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment