Write a program for a vending machine. The vending machine when powered on will initially have zero drinks stored in its hoppers. There are three kinds of drinks in the machine.
The machine has two modes of operation: Admin mode and user mode.
When powered it will display a log in for the admin, the log in screen will ask for a password which is admin123. Should that entry be wrong, the screen will prompt for the password again. After three tries, the machine will no longer prompt for the password but will terminate the program and exit.
If the password is correct, the machine will display the current inventory with a menu to choose drink types for replenishing. You should have a maximum of 5 drinks per category (remember you have only three types). The replenishing level doesn’t have to max out but an error will occur if the admin tries to enter a number higher than present capacity. The admin should also be able to set the price for the drinks. They should all have the same price regardless of category. The default price is $1.00.
Once the machine is replenished the admin can choose to exit admin mode and only then would user mode start. User mode should display a choice of beverages and an option to purchase. An admin option should be present so that the user mode can be interrupted.
Only the admin can terminate the program or when there are no more drinks in the machine.
At any given time, the admin can log in and check how much money is collected and what the status of the inventory is.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.util.Scanner;

public class VendingMachine {

public static String adminPassword = "admin123";
public static String[] type = {"Coke", "Sprite", "Dr. Pepper"};
public static int maxSodas = 5;

public static void main(String[] args)
Scanner input = new Scanner(;
int count = 0;
int[] inv = {0, 0, 0};
double price = 1.0;
double collected = 0.0;
String pass;
while(count != 3)
System.out.print("Welcome to the vending machine admin mode, please enter the password: ");
pass =;
if(pass.compareTo(adminPassword) == 0)
System.out.println("Incorrect password, try again");
if(count == 3)
System.out.println("Too many attempts, closing program");

$8.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats