0

do while problem got stuck..pls help

You are creating an automated phone system for bank clients. Number selections should activate the actions noted below as follows: 1 => Language selection 2 => Customer support 3 => Check account balance 4 => Check loan balance 0 => Exit You can use the first 4 commands in a random sequence without interrupting the phone call - only the number 0 does. Write a program that will continuously take a number as input and output the corresponding message, until the client enters 0.

1st Mar 2021, 7:13 PM
lordzrealm
lordzrealm - avatar
11 Respostas
+ 1
import java.util.Scanner; public class soloLearn { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int number = scanner.nextInt(); do { // take input and output corresponding message /* * 1 => Language selection 2 => Customer support 3 => Check the balance 4 => * Check loan balance 0 => Exit */ switch (number) { case 1: System.out.println("Language selection"); break; case 2: System.out.println("Customer support"); break; case 3: System.out.println("Check the balance"); break; case 4: System.out.println("Check loan balance"); break; } break; } while (number != 0); } } ---NOT WORKING----- Sample Input 1 4 3 0 Sample Output Language selection Check loan balance Check the balance Exit In case the user enters an incorrect number, the program shouldn't output anything. Use Scanner in loop in order to take inputs continuously.
1st Mar 2021, 9:53 PM
lordzrealm
lordzrealm - avatar
0
when asking for help with a program that is not functioning, it is semi-mandatory to post your attempt via code playground, and the error message you were getting.
1st Mar 2021, 7:24 PM
Wilbur Jaywright
Wilbur Jaywright - avatar
0
you have a break statement in each switch case, so the loop cannot possibly continue as instructed. Also, please use code playground to share code.
1st Mar 2021, 10:02 PM
Wilbur Jaywright
Wilbur Jaywright - avatar
0
https://code.sololearn.com/cA25A11A21A1/#java i change to if ,else if,,,still can't run properly
1st Mar 2021, 10:43 PM
lordzrealm
lordzrealm - avatar
0
what is the error message?
1st Mar 2021, 10:45 PM
Wilbur Jaywright
Wilbur Jaywright - avatar
0
/usercode/public class Program.java:26: error: while expected } ^ /usercode/public class Program.java:27: error: illegal start of expression } ^ /usercode/public class Program.java:27: error: reached end of file while parsing } ^ 3 errors I put 1,2 & 4 as input
2nd Mar 2021, 12:35 AM
lordzrealm
lordzrealm - avatar
0
I discovered you were missing an ending bracket, but then I encountered another problem with the scanner class.
2nd Mar 2021, 2:21 AM
Wilbur Jaywright
Wilbur Jaywright - avatar
0
Also, be sure to end the input with a zero, so the code will not loop forever
2nd Mar 2021, 2:22 AM
Wilbur Jaywright
Wilbur Jaywright - avatar
0
thank you so much for the help..
2nd Mar 2021, 5:06 AM
lordzrealm
lordzrealm - avatar
0
To implement automated business phone system that processes number selections, use a loop to continuously take user input and output the corresponding action. Exit the loop when the user enters 0, which terminates the call.https://quantacom.com.au/
5th Aug 2024, 8:27 AM
quantacom
quantacom - avatar