diff --git a/assigntment-01/H071191030/Main.java b/assigntment-01/H071191030/Main.java new file mode 100644 index 0000000..51b31d7 --- /dev/null +++ b/assigntment-01/H071191030/Main.java @@ -0,0 +1,82 @@ +import java.util.HashMap; +import java.util.Map; + +/** + * Main + */ +public class Main { + + public static void main(String[] args) { + Map facultyMap = new HashMap<>(); + Map majorMap = new HashMap<>(); + facultyMap.put("Ekonomi dan Bisnis", "A"); + facultyMap.put("Hukum", "B"); + facultyMap.put("Kedokteran", "C"); + facultyMap.put("Teknik", "D"); + facultyMap.put("SOSPOL", "E"); + facultyMap.put("Ilmu Budaya", "F"); + facultyMap.put("Pertanian", "G"); + facultyMap.put("MIPA", "H"); + + + majorMap.put("Matematika", "01"); + majorMap.put("Fisika", "02"); + majorMap.put("Sosiologi", "03"); + majorMap.put("Ilmu Politik", "04"); + majorMap.put("Statistika", "05"); + majorMap.put("Hubungan Internasional", "06"); + majorMap.put("Ilmu Komputer", "07"); + majorMap.put("Aktuaria", "08"); + + Student student1 = new Student(); + Student student2 = new Student(); + Student student3 = new Student(); + + student1.setFirstName("mUHammAd"); + student1.setLastName("ZaKy IrGiaWan"); + student1.setRegisterYear(2019); + student1.setFaculty("SOSPOL"); + student1.setDepartment("Ilmu Politik"); + student1.setMajor("Ilmu Politik"); + student1.setId(facultyMap, majorMap); + student1.setEmail(facultyMap); + + student2.setFirstName("jAMiL"); + student2.setLastName("HaidiR"); + student2.setRegisterYear(2019); + student2.setFaculty("SOSPOL"); + student2.setDepartment("Sosiologi"); + student2.setMajor("Sosiologi"); + student2.setId(facultyMap, majorMap); + student2.setEmail(facultyMap); + + student3.setFirstName("Pande"); + student3.setLastName("putu DYLAN sugAnggA"); + student3.setRegisterYear(2019); + student3.setFaculty("SOSPOL"); + student3.setDepartment("Hubungan Internasional"); + student3.setMajor("Hubungan Internasional"); + student3.setId(facultyMap, majorMap); + student3.setEmail(facultyMap); + + student1.description(); + student2.description(); + student3.description(); + + + + + + + + + + + + + + + + + } +} \ No newline at end of file diff --git a/assigntment-01/H071191030/Student.java b/assigntment-01/H071191030/Student.java new file mode 100644 index 0000000..9071305 --- /dev/null +++ b/assigntment-01/H071191030/Student.java @@ -0,0 +1,122 @@ +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +public class Student { + private String id; + private String firstName; + private String lastName; + private String email; + private int registerYear; + private String faculty; + private String department; + private String major; + + public void setId(String id) { + this.id = id; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public void setEmail(String email) { + this.email = email; + } + + public void setRegisterYear(int registerYear) { + this.registerYear = registerYear; + } + + public String getRegisterYear() { + String rgstYr = "" + registerYear; + String[] rgst = { rgstYr.substring(0, 2), rgstYr.substring(2) }; + String lastTwoDigits = rgst[1]; + + return lastTwoDigits; + } + + public void setFaculty(String faculty) { + this.faculty = faculty; + + } + + public void setDepartment(String department) { + this.department = department; + } + + public void setMajor(String major) { + this.major = major; + } + + public String getId() { + + return id; + } + + public String getEmail() { + + return email; + } + + public String getFaculty() { + + return faculty; + } + + public String getDepartment() { + + return department; + } + + public String getMajor() { + + return major; + } + + public void setId(Map facultyMap, Map majorMap) { + + Random random = new Random(); + int randomDigit = 1 + random.nextInt(60); + id = String.format("%s%s1%s1%03d", facultyMap.get(faculty), majorMap.get(major), getRegisterYear(), + randomDigit); + + } + + public void setEmail(Map facultyMap) { + String fullName[] = (firstName.toLowerCase() + " " + lastName.toLowerCase()).split(" "); + String lastName = fullName[fullName.length - 1]; + String firstW = ""; + for (int i = 0; i < fullName.length - 1; i++) { + firstW += fullName[i].charAt(0); + } + email = String.format("%s%s%s%s@student.unhas.ac.id", lastName, firstW, getRegisterYear(), + facultyMap.get(faculty).toLowerCase()); + + } + + public String getFullName() { + + String fullName[] = (firstName.toLowerCase() + " " + lastName.toLowerCase()).split(" "); + String name = ""; + for (int i = 0; i < fullName.length; i++) { + name += fullName[i].substring(0, 1).toUpperCase() + fullName[i].substring(1, fullName[i].length()) + " "; + } + return name; + } + + public void description() { + System.out.printf("Nama\t\t : %s\n", getFullName()); + System.out.printf("NIM\t\t : %s\n", getId()); + System.out.printf("Email Mahasiswa : %s\n", getEmail()); + System.out.printf("Fakultas\t : %s\n", getFaculty()); + System.out.printf("Departemen\t : %s\n", getDepartment()); + System.out.printf("Program Studi\t : %s\n\n", getMajor()); + + } + +} \ No newline at end of file diff --git a/assigntment-02/H071191030/App.java b/assigntment-02/H071191030/App.java new file mode 100644 index 0000000..3b1944e --- /dev/null +++ b/assigntment-02/H071191030/App.java @@ -0,0 +1,12 @@ +/** + * App + */ +public class App { + + public static void main(String[] args) throws Exception{ + Login login = Login.getObject(); + + login.auth("arzk", "qwert"); + login.status(); + } +} \ No newline at end of file diff --git a/assigntment-02/H071191030/DataSource.java b/assigntment-02/H071191030/DataSource.java new file mode 100644 index 0000000..098c074 --- /dev/null +++ b/assigntment-02/H071191030/DataSource.java @@ -0,0 +1,99 @@ +import java.util.*; +import java.io.*; + +/** + * DataSource + */ +public class DataSource { + + private static DataSource dataSource; + private HashMap userMap = new HashMap<>(); + private HashMap userDetailMap = new HashMap<>(); + + private DataSource() { + + try { + putUserDetail(); + putUser(); + } catch (Exception e) { + System.out.println(e); + } + + } + + public static DataSource getObject() { + + if (dataSource == null) { + dataSource = new DataSource(); + } + + return dataSource; + + } + + private void putUserDetail() throws IOException { + + BufferedReader reader = new BufferedReader(new FileReader("UserDetail.txt")); + String s[]; + + while (reader.ready()) { + + s = reader.readLine().split(";"); + + if (isInt(s[0])) { + userDetailMap.put(Integer.valueOf(s[0]), new UserDetail(Integer.valueOf(s[0]), s[1], s[2], s[3])); + } + } + + s = null; + reader.close(); + + } + + private void putUser() throws IOException { + + BufferedReader reader = new BufferedReader(new FileReader("User.txt")); + String s[]; + + while (reader.ready()) { + + s = reader.readLine().split(";"); + + if (isInt(s[0])) { + userMap.put(s[1], + new User(Integer.valueOf(s[0]), s[1], s[2], userDetailMap.get(Integer.valueOf(s[0])))); + } + } + + s = null; + reader.close(); + + } + + public User getUser(String key) { + + return userMap.get(key); + + } + + public UserDetail getUserDetail(int key) { + + return userDetailMap.get(key); + + } + + public static boolean isInt(String sm) { + + boolean isInt = false; + + try { + Integer.parseInt(sm); + isInt = true; + } catch (NumberFormatException e) { + System.out.println(e); + } + + return isInt; + } + +} \ No newline at end of file diff --git a/assigntment-02/H071191030/Login.java b/assigntment-02/H071191030/Login.java new file mode 100644 index 0000000..94eb00e --- /dev/null +++ b/assigntment-02/H071191030/Login.java @@ -0,0 +1,53 @@ +import java.util.NoSuchElementException; + +/** + * Login + */ +public class Login { + + private static Login login; + private User user; + private UserDetail userDetail; + private DataSource dataSource; + + private Login() { + dataSource = DataSource.getObject(); + } + + public static Login getObject() { + + if (login == null) { + login = new Login(); + } + + return login; + + } + + public void auth(String userName, String password) throws NoSuchElementException { + + user = dataSource.getUser(userName); + + try { + + if (user.Pass(password)) { + userDetail = user.getUserDetail(); + } + + } catch (Exception e) { + throw new NoSuchElementException("No such Username : " + userName); + } + + } + + public void status() { + + System.out.println("Name : " + userDetail.getName()); + System.out.println("Email : " + userDetail.getEmail()); + System.out.println("Date of Birth : " + userDetail.getDateOfBirth()); + System.out.println("UserName : " + user.getUserName()); + System.out.println("Password : " + user.getPassword()); + + } + +} \ No newline at end of file diff --git a/assigntment-02/H071191030/User.java b/assigntment-02/H071191030/User.java new file mode 100644 index 0000000..7ab8c6c --- /dev/null +++ b/assigntment-02/H071191030/User.java @@ -0,0 +1,37 @@ +/** + * User + */ +public class User { + + private Integer id; + private String userName; + private String password; + private UserDetail userDetail; + + public User(Integer id, String userName, String password, UserDetail userDetail){ + this.id = id; + this.userName = userName; + this.password = password; + this.userDetail = userDetail; + } + + public int getId(){ + return this.id; + } + + public String getUserName(){ + return this.userName; + } + + public String getPassword(){ + return this.password; + } + + public UserDetail getUserDetail(){ + return this.userDetail; + } + + public boolean Pass(String password){ + return password.equals(this.password); + } +} \ No newline at end of file diff --git a/assigntment-02/H071191030/User.txt b/assigntment-02/H071191030/User.txt new file mode 100644 index 0000000..3dc2197 --- /dev/null +++ b/assigntment-02/H071191030/User.txt @@ -0,0 +1,5 @@ +1;ftrh;12345678 +2;arzk;qwert +3;ken;asdf +4;Naim;naim +5;farhan;Parhan \ No newline at end of file diff --git a/assigntment-02/H071191030/UserDetail.java b/assigntment-02/H071191030/UserDetail.java new file mode 100644 index 0000000..35b98f2 --- /dev/null +++ b/assigntment-02/H071191030/UserDetail.java @@ -0,0 +1,33 @@ +/** + * UserDetail + */ +public class UserDetail { + + private Integer id; + private String name; + private String dateOfBirth; + private String email; + + public UserDetail(Integer id, String name, String dateOfBirth, String email){ + this.id = id; + this.name = name; + this.dateOfBirth = dateOfBirth; + this.email = email; + } + + public int getId(){ + return this.id; + } + + public String getName(){ + return this.name; + } + + public String getDateOfBirth(){ + return this.dateOfBirth; + } + + public String getEmail(){ + return this.email; + } +} \ No newline at end of file diff --git a/assigntment-02/H071191030/UserDetail.txt b/assigntment-02/H071191030/UserDetail.txt new file mode 100644 index 0000000..908948c --- /dev/null +++ b/assigntment-02/H071191030/UserDetail.txt @@ -0,0 +1,5 @@ +1;Muhammad Fitrah;04-09-1998;fitrahm17h@student.unhas.ac.id +2;Muhammad Arizki;00-00-0000;arizkim17h@student.unhas.ac.id +3;Kennedy;00-02-2000;kennedy17h@student.unhas.ac.id +4;Muhammad Muflihun Naim;00-00-0000;naimmm17h@student.unhas.ac.id +5;Farhan Ramdhani;00-00-0000;ramdhanif17h@student.unhas.ac.id \ No newline at end of file