Question

Java Computer Labs Assignment! The code NEEDS to be commented properly! Every class file should have a header comment that includes your name and assignment number and briefly documents what the prog...

Java Computer Labs Assignment!

  • The code NEEDS to be commented properly!
  • Every class file should have a header comment that includes your name and assignment number and briefly documents what the program does!
  • If there are known deficiencies with your program such as known problems or incomplete features, these should be clearly listed in the header comment!
  • Every method should have a method header comment that documents what the method does, what its parameters are, and what it returns!

You run four computer labs. Each lab contains computer stations that are numbered as shown in the table below:-

Lab Number

Computer Station Numbers

1

1-5

2

1-6

3

1-4

4

1-3

Each user has a unique five-digit ID Number. Whenever a user logs on, the user's ID, Lab Number, and the computer station are transmitted to your station. For example, if user 49193 logs onto station 2 in Lab 3, your system receives (49193, 2, 3) as input data. Similarly, when a user logs off a station, your system receives the Lab Number and computer station number.

Write a computer program that could be used to track, by lab, which user is logged onto which computer. For example, if user 49193 is logged into station 2 in lab 3 and user 99577 is logged into station 1 of lab 4, then your system might display the following:-

Lab Number Computer Stations

1 1: empty 2: empty 3: empty 4: empty 5: empty

2   1: empty 2: empty 3: empty 4: empty 5: empty 6: empty

3   1: empty 2: 49193 3: empty 4: empty  

4   1: 99577 2: empty 3: empty

Task:-

1. Create a menu that allows the administrator to simulate the transmission of information by manually typing in the login or logoff data. Whenever someone logs in or out, the display table should be updated.

2. Write a search option so the administrator can type in a user Id and the system will output what Lab Number and station number the user is logged into, or "None" if the user Id is not logged into any computer station.

You should use a fixed array of length 4 for the labs. Each array entry points to a dynamic array that stores the user login information for each respective computer station.

Sample Output:- (User input is in bold and Italics)

LAB STATUS
Lab # Computer Stations
1 1: empty 2: empty 3: empty 4: empty 5: empty
2 1: empty 2: empty 3: empty 4: empty 5: empty 6: empty
3 1: empty 2: empty 3: empty 4: empty
4 1: empty 2: empty 3: empty

MAIN MENU
0) Quit
1) Simulate login
2) Simulate logoff
3) Search
1
Enter the 5 digit ID number of the user logging in:
12345
Enter the lab number the user is logging in from (1-4):
2
Enter computer station number the user is logging in to (1-6):
3

LAB STATUS
Lab # Computer Stations
1 1: empty 2: empty 3: empty 4: empty 5: empty
2 1: empty 2: empty 3: 12345 4: empty 5: empty 6: empty
3 1: empty 2: empty 3: empty 4: empty
4 1: empty 2: empty 3: empty

MAIN MENU
0) Quit
1) Simulate login
2) Simulate logoff
3) Search
2
Enter the 5 digit ID number of the user to find:
12345
User 12345 is logged off.

LAB STATUS
Lab # Computer Stations
1 1: empty 2: empty 3: empty 4: empty 5: empty
2 1: empty 2: empty 3: empty 4: empty 5: empty 6: empty
3 1: empty 2: empty 3: empty 4: empty
4 1: empty 2: empty 3: empty

MAIN MENU
0) Quit
1) Simulate login
2) Simulate logoff
3) Search

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// LabsSimulation.java

import java.util.Scanner;

public class LabsSimulation {

      // 2d array of ints for representing labs and stations

      static int[][] lab;

      // method to set up the lab array

      static void setup() {

            // initializing with 4 labs

            lab = new int[4][];

            // 5 stations for first lab

            lab[0] = new int[5];

            // 6 stations for second lab

            lab[1] = new int[6];

            // 4 stations for third lab

            lab[2] = new int[4];

            // 3 stations for fourth lab

            lab[3] = new int[3];

      }

      // method to simulate login of a user

