cant pass a course maybe bug? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

cant pass a course maybe bug?

You are making an automated response program for a store. The bot should take a number from the user as input and reply with an automated message. There are currently 3 responses, that you need to a handle: User message: "1", Reply: "Order confirmed" User message: "2", Reply: "info@sololearn.com" For any other number, the reply should be: "Try again". The given code calls a method called bot(). Define the method, which should take an integer input from the user, and handle the above mentioned cases, by outputting the corresponding reply. Do not change the method call in main(). my code is import java.util.Scanner; public class Program { public static void main(String[] args) { bot(); } public static void bot(){ Scanner sc = new Scanner(System.in); int num = sc.nextInt(); switch(num){ case 1: System.out.println("Order Confirmed"); break; case 2: System.out.println("info@sololearn.com"); break; default: System.out.println("Try again"); } } } case 4 is locked and the solution is kinda the same... any explaination?

7th Mar 2023, 7:59 PM
Dimitrios Mylonas
Dimitrios Mylonas - avatar
4 Answers
+ 9
You spell "confirmed" with a capital C, is that correct?
7th Mar 2023, 8:26 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 5
damn that was the problem. thanks a lot.
7th Mar 2023, 10:05 PM
Dimitrios Mylonas
Dimitrios Mylonas - avatar
+ 3
You're welcome :)
8th Mar 2023, 4:50 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 1
import java.util.Scanner; public class Program { //your code goes here /* User message: "1", Reply: "Order confirmed" User message: "2", Reply: "info@sololearn.com" For any other number, the reply should be: "Try again". */ public static void bot() { Scanner scanner = new Scanner (System.in); int userInput = scanner.nextInt(); if (userInput==1){ System.out.println("Order confirmed"); }else if(userInput==2){ System.out.println("info@sololearn.com"); }else{ System.out.println("Try again"); } scanner.close(); } public static void main(String[] args) { bot(); } }
28th Oct 2023, 9:21 AM
dennis rasugu
dennis rasugu - avatar