Question
Ok, So im having some difficulty getting started I'm having determining if the array list is empty - this is the assignment and program so
Ok, So im having some difficulty getting started I'm having determining if the array list is empty - this is the assignment and program so far along with what i have -
The
LinkedIn Command Line Interface
Class
Package: edu.sinclair
Create a class called, LinkedInInterface which will serve as the command line interface between the
user and your software.
Define the following properties.
/**
*
Holds the list of users in the system.
*/
private List
;
/**
*
Holds the logged in user.
*/
private LinkedInUser loggedInUser;
public LinkedInInterface () {users = new ArrayList<>();}
The LinkedInInterface class should have methods to list all the users (i.e. print out their usernames), sign up a new user, delete a user, print who the logged in user is, sign off, and quit
.
1.
Create a public static void main method which prints the following menu to the console
and awaits user input.
Upon entry the application should do the following:
a.Load any previously saved data.
See the Serializing and Deserializing section below for the details
b.If there are no users in the syste, do the following
i.prompt the user to establish the root user and password.
ii. Default the LinkedInUser type to P for premier.
iii. Add the newly created user to the list of users defined within the constructor.
iv. Assign the newly created user to loggedInUser property on the class to indicate that this new user is the logged in user.
v.Display the Welcome menu(step 2 below)
.
c.If there is at least one user in the system, do the following
i.Prompt the user to login by supplying a user name and password.
ii.If the user name doesnt exist, display the message, There is no user with tha
t user name and re-display the login prompt.
iii.If the user does exist and the password is incorrect, display the message,
Password mismatch and re-display the login prompt.
iv.If both username and password are valid
1.Assign the user to loggedInUser
property o
n the class to indicate that this is the logged in user.
2.display the Welcome menu (step 2 below).
2.Display the Welcome menu.Welcome
1.List all Users,
2.Sign up a New User,
3.Delete a User,
4.Who am I
5.Sign Off
6.Quit(substitutethe actual logged in user name for the
continue until the user chooses to
Quit
.
(See the below sections for the details on each menu choice)Serializing and De
-
serializingWe want the data entered within our LinkedIn Interface to persist between program executions. To
do this, serialize yourlist ofLinkedInUserobjects before the program terminates
(see the Quitsection belowfor the details on this)
.
Whenthe program starts up again
, deserialize the list of LinkedInUserobjectsrather than making the user always create new ones
.
Remember:toserialize and de
-
serialize the LinkedInUserclass, it(along with its superclass)must implement Serializable
.
Menu Options
List all UsersLoop through all the LinkedInusers and print their user name to the console.Sign up a NewUser
Prompt the user for the user nameto add. Check if the supplied user name already exists in the userslist. If it does, display an error message to the console and re
-
display the menu.
If the supplied user name is unique, do the following
o
prompt the user to enter a password and what type of user he/she is
Valid types are S for Standard and P for Premier. If the user enters
any other value, display the message, Invalid user type. Valid types are
P or S and redisplay the menu.
o
construct a LinkedInUserinstance and add the instance to the usersliston the LinkedInInterface.
oAfterwards, re
-display the menu.Delete a User
Prompt for the user name to delete. Check if the supplied user name exists in the user list.
If the userdoes NOT exist, display an error message to the console and re
-
display the menu.
If the user does exist, prompt for the password of the user being deleted.
If the password is not correct, display an error message to the console and re
-
display
the menu.
If the password is correct, remove the user from the
Users list on the LinkedInInterface class and re-display the menu.
If the deleted user was the logged in user, null out the loggedInUser property on the LinkedInInterface class and re
-
present the user interface.
o
Since the logged in user is now null, the application should act the same as the application
Did upon start up (either making the user establish a root user or
login with an existing user). See step 1 b.
Who am I
Display the logged in user. Sign off
Null out the loggedInUser property and re
-
present the user interface.
Since the logged in user is now null, the application should act the same as the
application does upon start up (
either making the user establish a root user or login with
an exi
sting user).
See step 1 b.
Quit
private static final
String PATH =
System.getProperty("user.home") +
File.separator + "sinclair" + File.separator;
private static final
String FILE_NAME = "
Users.dat";
Place the above
static final
fields in your
LinkedInInterface class.
Using the above
static final
fields, serialize the users list to the
PATH +
FILE_NAME
location.
o
new
FileOutputStream(PATH + FILE_NAME);
o
The
PATH
constant will point to your computers home directory.
o
The
File.separator
constant will contain the directory separator character
for your operating system.
/ for linux or mac
s
\
for windows
If any of the folders in the
PATH
do not exist, create them.
o
new
File(PATH).mkdirs();
If an existing
Users.dat
file
already
e
xists, delete it and recreate it upon exiting
the application.
Write Goodbye to the system.out console.
///////////////
Here is what i have
package edu.Sinclair;
import edu.Sinclair.UserAccount;
public abstract class UserAccount implements java.io.Serializable { private static final long serialVersionUID = -974304835833540220L; // User Account Data Fields private String username; private String password; // User Account Constructor public UserAccount(String username, String password) { this.username = username; this.setPassword(password); }
// Generated Getters and Setters for the Data Fields public String getUsername() { return username; }
public boolean isPasswordCorrect(String password) { return this.getPassword() == null ? false : this.getPassword().equals(password); } public abstract void setType (String type); @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((username == null) ? 0 : username.hashCode()); return result; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null) return false; if (getClass() != o.getClass()) return false; UserAccount other = (UserAccount) o; if (username == null) { if (other.username != null) return false; } else if (!username.equals(other.username)) return false; return true; }
@Override public String toString() { String str = ""; str += "User Name: " + username; return str; }
public String getPassword() { return password; }
public void setPassword(String password) { this.password = password; }
}
package edu.Sinclair;
import java.util.ArrayList; import java.util.List;
class LinkedInUser extends UserAccount implements Comparable
public LinkedInUser(String username, String password) { super(username, password); }
public String getType() { return this.type; }
@Override public void setType(String type) { this.type = type; }
public void addConnection(LinkedInUser user) throws LinkedInException{
for(LinkedInUser linkedInUser : this.connections) { if(linkedInUser.equals(user)) { throw new LinkedInException("Error: Already Connected"); } }
this.connections.add(user);
}
public void removeConnection(LinkedInUser user) throws LinkedInException { for(LinkedInUser linkedInUser : this.connections) { if(linkedInUser.equals(user)) { this.connections.remove(user); return; } } throw new LinkedInException("Error: Not Connected"); }
public List
// this calls to the above method and compares both the original and the new
@Override public int compareTo(LinkedInUser user) { return this.getUsername().compareToIgnoreCase(user.getUsername()); }
}
package edu.Sinclair; import java.util.ArrayList; import java.util.List;
public class LinkedInCLI extends LinkedInUser{
private static final long serialVersionUID = -974304835833540220L; private LinkedInUser loggedInUser; private List
} public LinkedInUser getLoggedInUser() { return loggedInUser; }
public void setLoggedInUser(LinkedInUser loggedInUser) { this.loggedInUser = loggedInUser; }
public List
public void setUsers(List
}
package edu.Sinclair; import java.util.Scanner; import java.util.Scanner;
public class LinkedInDriver { public static Scanner keyIn; // scanner in thingy public static void main(String[] args) { LinkedInUser h = new LinkedInUser("han", "ABC124"); System.out.println(); System.out.println(users.listLength()); int menuvar;
keyIn = new Scanner(System.in); menuvar = menu(); while(menuvar < 1 ||menuvar > 6) { } while(menuvar !=6) { if(menuvar == 1) { System.out.println(" Would you like to make an additional selection? " ); menuvar = menu(); } else if(menuvar == 2) { System.out.println(" Would you like to make an additional selection? " ); menuvar = menu(); }else if(menuvar == 3) { System.out.println(" Would you like to make an additional selection? " ); menuvar = menu(); } else if(menuvar == 4) { System.out.println(" Would you like to make an additional selection? " ); menuvar = menu(); } else if(menuvar == 5) { System.out.println(" Would you like to make an additional selection? " ); menuvar = menu(); }
} System.out.println(" Thank you, good day, eh? "); keyIn.close(); System.exit(0);
} public static int menu() { keyIn = new Scanner(System.in); int choice; System.out.print("1 - List All Users 2- Sign up a new user 3- Delete User 4- Who am I 5-Sign off 6- Quit "); choice = keyIn.nextInt(); return choice; }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started