      static void simulateLogin(int userId, int stationId, int labId) {

            // converting user id to string to check if it has 5 digits

            if ((userId + "").length() != 5) {

                  System.out.println("Invalid user id");

                  return;

            }

            // converting lab & station numbers to array indices

            labId--;

            stationId--;

            // validating lab

            if (labId >= 0 && labId < lab.length) {

                  // validating station

                  if (stationId >= 0 && stationId < lab[labId].length) {

                        // checking if the station is available

                        if (lab[labId][stationId] == 0) {

                              // assigning user id to current station

                              lab[labId][stationId] = userId;

                              System.out.println("User " + userId + " logged in.");

                              return;

                        } else {

                              // occupied by someone

                              System.out.println("Station is already occupied!");

                        }

                  } else {

                        // station id out of range

                        System.out.println("Invalid station id!");

                  }

            } else {

                  // lab id out of range

                  System.out.println("Invalid lab id!");

            }

      }

      // method to simulate log off using user id

      static void simulateLogoff(int userId) {

            // converting user id to string to check if it has 5 digits

            if ((userId + "").length() != 5) {

                  System.out.println("Invalid user id");

                  return;

            }

            // locating the station user logged in

            for (int i = 0; i < lab.length; i++) {

                  for (int j = 0; j < lab[i].length; j++) {

                        if (lab[i][j] == userId) {

                              // found, changing to 0 means the station is now free

                              lab[i][j] = 0;

                              System.out.println("User " + userId + " is logged off.");

                              return;

                        }

                  }

            }

            // not found

            System.out.println("Not found!");

      }

      // method to locate a user using id

      static void search(int userId) {

            // converting user id to string to check if it has 5 digits

            if ((userId + "").length() != 5) {

                  System.out.println("Invalid user id");

                  return;

            }

            for (int i = 0; i < lab.length; i++) {

                  for (int j = 0; j < lab[i].length; j++) {

                        if (lab[i][j] == userId) {

                              // found, displaying lab and station

                              System.out.println("User " + userId

                                           + " is currently logged in at lab " + (i + 1)

                                           + ", station " + (j + 1));

                              return;

                        }

                  }

            }

            // not found

            System.out.println("None");

      }

      // method to display the labs and stations

      static void display() {

            System.out.println("LAB STATUS");

            System.out.println("Lab # Computer Stations");

            for (int i = 0; i < lab.length; i++) {

                  System.out.print((i + 1) + "   ");

                  for (int j = 0; j < lab[i].length; j++) {

                        System.out.print((j + 1) + ": ");

                        if (lab[i][j] == 0) {

                              // if a value is 0, displaying empty

                              System.out.print("empty ");

                        } else {

                              // else, displaying user id

                              System.out.print(lab[i][j] + " ");

                        }

                  }

                  System.out.println();

            }

      }

      public static void main(String[] args) {

            //setting up labs

            setup();

           

            //scanner for input

            Scanner scanner = new Scanner(System.in);

            int ch = 0, id, lab_num, station_num;

            //looping until user choose to quit

            do {

                  //displaying labs

                  display();

                  //displaying menu

                  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");

                  //getting and handling choice

                  ch = scanner.nextInt();

                  switch (ch) {

                  case 1:

                        //login

                        System.out

                                    .println("Enter the 5 digit ID number of the user logging in:");

                        id = scanner.nextInt();

                        System.out

                                    .println("Enter the lab number the user is logging in from (1-4)");

                        lab_num = scanner.nextInt();

                        System.out

                                    .println("Enter the station number the user is logging in to (1-6)");

                        station_num = scanner.nextInt();

                        simulateLogin(id, station_num, lab_num);

                        break;

                  case 2:

                        //logoff

                        System.out

                                    .println("Enter the 5 digit ID number of the user to find:");

                        id = scanner.nextInt();

                        simulateLogoff(id);

                        break;

                  case 3:

                        //search

                        System.out

                                    .println("Enter the 5 digit ID number of the user to search:");

                        id = scanner.nextInt();

                        search(id);

                        break;

                  }

            } while (ch != 0);

      }

}

