Question
I'm making a Java program that allows a user the ability to choose one product inside a vending machine then allows the user the ability
I'm making a Java program that allows a user the ability to choose one product inside a vending machine then allows the user the ability to print the whole day transaction or receipt of the vending machine. I want to print out the receipt that will include the name and the cost of each of the products ordered. I found that using an array is the only way I can get the items ordered in a list format. Help and suggestions would really be appreciated. Keep in mind that I cant do advanced stuff. I posted my program below.
*************************************************************************
import java.util.Scanner;
public class Assignment_main
{
public static void main(String[] args)
{
VendingMachine1 machine = new VendingMachine1();
InventoryManagement management = new InventoryManagement ();
Scanner input = new Scanner(System.in);
String response;
double amountB;
int choice;
do{
System.out.println("-----------------MENU-----------------");
System.out.println("---------Select a Snack Option--------");
System.out.println("Press 1 for M & M's: (Price $1.00)");
System.out.println("Press 2 for Popcorn: (Price $3.67)");
System.out.println("Press 3 for Snickers: (Price $4.00)");
System.out.println("Press 4 for Gum: (Price $0.99)");
System.out.println("Press 5 for Crackers: (Price $1.89)");
System.out.println("Press 6 for Chips: (Price $0.99)");
System.out.println("Press 7 for Corn: (Price $0.88)");
System.out.println("Press 8 for Soda: (Price $1.29)");
System.out.println("Press 9 for Milk (Price $5.00)");
System.out.println("Press 10 for Juice: (Price $3.00)");
System.out.println("Press 11 for Water: (Price $2.00)");
System.out.println("Press 12 for Bars: (Price $4.00)");
System.out.println("Press 13 for Donuts: (Price $3.35)");
System.out.println("Press 14 for Tuna: (Price $2.55)");
System.out.println("Press 15 for Apple: (Price $1.89)");
System.out.println("Press 16 for Orange: (Price $1.55)");
System.out.println("Press 17 to Restock: ");
System.out.println("Press 18 to Print Transaction Report:");
System.out.println("Press 19 to Quit: ");
System.out.print("Enter money to be added: $");
amountB = input.nextDouble();
machine.addMoneyB(amountB);
System.out.print("Enter your choice: ");
choice = input.nextInt();
if (choice == 1)
{
amountB = machine.vendA();
System.out.printf("Returned amount: $%.2f ", amountB);
management.IventoryA();
}
else if (choice == 2)
{
amountB = machine.vendB();
System.out.printf("Returned amount: $%.2f ", amountB);
management.IventoryB();
}
else if (choice == 3)
{
amountB = machine.vendC();
System.out.printf("Returned amount: $%.2f ", amountB);
management.IventoryC();
}
else if (choice == 4)
{
amountB= machine.vendD();
System.out.printf("Returned amount: $%.2f ", amountB);
management.IventoryD();
}
else if (choice == 5)
{
amountB = machine.vendE();
System.out.printf("Returned amount: $%.2f ", amountB);
management.IventoryE();
}
else if (choice == 6)
{
amountB = machine.vendF();
System.out.printf("Returned amount: $%.2f ", amountB);
management.IventoryF();
}
else if (choice == 7)
{
amountB = machine.vendG();
System.out.printf("Returned amount: $%.2f ", amountB);
management.IventoryG();
}
else if (choice == 8)
{
amountB = machine.vendH();
System.out.printf("Returned amount: $%.2f ", amountB);
management.IventoryH();
}
else if (choice == 9)
{
amountB = machine.vendI();
System.out.printf("Returned amount: $%.2f ", amountB);
management.IventoryI();
}
else if (choice == 10)
{
amountB = machine.vendJ();
System.out.printf("Returned amount: $%.2f ", amountB);
management.IventoryJ();
}
else if (choice == 11)
{
amountB = machine.vendK();
System.out.printf("Returned amount: $%.2f ", amountB);
management.IventoryK();
}
else if (choice == 12)
{
amountB = machine.vendL();
System.out.printf("Returned amount: $%.2f ", amountB);
management.IventoryL();
}
else if (choice == 13)
{
amountB = machine.vendM();
System.out.printf("Returned amount: $%.2f ", amountB);
management.IventoryM();
}
else if (choice == 14)
{
amountB = machine.vendN();
System.out.printf("Returned amount: $%.2f ", amountB);
management.IventoryN();
}
else if (choice == 15)
{
amountB = machine.vendO();
System.out.printf("Returned amount: $%.2f ", amountB);
management.IventoryO();
}
else if (choice == 16)
{
amountB = machine.vendO();
System.out.printf("Returned amount: $%.2f ", amountB);
management.IventoryP();
}
else if (choice == 17)
{
management.restock();
}
else if (choice == 18)
{
System.out.println("Print Transaction Report:");
}
else if (choice == 19)
{
System.out.println("Thank you!");
}
}
while (choice != 19);
}
}
************************************************************************************************
public class InventoryManagement
{
private final int MAX_MMs = 2;
private final int MAX_POPCORN = 2;
private final int MAX_SNICKERS = 2;
private final int MAX_GUM = 2;
private final int MAX_CRACKERS = 2;
private final int MAX_CHIPS = 2;
private final int MAX_CORN = 2;
private final int MAX_SODA = 2;
private final int MAX_MILK = 2;
private final int MAX_JUICE = 2;
private final int MAX_WATER = 2;
private final int MAX_BARS = 2;
private final int MAX_DONUTS = 2;
private final int MAX_TUNA = 2;
private final int MAX_APPLE = 2;
private final int MAX_ORANGE = 2;
private int MMsCount;
private int PopcornCount;
private int SnickersCount;
private int GumCount;
private int CrackersCount;
private int ChipsCount;
private int CornCount;
private int SodaCount;
private int MilkCount;
private int JuiceCount;
private int WaterCount;
private int BarCount;
private int DonutsCount;
private int TunaCount;
private int AppleCount;
private int OrangeCount;
public double IventoryA()
{
if(MMsCount == 0)
{
System.out.println("Not enough stock is in the machine to get M&Ms.");
return 0;
}
MMsCount = MMsCount - 1;
return MMsCount;
}
public double IventoryB()
{
if(PopcornCount == 0)
{
System.out.println("Not enough stock is in the machine to get Popcorn.");
return 0;
}
PopcornCount = PopcornCount - 1;
return PopcornCount;
}
public double IventoryC()
{
if(SnickersCount == 0)
{
System.out.println("Not enough stock is in the machine to get Snickers.");
return 0;
}
SnickersCount = SnickersCount - 1;
return SnickersCount;
}
public double IventoryD()
{
if(GumCount == 0)
{
System.out.println("Not enough stock is in the machine to get Gum.");
return 0;
}
GumCount = GumCount - 1;
return GumCount;
}
public double IventoryE()
{
if(CrackersCount == 0)
{
System.out.println("Not enough stock is in the machine to get Crackers.");
return 0;
}
CrackersCount = CrackersCount - 1;
return CrackersCount;
}
public double IventoryF()
{
if(ChipsCount == 0)
{
System.out.println("Not enough stock is in the machine to get Chips.");
return 0;
}
ChipsCount = ChipsCount - 1;
return ChipsCount;
}
public double IventoryG()
{
if(CornCount == 0)
{
System.out.println("Not enough stock is in the machine to get Corn.");
return 0;
}
CornCount = CornCount - 1;
return CornCount;
}
public double IventoryH()
{
if(SodaCount == 0)
{
System.out.println("Not enough stock is in the machine to get Soda.");
return 0;
}
SodaCount = SodaCount -1;
return SodaCount;
}
public double IventoryI()
{
if(MilkCount == 0)
{
System.out.println("Not enough stock is in the machine to get Milk.");
return 0;
}
MilkCount = MilkCount - 1;
return MilkCount;
}
public double IventoryJ()
{
if(JuiceCount == 0)
{
System.out.println("Not enough stock is in the machine to get Juice.");
return 0;
}
JuiceCount = JuiceCount - 1;
return JuiceCount;
}
public double IventoryK()
{
if(WaterCount == 0)
{
System.out.println("Not enough stock is in the machine to get Water.");
return 0;
}
WaterCount = WaterCount - 1;
return WaterCount;
}
public double IventoryL()
{
if(BarCount == 0)
{
System.out.println("Not enough stock is in the machine to get Bar.");
return 0;
}
BarCount = BarCount - 1;
return BarCount;
}
public double IventoryM()
{
if(DonutsCount == 0)
{
System.out.println("Not enough stock is in the machine to get Donut.");
return 0;
}
DonutsCount = DonutsCount - 1;
return DonutsCount;
}
public double IventoryN()
{
if(TunaCount == 0)
{
System.out.println("Not enough stock is in the machine to get Tuna.");
return 0;
}
TunaCount = TunaCount - 1;
return TunaCount;
}
public double IventoryO()
{
if(AppleCount == 0)
{
System.out.println("Not enough stock is in the machine to get Apple.");
return 0;
}
AppleCount = AppleCount - 1;
return AppleCount;
}
public double IventoryP()
{
if(OrangeCount == 0)
{
System.out.println("Not enough stock is in the machine to get Orange.");
return 0;
}
OrangeCount = OrangeCount - 1;
return OrangeCount;
}
public void restock()
{
MMsCount = MAX_MMs;
PopcornCount = MAX_POPCORN;
SnickersCount = MAX_SNICKERS;
GumCount = MAX_GUM;
CrackersCount = MAX_CRACKERS;
ChipsCount = MAX_CHIPS;
CornCount = MAX_CORN;
SodaCount = MAX_SODA;
MilkCount = MAX_MILK;
JuiceCount = MAX_JUICE;
WaterCount = MAX_WATER;
BarCount = MAX_BARS;
DonutsCount = MAX_DONUTS;
TunaCount = MAX_TUNA;
AppleCount = MAX_APPLE;
OrangeCount = MAX_ORANGE;
}
}
*****************************************************************************************
public class VendingMachine1
{
private final double MMs_COST = 1.00;
private final double POPCORN_COST = 3.67;
private final double SNICKERS_COST = 4.00;
private final double GUM_COST = 0.99;
private final double CRACKERS_COST = 1.89;
private final double CHIPS_COST = 0.99;
private final double CORN_COST = 0.88;
private final double MILK_COST = 2.30;
private final double SODA_COST = 1.29;
private final double JUICE_COST = 3.00;
private final double WATER_COST = 2.00;
private final double BARS_COST = 4.00;
private final double DONUTS_COST = 3.35;
private final double TUNA_COST = 2.25;
private final double APPLE_COST = 1.89;
private final double ORANGE_COST = 1.55;
private double moneyCreditB;
public void addMoneyB(double amountB)
{
moneyCreditB = amountB;
}
public double vendA()
{if(moneyCreditB < MMs_COST)
{
System.out.println("Not enough money is in the machine to get M&M'S.");
return 0;
}
double changeB = moneyCreditB - MMs_COST;
return changeB;
}
public double vendB()
{if(moneyCreditB < POPCORN_COST)
{
System.out.println("Not enough money is in the machine to get PopCorn.");
return 0;
}
double changeB = moneyCreditB - POPCORN_COST;
return changeB;
}
public double vendC()
{if(moneyCreditB < SNICKERS_COST)
{
System.out.println("Not enough money is in the machine to get Snickers.");
return 0;
}
double changeB = moneyCreditB -SNICKERS_COST ;
return changeB;
}
public double vendD()
{if(moneyCreditB < GUM_COST)
{
System.out.println("Not enough money is in the machine to get Gum.");
return 0;
}
double changeB = moneyCreditB - GUM_COST;
return changeB;
}
public double vendE()
{if(moneyCreditB < CRACKERS_COST)
{
System.out.println("Not enough money is in the machine to get Crackers.");
return 0;
}
double changeB = moneyCreditB - CRACKERS_COST;
return changeB;
}
public double vendF()
{if(moneyCreditB < CHIPS_COST)
{
System.out.println("Not enough money is in the machine to get Chips.");
return 0;
}
double changeB = moneyCreditB - CHIPS_COST ;
return changeB;
}
public double vendG()
{if(moneyCreditB < CORN_COST)
{
System.out.println("Not enough money is in the machine to get Corn.");
return 0;
}
double changeB = moneyCreditB - CORN_COST ;
return changeB;
}
public double vendH()
{if(moneyCreditB < SODA_COST)
{
System.out.println("Not enough money is in the machine to get Soda.");
return 0;
}
double changeB = moneyCreditB - SODA_COST ;
return changeB;
}
public double vendI()
{if(moneyCreditB < MILK_COST)
{
System.out.println("Not enough money is in the machine to get Milk.");
return 0;
}
double changeB = moneyCreditB - MILK_COST;
return changeB;
}
public double vendJ()
{if(moneyCreditB < JUICE_COST)
{
System.out.println("Not enough money is in the machine to get Juice.");
return 0;
}
double changeB = moneyCreditB - JUICE_COST ;
return changeB;
}
public double vendK()
{if(moneyCreditB < WATER_COST)
{
System.out.println("Not enough money is in the machine to get Water.");
return 0;
}
double changeB = moneyCreditB - WATER_COST;
return changeB;
}
public double vendL()
{if(moneyCreditB < BARS_COST)
{
System.out.println("Not enough money is in the machine to get Bars.");
return 0;
}
double changeB = moneyCreditB - BARS_COST;
return changeB;
}
public double vendM()
{if(moneyCreditB < DONUTS_COST)
{
System.out.println("Not enough money is in the machine to get Donuts.");
return 0;
}
double changeB = moneyCreditB - DONUTS_COST;
return changeB;
}
public double vendN()
{if(moneyCreditB < TUNA_COST)
{
System.out.println("Not enough money is in the machine to get Donuts.");
return 0;
}
double changeB = moneyCreditB - TUNA_COST;
return changeB;
}
public double vendO()
{if(moneyCreditB < APPLE_COST)
{
System.out.println("Not enough money is in the machine to get Apple.");
return 0;
}
double changeB = moneyCreditB - APPLE_COST;
return changeB;
}
public double vendP()
{if(moneyCreditB < ORANGE_COST)
{
System.out.println("Not enough money is in the machine to get Orange.");
return 0;
}
double changeB = moneyCreditB - ORANGE_COST;
return changeB;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started