Question

Prompt 1 Write a program for a simple vending machine. The vending machine contains the following set of drinks (indexed from

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.

package HomeworkLib1;
import java.util.Scanner;
public class VendingMachine {
        public static void main(String[] args) {
                Scanner scan = new Scanner(System.in);
                System.out.println("1: Coca-Cola");             //Different drinks available in the machine
                System.out.println("2: Sprite");
                System.out.println("3: Snapple");
                System.out.println("4: Dr. Pepper");
                System.out.println("5: Water");
                
                byte choice;
                System.out.println("Enter your choice: ");
                choice = scan.nextByte();
                switch (choice) {
                case 1:
                        System.out.println("You have chosen Coca-Cola.");
                        break;
                case 2:
                        System.out.println("You have chosen Sprite.");
                        break;
                case 3:
                        System.out.println("You have chosen Snapple.");
                        break;
                case 4:
                        System.out.println("You have chosen Dr. Pepper.");
                        break;
                case 5:
                        System.out.println("You have chosen Water.");
                        break;
                default:
                        System.out.println("Please enter a valid choice.");
                        break;
                }
        }
}

lavadex: R. Declaration-Console X Employejava Lawyerjva Programmerjava SeniorProgrammerjavaD 1 package HomeworkLib1; 2 import java.

package HomeworkLib1;
import java.util.Scanner;
public class IntToCheck {
        public static void main(String[] args) {
                int intToCheck;
                System.out.println("Enter number: ");
                Scanner scan = new Scanner(System.in);
                intToCheck = scan.nextInt();
                if(intToCheck%2==0)
                        System.out.println("Even");
                else
                        System.out.println("Odd");
                if(intToCheck<0)
                        System.out.println("Negative");
                else if (intToCheck>0)
                        System.out.println("Positive");
                else
                        System.out.println("Neigher positive, nor negative");
        }
}

Employeejava D Lawyer.javaEmployeeMai. 1 package HomeworkLib1; 2 import java.util.Scanner 3 public class IntToCheck { 4 public stat

Add a comment
Know the answer?
Add Answer to:
Prompt 1 Write a program for a simple vending machine. The vending machine contains the following...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Drink Machine Simulator C++

    Drink Machine SimulatorThe purpose of this exercise is to give you practice with abstract data types, namely structures and arrays of structures.Write a program that simulates a softdrink machine. The program should use a structure that stores the following data:Drink NameDrink CostNumber of Drinks in MachineThe program should create an array of five structures. The elements should be initialized with the following data:Drink Name Cost Number in MachineCoca-Cola .75 20Root Beer .75 20Sprite .75 20Spring Water .80 20Apple Juice .80...

  • 1. Create a new multi-class Java program which implements a vending machine simulator which contains the...

    1. Create a new multi-class Java program which implements a vending machine simulator which contains the following functionality: A) At program startup, the vending machine is loaded with a variety of products in a variety of packaging for example soda/tonic/Coke in bottles, peanuts in bags, juice in cartons, etc. Also included is the cost of each item. The program should be designed to easily load a different set of products easily (for example, from a file). Also at program startup,...

  • Vending Machine (Python 3) Thinking Outside the box Write a program that asks the user to...

    Vending Machine (Python 3) Thinking Outside the box Write a program that asks the user to enter a bill value (1 = $1 bill, 5 = $5 bill, etc.) and the price of an item they want to buy in pennies and calculate their change amount in dollars, quarters, dimes, nickels, and pennies. Your code should start like this: ## # This program simulates a vending machine that gives change # Define constants PENNIES PER DOLLAR = 100 PENNIES PER...

  • q13 c++ if answering please do not write code in paragrapth form. 13. Drink Machine Simulator...

    q13 c++ if answering please do not write code in paragrapth form. 13. Drink Machine Simulator Write a program that simulates a soft drink machine. The program should use a structure that stores the following data: Drink Name Drink Cost Number of Drinks in Machine The program should create an array of five structures. The elements should be initialized with the following data: Drink Name Cost Number in Machine Cola .75 20 Root Beer .75 20 Lemon-Lime .75 20 Grape...

  • I have to write a program in java which uses while loops. 1.prompt the user to...

    I have to write a program in java which uses while loops. 1.prompt the user to input two intergers: firstnum ans second numnumber. (first number must be smaller that the second number). 2. Output all the even numbers between first number and second number inclusive. 3. Output the sum of all the even number between first number and second number inclusive. 4 Output all the odd numbers between first number and second number inclusive. 5. Output the sum of all...

  • To be turned in You will write a program that will do the following: Prompt the...

    To be turned in You will write a program that will do the following: Prompt the user to enter any character form the keyboard. You will compute some statistic concerning the type of characters entered. You will keep reading characters until a 'Q' is entered. The 'Q' should not be included when computing the statistics properties of the input. Example input: $8mJ0*5/I+Nx1@3qc2XQ We are interested in determining the following statistics: The number of alphabets The number of uppercase letters The...

  • 1. Write a program that takes a number as input and check whether the number is...

    1. Write a program that takes a number as input and check whether the number is positive, negative or zero. 2. Write a C++ program that prompts the user to enter a number and checks whether the entered number is even or odd. 3.  Using switch-case statement write a C++ program that prompts the user to enter 1, 2 or 3 and display "Red" if selection is 1, "Yellow" if selection is 2, or "Green" if selection is 3. 4. Write...

  • Write a Java program to meet the following requirements: 1. Prompt the user to enter three...

    Write a Java program to meet the following requirements: 1. Prompt the user to enter three strings by using nextLine(). Space can be part of the string). ( Note: your program requires using loop: for-loop, while-loop or do-while-loop to get the input String ) 2. Write a method with an input variable (string type).The method should return the number of lowercase letters of the input variable. 3. Get the number of the lowercase letters for each user input string by...

  • Write a program in C++ that simulates a soft drink machine. The program will need several...

    Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem, DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class. DrinkItem class The DrinkItem class will contains the following private data members: name: Drink name (type of drink – read in from a file). Type...

  • C++ HW Question Your program will simulate a simple change maker for a vending machine. It...

    C++ HW Question Your program will simulate a simple change maker for a vending machine. It will start with a stock of coins and dollars. It will then repeatedly request the price for an item to be purchased or to quit. If given a price, it will accept nickels, dimes, quarters, one-dollar and five-dollar bills—deposited one at a time—in payment. When the user has deposited enough to cover the cost of the item, the program will calculate the coins to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT