this is problem ive been given
Problem
Using a structure chart design a program that essentially implements the login
piece of your project, i.e.:
CIT MODULE REGISTRATION - Login
================================================== =========================
ID Number: S1234
Password: apples
Implement the solution in Java - your solution should use void and/or value
returning methods as appropriate. The program should use a set of parallel
arrays to store the details corresponding to each user and another set of parallel
array to store the details of modules available.
For example the following arrays could be declared to store:
• user details:
String[] userId = {“S1234”, “A1234”, “S456”, “S789”};
String[] password = {“apple”, “peach”, “banana”, “apricot”};
String[] firstName = {“Jack”, “Belinda”, “John”, “Mary”};
String[] lastName = {“Black”, “Blake”, “Smith”, “Murphy”};
int[] userType = {1, 2, 1, 1};
String[] choice1 = {“SOFT6017”, null, “SOFT6018”, “SOFT6017”};
String[] choice2 = {“SOFT6018”, null, “SOFT6017”, “SOFT6018”};
• module details:
String[] moduleCode = {“SOFT6018”, “SOFT6017”, “COMH6002”,
“COMH6003”};
String[] moduleName = {“PSP1”, “PSP2”, “Computer Architecture”,
“Computer Hardware”};
int[] numberRegistered = {3, 3, 0, 0};
From the above sample data we can that:
• the user with user ID S1234 has:
o a password of apple
o a first name of Jack
o last name of Black
o is a student, i.e. a user type of 1 indicates a student while a user type
of 2 indicates an administrator.
o chosen SOFT6017 as their first module
o chosen SOFT6018 as their second module.
• the module with module code SOFT6018 has:
o a name of PSP1
o a 2 students registered
Please note that, for the moment it is sufficient to auto-initialise the arrays to
populate them with data but ultimately this data will be read from a file.
This program should:
• Enable the user to login, i.e. provided a valid user id and password
combination is entered, the user should be informed that they have logged in
successfully and be presented with an appropriate menu depending on the
type of user they are, i.e.
3 Department of Computing
o If the user is an administrator then they should be presented with the
following menu:
Belinda B. (Admin) MODULE REGISTRATION - [Main Menu] 12-Mar-2013
================================================== =========================
1 - Add a Student
2 - List All Students
3 - Add a Module
4 - List all Modules
5 - List Students Registered for a Module
6 - Exit
Please choose and option:[1-6]
o If the user is a student then they should be presented with the following
menu:
Jack B. (Student) MODULE REGISTRATION - [Main Menu] 12-Mar-2013
================================================== =========================
1 - List my Current Modules
2 - Register for a Module
3 - Deregister for a Module
4 - List all Modules
5 - Exit
Please choose and option:[1-5]
• Implement administrator menu option 4 and student menu options 1 and 4
– for the other menu options it is sufficient to create stub methods which
simply display a message to say that this method must be written.
this is what i have so far -------now i am stuck any tips/suggestions
import java.util.Scanner; public class Registration{ /** * @param args */ public static void main(String[] args) { String[] userId = {"S1234", "A1234", "S456", "S789"}; String[] password = {"apple", "peach", "banana", "apricot"}; String[] firstName = {"Jack", "Belinda", "John", "Mary"}; String[] lastName = {"Black", "Blake", "Smith", "Murphy"}; int[] userType = {1, 2, 1, 1}; String[] choice1 = {"SOFT6017", null, "SOFT6018", "SOFT6017"}; String[] choice2 = {"SOFT6018", null, "SOFT6017", "SOFT6018"}; welcome(); int loggedInIndex = login(userId, password); if(loggedInIndex!=-1) { System.out.println("Welcome " + firstName[loggedInIndex] +" " + lastName[loggedInIndex]); } else { System.out.println("Invailed Details Entered"); } } private static int login(String[] userId, String[] password) { Scanner keyboard = new Scanner(System.in); String userIdEntered = readString("Please Enter ID Number: "); int index = find(userId, userIdEntered ); String passwordEntered = readString("Enter Password: "); if(passwordEntered.equals(password[index])) { return index; } else { return -1; } } private static void welcome() { System.out.println(" CIT MODULE REGISTRATION - Login"); System.out.println("================================"); } private static String readString(String prompt) { // Create a scanner object for input from the console window Scanner keyboard = new Scanner(System.in); String value; do { System.out.println(prompt); value = keyboard.nextLine(); if(value.length()<1) { //error System.out.println("Error"); } }while(value.length()<1); return value; } /**Finds the index of a specified item in an array * @param x The array to be searched * @param value The value to be found * @return The index in the array at which the item is found */ public static int find(String[] x, String value) { int index = 0; boolean found = false; while(index < x.length && !found) { if (x[index].equals( value)) found = true; else index++; } if (found) return index; else return -1; } /** The readInteger method reads an integer value from * the console window and will display an appropriate * error message if a non-integer value is entered. * @param prompt A prompt to request the user to enter a value * @return The integer value entered. */ public static int readInteger(String prompt) { // Create a scanner object for input from the console window Scanner keyboard = new Scanner(System.in); // boolean flag which is used to control the // data validation loop boolean numGood = false; // Assume the worst do { System.out.print(prompt); // ask for the value if(!keyboard.hasNextInt()) // check if what's in the keyboard buffer is not an integer { System.out.println("You must enter an integer value!"); // display an error message keyboard.nextLine(); // consume the bad value entered } else numGood = true; // value entered is good } while(!numGood); // at this point we know the value in the // keyboard buffer is numeric so we can go ahead and // return it. return keyboard.nextInt(); } /** * The readPositiveInteger method reads a positive integer value * from the console window and will display an appropriate * error message if a non-positive integer value is entered. * @param prompt A prompt to request the user to enter a value * @return The positive integer value entered. */ public static int readPositiveInteger(String prompt) { int value; do { value = readInteger(prompt); // ask for and read an integer value if (value < 0) // check if the value entered is less than 0 // display an error message System.out.println("Error - you must enter a positive integer value!"); } while (value <0); // at this point we know the value entered is positive // so return it return value; } }