Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help on this java program as soon as possible. The code below was given to me by the instructor and I need help on

Need help on this java program as soon as possible. The code below was given to me by the instructor and I need help on revising this code as per the instructions below. I have also include the Java code below.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Java Lab - User Id and Password Entry Revised Objective: This project is a revision of the previous Password project. The user information entered will be written as a record to an output file. Menu option 2 will be added that allows all the user accounts to be read from the file and displayed to the console. Arrays will be implemented and used as a reference for validation and in the display process. Instantiable class UserInfo: String userId String userPassword Integer userStatus: 1 - Commuter no meal plan 2 - Commuter with meal plan 3- Dorm Charyser Program: B-Business P-Programming L - Lasers R- Robotics N - Networking S-Social Media . o O o o O o 0 getters and setters Default constructor (your choice of default values) Parameterized/overloaded constructor (accepts all four fields and sets them) User Entry Program: Define a hard-coded char array to hold the valid user program values (used for validating/searching) Define a hard-coded String array to hold the user program names (used when displaying user info) Define a hard-coded String array to hold the user status names (used when displaying user info) File stream objects to read and write data to an external file Menu: Menu Option 1 changes: Add a loop to prompt and validate for user status (must meet the following specifications): Must be a number 1 - 3 Use a try/catch to validate for numeric entry Do not exit loop until user status is valid. User must get it right. Add a loop to prompt and validate for program (must meet the following specifications): Must be a single character Must be a B, L, N, P, R or S Create a hard-coded array to store these values Use a search loop to validate the value entered is in the array. The subscript must be saved so that it can be used to access the program description array. Do not exit loop until user program is valid. User must get it right. After all four fields are valid, instantiate a UserInfo object with the data (use the parameterized constructor). Do not instantiate this object right away like the previous project, but only after the data is entered and validated. o Write the user information as a fixed-length record to the file. Each record will occupy a separate line in the file. When formatting the record, user id and password should occupy 12 positions each, status and program 1 position each, for a total record length of 26. The getters from the UserInfo class should be used to retrieve the data from the object Display a successful add message until the user presses Enter Menu Option 2 - Display all users: When this option is chosen, use a file read loop, and display the user information in a formatted report layout to the console. Use column headings at the top of the report, and single space the records. Display a count of users on a total line at the bottom. Be sure to pause the screen. When user presses Enter, the program will return to the Menu. Be sure to instantiate your file Scanner object each time Menu option 2 is selected. Doing so ensures that the file pointer will start at the beginning of the file. . 0 O This project is worth 30 points. Lab 5 Password User Entry Program java UserInfo.java 1 A 44 AV 4 This Program will ask the user to enter a user id and password, then the program will validate them according to our specifications. The user will keep being prompted to reenter the user id and password until both are correct. After entering a valid user id and password, the Menu will redisplay. Christopher Carlson 01-29-2020 * KayPromoter on Database 5 6 8 LO 13 14 import java.util.*; class UserEntry Program { public static void main(String args[]) { UserInfo user = null; Scanner sc = new Scanner(System.in); int ch = 1; String id, password: while(ch!=3) { // Loop for both the username and password displayMenu(); //displayMenu Method Below ch = sc.nextInto: if(ch=-1)//If the User chooses Choice one, the program continues 17 28 19 20 23 24 25 26 { 28 29 30 32 32 idSpecificationlisg); //idSpecificationsg Method Below sc.nextLine()://skip or go to the new line id = so.nextLine(); while(validateId(id)) //validated Boolean Method Below { System.out.print("Try another User ID name: "); 1d = sc.nextLine(); 1 passwordSpecifications: 1/password SpecificationMsg Method Below password = sc.nextLine(); while( validatePassword(password)) //validatePassword Boolean Method Below { 35 36 37 Use Entry Program java Userinfo.java 38 39 40 System.out.print("Try another password please: "); password = sc.nextLine(); A } 42 43 45 46 47 user = new UserInfo(id, password); //UserInfo is stored in the user Info.java file. System.out.println("User information was accepted"); System.out.println("User ID: "+user.getUserId()); //Getters for the User ID in the UserInfo.java file System.out.println("user Password: "+user.getUser Password(); //Getters for the Password in the UserInfo.java file sc.nextLine();//hold the screen } else 48 49 52 53 54 55 if (ch==3) { terminateMsgO; //Termination Method, the program will then end with a message sc.nextLine();//skip or goes to the new Line option sc.nextLine();//holds / pauses the screen } else + System.out.println("ERROR!! Wrong option, please enter 1 or 3. "); //Informs the user in the option chosen was chosen. } } }//End of While Loop for Username and Password F 56 57 58 59 61 }//End of Main Method 64 65 66 67 static void displayMenu() { //this method displays the menu on the screen. System.out.println(" *****************************"); System.out.println("1- Create a new user."); System.out.println("3 - Exit program."); System.out.print("Enter your choice (1-3): "); } 69 79 71 @ @ User Entry Program.java Userinfo.java static boolean validateId(String id) { 72 //method to validate userID 73 //returns true if it passes all validation tests else false 24 int i,l=id.length(c=0; 75 if(1>12) //Length must be greater than 12 characters { 7 return false; //Length greater than 12 78 } BC B1 84 86 int Lasti, last2; lasti = id.charAt(L-1), last2 = id.charAt(1-2); if(last1548 || Last1>57 || last257) // last 2 characters are not number return false; for(i=0;i12) // Length must be greater than 12 characters { return false; //Length greater than 12 } if(l12) //Length must be greater than 12 characters { 7 return false; //Length greater than 12 78 } BC B1 84 86 int Lasti, last2; lasti = id.charAt(L-1), last2 = id.charAt(1-2); if(last1548 || Last1>57 || last257) // last 2 characters are not number return false; for(i=0;i12) // Length must be greater than 12 characters { return false; //Length greater than 12 } if(l

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions