Java Code
Problem 02: Wi-Fi Diagnostic Tree
The figure below shows a simplified flowchart for troubleshooting a bad Wi-Fi connection. Use the flowchart to create a program that leads a person through the steps of fixing a bad Wi-Fi connection.
One way to code this troubleshooting flowchart is by using if-else statements. However, we can avoid much code repetition and can organize our code better if we use methods. The CMPE160_HW2_Part2 class contains a starter code that you can add to.
package CMPE160_HW2;
import java.util.Scanner;
public class CMPE160_HW2_Part2 {
static Scanner sc = new Scanner (System.in);
public static void main(String[] args) {
System.out.println("Part2: This program will troublehsoot your Wifi connection.\n");
System.out.println("Reboot the computer and try to connect.");
//complete this main method to print the appropriate suggestion and check if the problem is solved after each suggestion.
System.out.println("Get a new router.");
}
//this method is executed when the problem is solved. Do not modify this method. Use this method is your solution.
public static void problemSolved() {
System.out.println("Glad to be of help. \nThe program will terminate now.");
sc.close();
System.exit(0);
}
//this method checks if the problem has been solved.
public static void check() {
System.out.print("Did that fix the problem? ");
String answer = sc.next();
//complete this method......
}
}
Do not change or delete any existing code. You only need to add code to complete the methods where indicated, add the user prompts and solution suggestions, and use the appropriate method calls.
Here is an example of the program’s output:
Reboot the computer and try to connect. Did that fix the problem? (y/n): n Reboot the router and try to connect. Did that fix the problem? (y/n): n Make sure the cables between the router and modem are plugged in firmly. Did that fix the problem? (y/n): y Glad to be of help. The program will terminate now. Reboot the computer and try to connect. Did that fix the problem? (y/n): n Reboot the router and try to connect. Did that fix the problem? (y/n): n Make sure the cables between the router and modem are plugged in firmly. Did that fix the problem? (y/n): n Move the router to a new location and try to connect. Did that fix the problem? (y/n): n Get a new router. |
【General guidance】The answer provided below has been developed in a clear step by step manner.Step1/4Question can be solved in below image In this Java code,We are using a nested if-else ladder to make the appropriate decision depending upon the answer entered by the user. if the user enters the response as yes, then we are immediately terminating the program, or else we are prompting the user to answer the questions as designed. Then finally terminating with printing some message, once the user enters no for all the 4 questions.(I believe that I choose the simplest way of doing this and making it more understandable. If you still have any query, Feel free to drop me a comment)Code:import java.util.Scanner;public class DiagnosticProgram{public static void main(String[] args){Scanner src=new Scanner(System.in);String userAnswer;//Prompting the user to enter the response ?m.out.println("Reboot the computer and(०.) , connect");Sictem nut nrint("Did that fix the nroblem? ").Explanation:Please refer to solution in this step.Step2/4Question can be solved in below image userAnswer=src.next();//If the answer is yes, then the program ends if(userAnswer.equals("yes")){System.exit(0);}//else ask another questionelse if(userAnswer.equals("no")){//Again Prompting the user to enter theresponseSystem.out.println("Reboot the router and try to connect.");System.out.print("Did that fix the problem? ");userAnswer=src.next();if(userAnswer.equals("yes"))System.exit(0);//else ask another questionelse if(userAnswer.equals("no")){//Again Prompting the user to enter theresponseSystem.out.println("Make sure the cables between the router & modem are plugged in firmly.");System.out.print("Did that fix the problem? ");userAnswer=src.next();IIf the answer is yes, then the program ends(.😇 rAnswer.equals("yes"))Dystem.exit(0);Explanation:Please refer to solution in this step.Step3/4Question can be solved in below image //else ask another questionelse if(userAnswer.equals("no")){//Again Prompting the user to enter theresponseSystem.out.println("Move the router ... See the full answer