<repo_name>LawrenceLoh/EPDA<file_sep>/src/model/Admin.java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;
import java.util.List;
import javax.swing.JOptionPane;

/**
 *
 * @author Acer
 */
public class Admin {
    public static boolean Login(int y){
    if(y==12345){
    return true;
    }
    return false;
    }
    
    public static Student createStudent(){
    String a = JOptionPane.showInputDialog("Enter student name");
    char b = JOptionPane.showInputDialog("Enter student gender").charAt(0);
    int c = Integer.parseInt(JOptionPane.showInputDialog("Enter student pin"));
    double d = Double.parseDouble(JOptionPane.showInputDialog("Enter student balance"));
    return new Student (a,b,c,d);
    
    }
    
    public static void deleteStudent(List x){
         String a = JOptionPane.showInputDialog("Enter student name:");
         boolean flag =false;
         for (int i = 0; i<x.size();i++){
         if (a.equals(((Student)(x.get(i))).getName())){
         x.remove(i);
         flag =true;
         break;
         }
         }
        if(flag){
        JOptionPane.showMessageDialog(null,"Done!");
        }else{
        JOptionPane.showMessageDialog(null,"Wrong Student name!");
        }
    }
    
    public static void printReport(List x){
    int male = 0;
    for(int i = 0;i <x.size();i++){
    if ('M' == (((Student)(x.get(i))).getGender())){
    male++;
    }
    }
    int female= x.size() -male;
    JOptionPane.showMessageDialog(null,"There are"+male+" male students and "+female+"female studemts.");
    }
    
}
<file_sep>/src/model/Account.java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;
import java.io.Serializable;
/**
 *
 * @author Acer
 */
public class Account implements Serializable {
    private double balance;
    public Account (double x){
       balance = x;
    }
    public void deposit (double x){
    balance = balance + x;
    }
    public void withdraw (double x){
    balance  =balance -x;
    }
    public double getBalance(){
    return balance;
    }
}
<file_sep>/src/week01/Week01.java
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package week01;

import data.Database;
import javax.swing.JOptionPane;
import java.util.logging.Logger;
import model.Admin;
import model.Student;

/**
 *
 * @author Acer
 */
public class Week01 {

    /**
     * @param args the command line arguments
     */
    private static final Logger log = Logger.getLogger(Week01.class.getName());
    private static Student Loginedstudent;

    public static void main(String[] args) {
        // TODO code application logic here

        Database.readData();
        menu();

    }

    public static void menu() {

        int choice = JOptionPane.showOptionDialog(null,
                "Select your role?",
                "Role Selection?",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE, null,
                new String[]{"Student", "Admin"}, "default");

        log.info(String.valueOf(choice));
        if (choice == 0 || choice == 1) {
            boolean selection = (choice == JOptionPane.YES_OPTION);
            //Student
            if (selection) {
                log.info("the student is chosen");
                login("Student");

            } else {
                //Admin
                log.info("the admin is chosen");
                login("Admin");
            }

        }

    }

    public static void login(String role) {

        switch (role) {
            case "Student":
                studentLogin();
                break;
            case "Admin":
                adminLogin();
                break;
        }

    }

    public static void adminLogin() {

        boolean loginSuccess = false;
        while (!loginSuccess) {
            String password = JOptionPane.showInputDialog(null, "input password");
            log.info(password);
            loginSuccess = Admin.Login(Integer.parseInt(password));
            if (loginSuccess) {
                showAdminMenu();
            }
        }
    }

    public static void studentLogin() {
        Database.readData();
        String name = JOptionPane.showInputDialog("Enter your name:");
        for (Student student : Database.getData()) {
            if (student.getName().equals(name)) {
                Loginedstudent = student;
            }
        }
        if (Loginedstudent == null) {
            JOptionPane.showMessageDialog(null, "No such student");
            studentLogin();
        }

        boolean loginSuccess = false;
        while (!loginSuccess) {
            loginSuccess = Loginedstudent.Login();
            if (loginSuccess) {
                showStudentMenu();
            } else {
                JOptionPane.showMessageDialog(null, "Invalid password");
            }

        }

    }

    public static void showStudentMenu() {
        int choice = JOptionPane.showOptionDialog(null,
                "Student Menu",
                "Menu",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.INFORMATION_MESSAGE, null,
                new String[]{"Deposit", "Withdraw", "Print", "Logout"}, "default");

        log.info(String.valueOf(choice));

        switch (choice) {
            case 0:
                Loginedstudent.deposit();
                Database.writeData();
                showStudentMenu();
                break;
            case 1:
                Loginedstudent.withdraw();
                Database.writeData();
                showStudentMenu();
                break;
            case 2:
                Loginedstudent.printing();
                showStudentMenu();
                break;
            case 3:
                menu();
                break;
        }

    }

    public static void showAdminMenu() {

        int choice = JOptionPane.showOptionDialog(null,
                "Admin Menu",
                "Menu",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.INFORMATION_MESSAGE, null,
                new String[]{"Create Student", "Delete Student", "Print Report", "Logout"}, "default");

        log.info(String.valueOf(choice));

        switch (choice) {
            case 0:
                Database.readData();
                Database.getData().add(Admin.createStudent());
                Database.writeData();
                showAdminMenu();
                break;
            case 1:
                Database.readData();
                Admin.deleteStudent(Database.getData());
                Database.writeData();
                showAdminMenu();
                break;
            case 2:
                Database.readData();
                Admin.printReport(Database.getData());
                showAdminMenu();
                break;
            case 3:
                menu();
                break;
        }

    }

}
