Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package educationcenter;
- import educationcenter.command.Command;
- import educationcenter.model.Lesson;
- import educationcenter.model.Student;
- import educationcenter.model.User;
- import educationcenter.storage.LessonDatabase;
- import educationcenter.storage.StudentDatabase;
- import educationcenter.storage.UserDatabase;
- import java.util.Date;
- import java.util.Random;
- import java.util.Scanner;
- public class EducationCenter implements Command {
- static Scanner scanner = new Scanner(System.in);
- static StudentDatabase studentDatabase = new StudentDatabase();
- static LessonDatabase lessonDatabase = new LessonDatabase();
- static UserDatabase userDatabase = new UserDatabase();
- static Random random = new Random();
- static User currentUser = null;
- public static void main(String[] args) {
- Student student = new Student("Karen", "Hovhannisyan", "04443", "mail.ru", "Manager", new Date());
- studentDatabase.addStudent(student);
- Student student1 = new Student("Artash", "Haroyan", "077698962", "art.aro@mail.ru", "Manager", new Date());
- studentDatabase.addStudent(student1);
- User user = new User(student.getName(), student.getSurname(), "login", "password", student);
- User user1 = new User(student1.getName(), student1.getSurname(), "milena", "vilena", student1);
- userDatabase.addUser(user);
- userDatabase.addUser(user1);
- boolean isRun = true;
- while (isRun) {
- System.out.println("Please input: " + EXIT + " for exit");
- System.out.println("Please input: " + LOGIN + " for login");
- int answer = Integer.parseInt(scanner.nextLine());
- switch (answer) {
- case EXIT:
- isRun = false;
- break;
- case LOGIN:
- System.out.println("Please input login and password");
- String loginAndPassword = scanner.nextLine();
- String[] data = loginAndPassword.split(",");
- currentUser = userDatabase.getUserByLoginAndPassword(data[0], data[1]);
- if (currentUser == null) {
- System.out.println("Invalid login or password");
- } else {
- if (currentUser.getStudent().getType().equalsIgnoreCase("manager")) {
- managerPage();
- } else {
- studentPage();
- }
- }
- }
- }
- }
- private static void studentPage() {
- boolean isRun = true;
- while (isRun) {
- System.out.println("input " + EXIT + "for exit");
- System.out.println("Input 1 for print your lessons");
- System.out.println("Input 2 for print all lessons");
- int answer = Integer.parseInt(scanner.nextLine());
- switch (answer) {
- case EXIT:
- isRun = false;
- break;
- case 1:
- printYourlesson();
- break;
- case 2:
- lessonDatabase.printLessons();
- break;
- }
- }
- }
- private static void printYourlesson() {
- for (int i = 0; i < currentUser.getStudent().getLessons().length; i++) {
- System.out.println(currentUser.getStudent().getLessons()[i]);
- }
- }
- private static String[] getLoginAndPassword(String[] strings) {
- String[] loginAndPassword = new String[2];
- boolean isRun = true;
- while (isRun) {
- loginAndPassword[0] = strings[0] + (1 + random.nextInt(999));
- if (userDatabase.isLogin(loginAndPassword[0])) {
- loginAndPassword[1] = strings[1] + (1 + random.nextInt(999));
- isRun = false;
- }
- }
- return loginAndPassword;
- }
- private static void managerPage() {
- boolean isRun = true;
- while (isRun) {
- printCommand();
- int answer = Integer.parseInt(scanner.nextLine());
- switch (answer) {
- case EXIT:
- isRun = false;
- break;
- case ADD_STUDENT:
- addedStudent();
- break;
- case ADD_LESSON:
- addedLesson();
- break;
- case PRINT_STUDENTS:
- studentDatabase.printStudents();
- break;
- case PRINT_LESSONS:
- lessonDatabase.printLessons();
- break;
- case CHANGE_STUDENT_BY_LESSON:
- changeStudentByLesson();
- break;
- case PRINT_STUDENTS_BY_LESSON_NAME:
- System.out.println("Please input lesson name");
- String lessonName = scanner.nextLine();
- studentDatabase.PrintStudentsByLessonName(lessonName);
- break;
- }
- }
- }
- private static void changeStudentByLesson() {
- System.out.println("OUR STUDENTS");
- studentDatabase.printStudents();
- System.out.println("Please input stundent name");
- String name = scanner.nextLine();
- Student student = studentDatabase.getStudentByStudentName(name);
- if (student == null) {
- System.out.println("Invalid student name");
- } else {
- lessonDatabase.printLessons();
- System.out.println("Input lessons name");
- String lessonsName = scanner.nextLine();
- String[] lessonData = lessonsName.split(",");
- Lesson[] lessons = new Lesson[lessonData.length];
- for (int i = 0; i < lessonData.length; i++) {
- lessons[i] = lessonDatabase.getLessonByLessonName(lessonData[i]);
- }
- student.setLessons(lessons);
- }
- }
- private static void printCommand() {
- System.out.println("Welcome to the Education Center");
- System.out.println("Input " + EXIT + " to Exit");
- System.out.println("Input " + ADD_STUDENT + " to add student");
- System.out.println("Input " + ADD_LESSON + " to add lesson");
- System.out.println("Input " + PRINT_STUDENTS + " to print students");
- System.out.println("Input " + PRINT_LESSONS + " to print lessons");
- System.out.println("Input " + CHANGE_STUDENT_BY_LESSON + " to change student by lesson");
- System.out.println("Input " + PRINT_STUDENTS_BY_LESSON_NAME + " to print students by lesson name");
- }
- private static void addedStudent() {
- System.out.println("Please Input student name,username,phone,email,type");
- String studentData = scanner.nextLine();
- String[] studentInfo = studentData.split(",");
- lessonDatabase.printLessons();
- System.out.println("Please input Lesson name");
- String studentlessons = scanner.nextLine();
- String[] lessons = studentlessons.split(",");
- Lesson[] lessons1 = new Lesson[lessons.length];
- for (int i = 0; i < lessons.length; i++) {
- lessons1[i] = lessonDatabase.getLessonByLessonName(lessons[i]);
- }
- Student student = new Student(studentInfo[0], studentInfo[1], studentInfo[2],
- studentInfo[3], studentInfo[4], new Date(), lessons1);
- studentDatabase.addStudent(student);
- System.out.println("if you want open accaunt in Education Center");
- String answer = scanner.nextLine();
- if (answer.equalsIgnoreCase("Yes")) {
- String[] studentdata = {student.getName(), student.getSurname()};
- String[] loginAndPassword = getLoginAndPassword(studentdata);
- User user = new User(student.getName(), student.getSurname(),
- loginAndPassword[0], loginAndPassword[1], student);
- System.out.println("Your Login is: " + loginAndPassword[0]);
- System.out.println("Your Password is: " + loginAndPassword[1]);
- userDatabase.addUser(user);
- } else {
- if (answer.equalsIgnoreCase("No")) {
- System.out.println("Thank You,You successfully Added ");
- }
- }
- }
- private static void addedLesson() {
- System.out.println("");
- System.out.println("Please input lesson name,duration,price,lecture name");
- String studentLesson = scanner.nextLine();
- String[] lessonInfo = studentLesson.split(",");
- int duration = Integer.parseInt(lessonInfo[1]);
- double price = Double.parseDouble(lessonInfo[2]);
- Lesson lesson = new Lesson(lessonInfo[0], duration, price, lessonInfo[3]);
- lessonDatabase.addLesson(lesson);
- }
- }
Add Comment
Please, Sign In to add comment