Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class VendingMachine {
- Scanner in = new Scanner(System.in);
- double price;
- double bill;
- double change;
- int numberOfDollarCoins;
- int numberOfQuarterCoins;
- double quarter = 0.25;
- void inputMoney() {
- System.out.print("What item do you want? (Price) ");
- price = in.nextDouble();
- System.out.print("How much are you putting in? ");
- bill = in.nextDouble();
- }
- void difference () {
- price = price * 100;
- bill = bill * 100;
- change = bill - price;
- }
- void typeOfCoinsForChange () {
- numberOfDollarCoins = (int)change / 100;
- numberOfQuarterCoins = (int)((change - numberOfDollarCoins*100) / (quarter * 100));
- }
- public static void main(String[] args) {
- VendingMachine one = new VendingMachine();
- one.inputMoney();
- one.difference();
- one.typeOfCoinsForChange();
- System.out.println("Dollar Coins: " + one.numberOfDollarCoins);
- System.out.println("Quarter Coins: " + one.numberOfQuarterCoins);
- //System.out.println("Your change is " + one.numberOfDollarCoins + " dollars and " + one.numberOfQuarterCoins
- // + " quarters.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement