Ok would someone look at this code and please tell me what I need to do to make the program run correctly? It is supposed to give the user a message if they enter any money below 25 cents or over 100. And it's not doing what it's supposed to. Plus, I have no idea how to code the part about only taking multiples of five. I know there are some smart, smart
java guys out there that can help me. I'd appreciate anything you can tell me.
Rose //**********************************************************
//* This program is a Vending Machine that accepts money *
//* from 25 cents to 100. *
//* If the user enters an amount lower than 25 cents, an *
//* error message should say, "A cost under 25 cents." *
//* If the user enters an amount over 100 an error *
//* message should say,"A cost that is more than a dollar."*
//* The user should also only be able to enter a price in *
//* multiple of fives, an error message should say,"A cost *
//* that is not an integer multiple of five." *
//**********************************************************
//* Author: Rose Evans *
//* Date last modified: October 14th 2004. *
//**********************************************************
public class ChangeMakerModified
{
public static void main(
String[] args)
{
int CANDYBAR = 55;
int DRINK = 65;
int PEANUTS = 50;
int CHIPS = 45;
int originalAmount, quarters, dimes, nickels, pennies;
int choice = 0;
int money = 0;
int amount = 0;
System.out.println("**********************************");
System.out.println("* Vending Machine *");
System.out.println("* Candy Bar - 55 Press 1 *");
System.out.println("* Drink - 65 Press 2 *");
System.out.println("* Peanuts - 50 Press 3 *");
System.out.println("* Chips - 45 Press 4 *");
System.out.println("**********************************");
System.out.println("Please enter your selection.");
choice = SavitchIn.readLineInt();
System.out.println("Enter an amount of money no less than 25");
System.out.println("cents, and no more than 100.");
System.out.println("I will output a combination of coins");
System.out.println("that equals that amount of change.");
{
money = SavitchIn.readLineInt();
//if (money < 25);
//System.out.println("You must enter an amout over 25 cents.");
//if (money > 100);
//System.out.println("You must enter an amount less than 100.");
// if ((money < 25) && (money > 100));
//System.exit(0);
}
switch(choice)
{
case 1:
System.out.println("You entered: " +money);
System.out.println("You chose a Candy Bar - .55");
amount = money - CANDYBAR;
System.out.println("Your change is: "+ amount + " cents");
System.out.println(amount + " cents in coins can be given as: ");
quarters = amount/25;
amount = amount%25;
dimes = amount/10;
amount = amount%10;
nickels = amount/5;
amount = amount%5;
pennies = amount;
System.out.println(quarters + " quarter(s)");
System.out.println(dimes + " dime(s)");
System.out.println(nickels+ " nickel(s) and ");
System.out.println(pennies + " pennies");
System.out.println("Thank you! Enjoy your snack!");
break;
case 2:
System.out.println("You entered: " +money);
System.out.println("You chose a Drink - .65");
amount = money - DRINK;
System.out.println("Your change is: "+ amount + " cents");
System.out.println(amount + " cents in coins can be given as: ");
quarters = amount/25;
amount = amount%25;
dimes = amount/10;
amount = amount%10;
nickels = amount/5;
amount = amount%5;
pennies = amount;
System.out.println(quarters + " quarter(s)");
System.out.println(dimes + " dime(s)");
System.out.println(nickels + " nickel(s) and ");
System.out.println(pennies + " pennies");
System.out.println("Thank you! Enjoy your snack!");
break;
case 3:
System.out.println("You entered: " +money);
System.out.println("You chose Peanuts - .50");
amount = money - PEANUTS;
System.out.println("Your change is: "+ amount + " cents");
System.out.println(amount + " cents in coins can be given as: ");
quarters = amount/25;
amount = amount%25;
dimes = amount/10;
amount = amount%10;
nickels = amount/5;
amount = amount%5;
pennies = amount;
System.out.println(quarters + " quarter(s)");
System.out.println(dimes + " dime(s)");
System.out.println(nickels + " nickel(s) and ");
System.out.println(pennies + " pennies");
System.out.println("Thank you! Enjoy your snack!");
break;
case 4:
System.out.println("You entered: " +money);
System.out.println("You chose Chips - .45");
amount = money - CHIPS;
System.out.println("Your change is: "+ amount + " cents");
System.out.println(amount + " cents in coins can be given as: ");
quarters = amount/25;
amount = amount%25;
dimes = amount/10;
amount = amount%10;
nickels = amount/5;
amount = amount%5;
pennies = amount;
System.out.println(quarters + " quarters");
System.out.println(dimes + " dimes");
System.out.println(nickels + " nickels and ");
System.out.println(pennies + " pennies");
System.out.println("Thank you! Enjoy your snack!");
break;
//Default message if user makes a choice other than 1 - 4.
default:
System.out.println("You must enter a selection between 1 and 4. Thank You!");
}
}
}