Java project

EstherHe
Project4.java

/* Name: Yuanmeng He Date: 5/19/2018 Introduction:Write a computer program that could be used to track, by lab, which user is logged onto which computer. */ import java.util.Scanner; import java.io.*; public class Project4 { public static void main(String[] args) { //varaible declaration int i,choice,lid,cid,f; String uid,chid,sid; String l1[]=new String[5]; String l2[]=new String[7]; String l3[]=new String[4]; String l4[]=new String[3]; for(i=0;i<5;i++) //making all the array to empty { l1[i]="empty"; } for(i=0;i<6;i++) { l2[i]="empty"; } for(i=0;i<4;i++) { l3[i]="empty"; } for(i=0;i<3;i++) { l4[i]="empty"; } do { f=0; //status of the machines System.out.println("LAB STATUS"); System.out.println("Lab # Computer Stations"); System.out.print("1 "); for(i=0;i<5;i++) { System.out.print((i+1)+": "+l1[i]+" "); } System.out.println(); System.out.print("2 "); for(i=0;i<6;i++) { System.out.print((i+1)+": "+l2[i]+" "); } System.out.println(); System.out.print("3 "); for(i=0;i<4;i++) { System.out.print((i+1)+": "+l3[i]+" "); } System.out.println(); System.out.print("4 "); for(i=0;i<3;i++) { System.out.print((i+1)+": "+l4[i]+" "); } System.out.println(); Scanner sc=new Scanner(System.in); 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"); choice = sc.nextInt();//asking for user choice if(choice == 0) { System.exit(0); } else if(choice == 1) { //taking input from user System.out.println("Enter the 5 digit ID number of the user logging in:"); uid=sc.next(); System.out.println("Enter the lab number the user is logging in from (1-4):"); lid=sc.nextInt(); System.out.println("Enter computer station number the user is logging in to (1-6):"); cid=sc.nextInt(); if(lid==1) { l1[cid-1]=uid; } else if(lid==2) { l2[cid-1]=uid; } else if(lid==3) { l3[cid-1]=uid; } else l4[cid-1]=uid; } else if(choice == 2) { //taking input from user System.out.println("Enter the 5 digit ID number of the user to find:"); chid=sc.next(); for(i=0;i<5;i++) { if(l1[i].equalsIgnoreCase(chid)) l1[i]="empty"; } for(i=0;i<6;i++) { if(l2[i].equalsIgnoreCase(chid)) l2[i]="empty"; } for(i=0;i<4;i++) { if(l3[i].equalsIgnoreCase(chid)) l3[i]="empty"; } for(i=0;i<3;i++) { if(l4[i].equalsIgnoreCase(chid)) l4[i]="empty"; } System.out.println("User "+chid+" is logged off."); } else if(choice == 3) { //taking inut from user System.out.println("Enter the 5 digit ID number of the user to find:"); sid=sc.next(); for(i=0;i<5;i++) { if(l1[i].equalsIgnoreCase(sid)) { System.out.println("User "+sid+" logged in lab 1 in system "+(i+1)); f=1; break; } } for(i=0;i<6;i++) { if(l2[i].equalsIgnoreCase(sid)) { System.out.println("User "+sid+" logged in lab 2 in system "+(i+1)); f=1; break; } } for(i=0;i<4;i++) { if(l3[i].equalsIgnoreCase(sid)) { System.out.println("User "+sid+" logged in lab 3 in system "+(i+1)); f=1; break; } } for(i=0;i<3;i++) { if(l4[i].equalsIgnoreCase(sid)) { System.out.println("User "+sid+" logged in lab 4 in system "+(i+1)); f=1; break; } } if(f==0) { System.out.println("None of the user Id is not logged into any computer station"); f=0; } } }while(choice!=0); } }