Your local public library wants to design new software to keep track of patrons, books, and lending activity. List at least three classes you think should be in the design. For each class, identify some data members and methods.
import java.sql.SQLException;
import java.text.ParseException;
import java.util.List;
import java.util.Scanner;
import model.Manager;
import model.Student;
//Login and register
public class LoginAndRegister {
//enter the system
public void initial() throws ClassNotFoundException, SQLException, ParseException{
System.out.println("Student S/Administrator M?");
Scanner sc=new Scanner(System.in);
String sm=sc.next();
//Student
if ("S".equals(sm)) {
System.out.println("Login L/Registration R?");
String lr=sc.next();
if ("L".equals(lr)) {
studentLogin();
}
//Student registration
if ("R".equals(lr)) {
studentRegister();
}
}
//Administrator
if ("M".equals(sm)) {
System.out.println("Login L/Registration R?");
String lr=sc.next();
//Admin login
if ("L".equals(lr)) {
managerLogin();
}
//Administrator registration
if ("R".equals(lr)) {
managerRegister();
}
}
}
//Student login
public void studentLogin() throws ClassNotFoundException, SQLException, ParseException{
System.out.println("Please log in");
System.out.println("Please enter the account number:");
Scanner sc=new Scanner(System.in);
String name=sc.next();
boolean n=true;//Name
boolean p=true;//Password
StudentDao studentDao=new StudentDao();
List<Student> list=studentDao.selectStudent();
for (Student student : list) {
if (name.equals(student.getStudentName())) {
System.out.println("Account exists, please enter password:");
n=false;
}
}
if (n) {
System.out.println("Account does not exist, please log in again");
}else{
String password=sc.next();
for (Student student : list) {
if ((name.equals(student.getStudentName()))&&(password.equals(student.getPassword()))) {
System.out.println("Login successful");
StudentChoose studentChoose=new StudentChoose();
studentChoose.choose();
p=false;
}
}
}
if (p) {
System.out.println("Wrong password, login failed");
}
}
//Student registration
public void studentRegister() throws ClassNotFoundException, SQLException, ParseException{
Scanner sc=new Scanner(System.in);
System.out.println("Please enter your registered account:");
String name=sc.next();
StudentDao studentDao=new StudentDao();
List<Student> list=studentDao.selectStudent();
for (Student student : list) {
if (name.equals(student.getStudentName())) {
System.out.println("Account has been registered, please re-enter");
studentRegister();
}else{
continue;
}
}
System.out.println("Please enter the login password:");
String password1=sc.next();
System.out.println("Please enter the login password again:");
String password2=sc.next();
if (password1.equals(password2)) {
studentDao.insertStudent(name, password1);
System.out.println("Registration succeeded, please log in");
studentLogin();
}else{
System.out.println("The password entered twice does not match, please re-register:");
studentRegister();
}
}
//Admin login
public void managerLogin() throws ClassNotFoundException, SQLException, ParseException{
System.out.println("Please log in");
System.out.println("Please enter the account number:");
Scanner sc=new Scanner(System.in);
String name=sc.next();
boolean n=true;
boolean p=true;
ManagerDao managerDao=new ManagerDao();
List<Manager> list=managerDao.selectManager();
for (Manager manager : list) {
if (name.equals(manager.getManagerName())) {
System.out.println("Account exists, please enter password:");
n=false;
}
}
if (n) {
System.out.println("Account does not exist, please log in again");
}else{
String password=sc.next();
for (Manager manager : list) {
if ((name.equals(manager.getManagerName()))&&(password.equals(manager.getPassword()))) {
System.out.println("Login successful");
ManagerChoose managerChoose=new ManagerChoose();
managerChoose.choose();
p=false;
}
}
}
if (p) {
System.out.println("Wrong password, login failed");
}
}
//Administrator registration
public void managerRegister() throws ClassNotFoundException, SQLException, ParseException{
Scanner sc=new Scanner(System.in);
System.out.println("Please enter your registered account:");
String name=sc.next();
ManagerDao managerDao=new ManagerDao();
List<Manager> list=managerDao.selectManager();
for (Manager manager : list) {
if (name.equals(manager.getManagerName())) {
System.out.println("Account has been registered, please re-enter");
managerRegister();
}else{
continue;
}
}
System.out.println("Please enter the login password:");
String password1=sc.next();
System.out.println("Please enter the login password again:");
String password2=sc.next();
if (password1.equals(password2)) {
managerDao.insertManager(name, password1);
System.out.println("Registration succeeded, please log in");
managerLogin();
}else{
System.out.println("The password entered twice does not match, please re-register:");
managerRegister();
}
}
}
Comments
Leave a comment