0

How do i do this in java

Supermarket item finder 1. Take input from user and based on the input, you should display user which aisle has the item 2. For example: user enter milk, you program should say aisle 8. If the item is not found, 3. display a message saying "Out of stock "Please create program for below requirement Milk = Aisle Eight Eggs = Aisle Eight French Fries = Aisle seven Candy = Aisle Three Frozen Pizza = Aisle seven Donuts = Aisle Eight Diapers = Aisle One Apple = Aisle two Orange = Aisle two

7th Dec 2018, 8:34 PM
Mamun Rahman
Mamun Rahman - avatar
19 Respuestas
+ 1
Mamun Rahman as you continue to practice more Java, you will use Scanner class often and become familiar with. Code provided does cover probably more then you need at the moment, so try to figure what you can rid of, break the code, play with it and don't forget to enjoy. :-)
9th Dec 2018, 6:32 PM
vlada
+ 16
● For comparing content of Strings U can make use .equals() method : Example : String a="a", b="a"; System.out.println(a.equals(b)); //true ● make use of if() & else if() conditions & at last an else() condition for "Out Of Stock"
7th Dec 2018, 9:33 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 6
You should use Scanner to take input. Remember to import it from util library. Then, check the user input on all conditions using if and else statements. That can be simple algorithm. Give it a try by yourself.
7th Dec 2018, 9:09 PM
Arushi Singhania
Arushi Singhania - avatar
+ 2
The Question is: did you tried to find an own Solution for this Problem? It is always better to write a Code by yourself. If it won't work you can post it here and the Community will help you to fix it. But you should not wait that anyone here does the Job for you.
7th Dec 2018, 8:48 PM
Sebastian Keßler
Sebastian Keßler - avatar
+ 2
i’ve been thinking just trying to figure out where to start. i just started learning and finding it really challenging ..
7th Dec 2018, 8:50 PM
Mamun Rahman
Mamun Rahman - avatar
+ 2
im going to try and see how far i can do , will keep u guys updated. thanks all of you :)
7th Dec 2018, 10:24 PM
Mamun Rahman
Mamun Rahman - avatar
+ 1
Yes, it can be done very easy. As suggested use Scanner for input. Next, in my opinion, you should check for switch/case option for comparing and if you need all of this to be executed more than once, then put it all in while loop. So, you need only three main things to learn. Easy, right? Look forward to see your progress.
7th Dec 2018, 11:39 PM
vlada
+ 1
im still struggling on how to start with scanner :( how do i put the items under which aisle...
9th Dec 2018, 1:29 PM
Mamun Rahman
Mamun Rahman - avatar
+ 1
Ok, compare this with your code and try to find what's troubling you. Or ask what is unclear. https://code.sololearn.com/crtLJ16NDUco/?ref=app
9th Dec 2018, 3:11 PM
vlada
+ 1
i appreciate it im trying to understand the whole coding you did. i guess i still need to learn a lot about scanner
9th Dec 2018, 6:09 PM
Mamun Rahman
Mamun Rahman - avatar
+ 1
no intellij
10th Dec 2018, 12:43 AM
Mamun Rahman
Mamun Rahman - avatar
0
yes i am really excited since i started and putting a lot of time i guess im just a slow learner im taking a online course trying to learn as much as i can. i am going to play with your codes and see what i can fogure out :) you are a great help. in this app you can’t chat one to one right?
9th Dec 2018, 6:37 PM
Mamun Rahman
Mamun Rahman - avatar
0
Scanner in = new Scanner(System.in); System.out.println("Welcome to our supermarket"); in.nextLine(); String Item = "Milk"; switch ("itemLocated") {     case "Milk":     case "Eggs":     case "Donuts":         System.out.println("Aisle8");         break;     case "French fries":     case "Frozen pizza":         System.out.println("Aisle7");         break;     case "Candy":         System.out.println("Aisle3");         break;     case "Diapers":         System.out.println("Aisle1");         break;     case "Apple":     case "Orange":         System.out.println("Aisle2");         break;     default:         System.out.println("Out of stock"); }         System.out.println("Milk is located "); (what should i change in this to get it right)
9th Dec 2018, 11:56 PM
Mamun Rahman
Mamun Rahman - avatar
0
String item = in.nextLine(); //to save user input switch(item) // to examine condition I can see a great progress... Do you?
10th Dec 2018, 12:20 AM
vlada
0
when i print it out it comes ‘out of stock’ first and it prints ‘looking for milk’
10th Dec 2018, 12:28 AM
Mamun Rahman
Mamun Rahman - avatar
0
Scanner in = new Scanner(System.in); System.out.println("Welcome to our supermarket"); String item = in.nextLine(); in.close(); switch (item) { case "Milk": case "Eggs": case "Donuts": System.out.println("Aisle8"); break; case "French fries": case "Frozen pizza": System.out.println("Aisle7"); break; case "Candy": System.out.println("Aisle3"); break; case "Diapers": System.out.println("Aisle1"); break; case "Apple": case "Orange": System.out.println("Aisle2"); break; default: System.out.println("Out of stock"); break; } System.out.println(item + " is located "); Using Eclipse? Ok, txs. There is just minor corrections here compared to your code. Congrats!
10th Dec 2018, 12:42 AM
vlada
0
i did copy yours and when i ran it output: welcome to our supermarket out of stock is located
10th Dec 2018, 12:51 AM
Mamun Rahman
Mamun Rahman - avatar
0
it dosent say milk is in aisle 8 its hard :(
10th Dec 2018, 12:53 AM
Mamun Rahman
Mamun Rahman - avatar
0
Did you input some string? Milk with big M? Here is working code: https://code.sololearn.com/c81Cy8t5qRfN/?ref=app
10th Dec 2018, 12:57 AM
vlada