Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is java InelliJ. I was trying to make this programm. The idea is to let the user enter number of cups he/she wants from
This is java InelliJ. I was trying to make this programm. The idea is to let the user enter number of cups he/she wants from the array and then I give the price.I have two Arrays.
public static String [] drinkable_items = {"Cofee", "Tea", "Cappuccino","Chocolate" }; public static double price [] = {3.75, 1.25, 2.25, 3.00};
I want to let the user input forinstance, Tea 3, that wil be 3* 1.25 = 3.75. And if you can assist me if the user wants more items such as 6 cups of cofee and 7 cups of chocolates. Then I will display the total price.
Here is the starting point or you can leave and start over.
package Mohamed.company; import java.util.ArrayList; import java.util.Scanner; /** * Created by mash4 on 1/26/2017. */ public class Repitation { //Reading from the scanner static Scanner numScanner = new Scanner(System.in); public static String [] drinkable_items = {"Cofee", "Tea", "Cappuccino","Chocolate" }; public static double price [] = {3.75, 1.25, 2.25, 3.00}; public static ArrayList allitems = new ArrayList<>(); static double total = 0; public static void main(String[] args) { welcomeCustomer(); collectItem(); } private static void collectItem() { String user_input = ""; System.out.println("Please palce you order, 'e.g., 3 cofee', Or Q to quit :"); user_input = numScanner.nextLine(); System.out.println("How many cups : "); double cups = numScanner.nextDouble(); //double sellsprice = cups * price[]; while(!getOrderline(user_input)) { user_input = numScanner.nextLine(); } } private static boolean getOrderline(String user_input) { if(user_input.equalsIgnoreCase("q")) { System.out.println("Thanks for using this progrmm !!!"); } return false; } private static void welcomeCustomer() { System.out.println("Welcome to Mohamed's Shop!!!"); System.out.println(String.format("%-15s %-20s", "Drinking items" , "Price")); for (int i = 0; i < drinkable_items.length; i++) { System.out.println(String.format("%-15s %-19.2f", drinkable_items[i] , price[i])); } } }
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