Question: Java Programmers Hello, can anyone fix my assignment my professor said Before assign iD, must check if the station is available. Can you spot the

Java Programmers

Hello, can anyone fix my assignment my professor said "Before assign iD, must check if the station is available." Can you spot the code that I wrote and understand what he meant by that? I'm assuming he wants my program to be safe where if I already entered an ID at the same position, then it will say "taken choose another one"

Here's my code, I'm making a computerLab it is all done, but I need to make a method to check if the station is available. Makes sense? Help me spot the error

package complab;

import java.util.Scanner;

public class CompLab { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); DisplayMenu(scnr); } public static void DisplayStation(int [][] displaySyntax) { System.out.println("LAB STATUS"); System.out.println("Lab # Computer Stations"); for(int i = 0; i < displaySyntax.length; i++) { System.out.print((i+1)+" "); for(int j = 0; j < displaySyntax[i].length; j++) { if(displaySyntax[i][j] != 0 && displaySyntax[i][j] != -1) { System.out.print((j+1) + ":" + displaySyntax[i][j] + " "); } else { System.out.print((j+1) + ":Empty "); } } System.out.println(); } System.out.println(); } public static void DisplayMenu(Scanner userInput) { int userChoice; int idNumber; int labNumber = -1; int stationNumber = -1; boolean checkUserID; int [][] computerStations = { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }; DisplayStation(computerStations); while(true) { checkUserID = false; System.out.println(); System.out.println("MAIN MENU"); System.out.println("0) Quit"); System.out.println("1) Simulate Login"); System.out.println("2) Simulate Logoff"); System.out.println("3) Search"); userChoice = userInput.nextInt(); switch(userChoice) { case 0: System.exit(0); case 1: System.out.println("Enter the 5 digit ID number of the user logging in:"); idNumber = userInput.nextInt(); System.out.println("Enter the lab number the user is logging in from (1-4):"); labNumber = userInput.nextInt(); System.out.println("Enter computer station number the user is logging in to (1-6): "); stationNumber = userInput.nextInt(); computerStations[labNumber - 1][stationNumber - 1] = idNumber; DisplayStation(computerStations); break; case 2: System.out.println("Enter the 5 digit ID number of the user to find:"); idNumber = userInput.nextInt(); for(int i = 0; i < computerStations.length; i++) { for(int j = 0; j < computerStations[i].length; j++) { if(computerStations[i][j] == idNumber) { computerStations[i][j] = 0; } } } System.out.println("User " + idNumber + " is logged off"); DisplayStation(computerStations); break; case 3: System.out.println("Enter the 5 digit ID Number of the user to search"); idNumber = userInput.nextInt(); for (int i = 0; i < computerStations.length; i++) { for (int j = 0; j < computerStations[i].length; j++) { if (computerStations[i][j] == idNumber) { labNumber = i + 1; stationNumber = j + 1; checkUserID = true; } } } if(checkUserID == false) { System.out.println("None: The 5 Digit ID you entered does not exist at all"); break; } else { System.out.println("User:" + idNumber + " is logged in lab " + labNumber + " on station " + stationNumber); } break; default: System.out.println("Please enter the number 1 - 3"); } } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!