/*OUTPUT*/

LAB STATUS

Lab # Computer Stations

1   1: empty 2: empty 3: empty 4: empty 5: empty

2   1: empty 2: empty 3: empty 4: empty 5: empty 6: empty

3   1: empty 2: empty 3: empty 4: empty

4   1: empty 2: empty 3: empty

MAIN MENU

0) Quit

1) Simulate login

2) Simulate logoff

3) Search

1

Enter the 5 digit ID number of the user logging in:

12345

Enter the lab number the user is logging in from (1-4)

2

Enter the station number the user is logging in to (1-6)

5

User 12345 logged in.

LAB STATUS

Lab # Computer Stations

1   1: empty 2: empty 3: empty 4: empty 5: empty

2   1: empty 2: empty 3: empty 4: empty 5: 12345 6: empty

3   1: empty 2: empty 3: empty 4: empty

4   1: empty 2: empty 3: empty

MAIN MENU

0) Quit

1) Simulate login

2) Simulate logoff

3) Search

1

Enter the 5 digit ID number of the user logging in:

11223

Enter the lab number the user is logging in from (1-4)

3

Enter the station number the user is logging in to (1-6)

1

User 11223 logged in.

LAB STATUS

Lab # Computer Stations

1   1: empty 2: empty 3: empty 4: empty 5: empty

2   1: empty 2: empty 3: empty 4: empty 5: 12345 6: empty

3   1: 11223 2: empty 3: empty 4: empty

4   1: empty 2: empty 3: empty

MAIN MENU

0) Quit

1) Simulate login

2) Simulate logoff

3) Search

2

Enter the 5 digit ID number of the user to find:

12345

User 12345 is logged off.

LAB STATUS

Lab # Computer Stations

1   1: empty 2: empty 3: empty 4: empty 5: empty

2   1: empty 2: empty 3: empty 4: empty 5: empty 6: empty

3   1: 11223 2: empty 3: empty 4: empty

4   1: empty 2: empty 3: empty

MAIN MENU

0) Quit

1) Simulate login

2) Simulate logoff

3) Search

3

Enter the 5 digit ID number of the user to search:

11223

User 11223 is currently logged in at lab 3, station 1

LAB STATUS

Lab # Computer Stations

1   1: empty 2: empty 3: empty 4: empty 5: empty

2   1: empty 2: empty 3: empty 4: empty 5: empty 6: empty

3   1: 11223 2: empty 3: empty 4: empty

4   1: empty 2: empty 3: empty

MAIN MENU

0) Quit

1) Simulate login

2) Simulate logoff

3) Search

3

Enter the 5 digit ID number of the user to search:

34567

None

LAB STATUS

Lab # Computer Stations

1   1: empty 2: empty 3: empty 4: empty 5: empty

2   1: empty 2: empty 3: empty 4: empty 5: empty 6: empty

3   1: 11223 2: empty 3: empty 4: empty

4   1: empty 2: empty 3: empty

MAIN MENU

0) Quit

1) Simulate login

2) Simulate logoff

3) Search

0

