Write a java program that simulates a vending machine. Products can be purchased by inserting coins with a value at least equal to the cost of the product. A user select a product from a list of available products, add coins, and either gets the products or gets the coins returned. The coins are returned if insufficient money was supplied or if the product it's sold out. The machine does not give change if too much money was added. Products can be restocked and money remove by an operator. Your solution should include a class VendingMachine that is not coupled with the Scanner or PrintStream classes. PS: For the VendingMachine.java, using public ArrayList getProductList(){ ArrayList list = new ArrayList<>();} instead of public ArrayList getProductList(){ ArrayList list = new ArrayList();} Runtime output S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit a Description: Cookie Price: 1.50 Quantity: 3 S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit A Description: Candy Price: 1.25 Quantity: 2 S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit S Cookie @ $1.50 Candy @ $1.25 S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit b A) Cookie @ $1.50 B) Candy @ $1.25 a Insufficient money S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit i A) nickel @ 0.05 B) dime @ 0.1 C) quarter @ 0.25 D) dollar @ 1.0 d S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit i A) nickel @ 0.05 B) dime @ 0.1 C) quarter @ 0.25 D) dollar @ 1.0 d S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit b A) Cookie @ $1.500 B) Candy @ $1.25 a Purchased: Cookie @ $1.50 Your change: $0.50 S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit s Cookie @ $1.50 Candy @ $1.25 S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit b A) Cookie @ $1.50 B) Candy @ $1.25 b Insufficient money S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit i A) nickel @ 0.05 B) dime @ 0.1 C) quarter @ 0.25 D) dollar @ 1.0 d S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit i A) nickel @ 0.05 B) dime @ 0.1 C) quarter @ 0.25 D) dollar @ 1.0 c S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit b A) Cookie @ $1.50 B) Candy @ $1.25 b Purchased: Candy @ $1.25 S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit r Removed: $2.75
Write a java program that simulates a vending machine. Products can be purchased by inserting coins with a value at least equal to the cost of the product. A user select a product from a list of available products, add coins, and either gets the products or gets the coins returned. The coins are returned if insufficient money was supplied or if the product it's sold out. The machine does not give change if too much money was added. Products can be restocked and money remove by an operator. Your solution should include a class VendingMachine that is not coupled with the Scanner or PrintStream classes.
PS: For the VendingMachine.java, using public ArrayList<Product> getProductList(){ ArrayList<Product> list = new ArrayList<>();}
instead of public ArrayList<String> getProductList(){ ArrayList<String> list = new ArrayList<String>();}
Runtime output
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
a
Description:
Cookie
Price:
1.50
Quantity:
3
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
A
Description:
Candy
Price:
1.25
Quantity:
2
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
S
Cookie @ $1.50
Candy @ $1.25
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
b
A) Cookie @ $1.50
B) Candy @ $1.25
a
Insufficient money
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
i
A) nickel @ 0.05
B) dime @ 0.1
C) quarter @ 0.25
D) dollar @ 1.0
d
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
i
A) nickel @ 0.05
B) dime @ 0.1
C) quarter @ 0.25
D) dollar @ 1.0
d
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
b
A) Cookie @ $1.500
B) Candy @ $1.25
a
Purchased: Cookie @ $1.50
Your change: $0.50
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
s
Cookie @ $1.50
Candy @ $1.25
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
b
- A) Cookie @ $1.50
B) Candy @ $1.25
b
Insufficient money
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
i
- A) nickel @ 0.05
B) dime @ 0.1
C) quarter @ 0.25
D) dollar @ 1.0
d
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
i
A) nickel @ 0.05
B) dime @ 0.1
C) quarter @ 0.25
D) dollar @ 1.0
c
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
b
A) Cookie @ $1.50
B) Candy @ $1.25
b
Purchased: Candy @ $1.25
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
r
Removed: $2.75
Trending now
This is a popular solution!
Step by step
Solved in 2 steps