Add a comment
Know the answer?
Add Answer to:
Java Computer Labs Assignment! The code NEEDS to be commented properly! Every class file should have a header comment that includes your name and assignment number and briefly documents what the prog...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA Programming Assignment: You run four computer labs. Each lab contains computer stations that are numbered...

    JAVA Programming Assignment: You run four computer labs. Each lab contains computer stations that are numbered as shown in the table below:- Lab Number   Computer Station Numbers 1   1-5 2   1-6 3   1-4 4   1-3 Each user has a unique five-digit ID Number. Whenever a user logs on, the user's ID, Lab Number, and the computer station are transmitted to your station. For example, if user 49193 logs onto station 2 in Lab 3, your system receives (49193, 2, 3)...

  • C++ program that could be used to track, by lab, who is logged into which computer

    C++ program that could be used to track, by lab, who is logged into which computer 1. |15 points| Suppose you run four computer labs. Each lab contains computer stations that are numbered as shown in the table below Lab Number |Computer Station Numbers 1-5 2 1-4 1-3 Each user has a unique five-digit ID number. Whenever a user logs on, the user's ID, lab number, and the computer station number are transmitted to your system. For instance, if user...

  • Write the following program in C++ You run four computer labs, Each lab contains computer stations...

    Write the following program in C++ You run four computer labs, Each lab contains computer stations that are numbered as shown in the table below: Lab Number Computer Station Numbers 1 1 - 5 2 1 - 6 3 1 - 4 4 1 - 3 Each user has a unique five-digit ID number. Whenever a user logs on, the user’s ID, lab number, and the computer station number are transmitted to your system. For example, if user 49193 logs...

  • Please post the code in c++! Computer Labs Write a Computer Labs program to store the...

    Please post the code in c++! Computer Labs Write a Computer Labs program to store the list of user IDs for each computer station using a linked list. Problem Description: You run four computer labs. Each lab contains computer stations that are numbered as shown in the table below: Lab Number Computer station Numbers 1-5 2 1-6 1-4 4 1-3 Each user has a unique five-digit ID number. Whenever a user logs on, the User's ID, labnumber, and the computer...

  • computer science

    CSCI 3000 Homework 4In this assignment, you will implement a simple version of Computer Lab administration system in C++. Your program will monitor computers in 4 computer labs and will allow users to log in and log out. Each computer lab has different number of computers.·      Lab 1 has 10 computers·      Lab 2 has 6 computers·      Lab 3 has 3 computers·      Lab 4 has 12 computersHere is a sample state of the system:Lab ArraySome of the computers are free (no...

  • In this assignment, you will implement a simple version of Computer Lab administration system in C++....

    In this assignment, you will implement a simple version of Computer Lab administration system in C++. Your program will monitor computers in 4 computer labs and will allow users to log in and log out. Each computer lab has different number of computers. •Lab 1 has 10 computers •Lab 2 has 6 computers •Lab 3 has 3 computers •Lab 4 has 12 computers Here is an example state of the system: Lab Array Some of the computers are free (no...

  • #include <iostream> #include <cstdlib> using namespace std; int **dynArray(int row, int cols) { int **myPtr; int...

    #include <iostream> #include <cstdlib> using namespace std; int **dynArray(int row, int cols) { int **myPtr; int lab[4]; myPtr = new int *[row]; for(int i = 0; i < row; i++) myPtr[i] = new int[lab[i]]; for(int i = 0; i<row ; i++) if(myPtr[i] == 0) cout<<"empty"; return myPtr; } void getinput(int ID,int &Station,int &labnumb) { cout<<" Enter your ID number: "<<endl; cin>>ID; cout<<" Enter your station number: "<<endl; cin>>Station; cout<<" Enter your lab number: "<<endl; cin>>labnumb; return; } void logout(int ID,int...

  • Language: C++ PLEASE INCLUDE SCREENSHOT OF OUTPUT In this assignment, you will consider the problem of organizing a collection of computer user-ids and passwords. Each time a user logs in to the syste...

    Language: C++ PLEASE INCLUDE SCREENSHOT OF OUTPUT In this assignment, you will consider the problem of organizing a collection of computer user-ids and passwords. Each time a user logs in to the system by entering his or her user-id and a secret password, the system must check the validity of this user-id and password to verify that this is a legitimate user. Because this validation must be done many times each day, it is necessary to structure this information in...

  • Program: Playlist (C++) I'm having difficulty figuring out how to get the header file to work....

    Program: Playlist (C++) I'm having difficulty figuring out how to get the header file to work. You will be building a linked list. Make sure to keep track of both the head and tail nodes. (1) Create three files to submit. Playlist.h - Class declaration Playlist.cpp - Class definition main.cpp - main() function Build the PlaylistNode class per the following specifications. Note: Some functions can initially be function stubs (empty functions), to be completed in later steps. Default constructor (1...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT