From 27ae8103f75c2dc521041d06d4c6239dca34d9db Mon Sep 17 00:00:00 2001 From: izzazzhr Date: Mon, 24 Feb 2020 11:11:21 +0800 Subject: [PATCH 1/6] added praktikum 1 --- assigntment-01/H071191030/Main.java | 82 +++++++++++++++++ assigntment-01/H071191030/Student.java | 122 +++++++++++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 assigntment-01/H071191030/Main.java create mode 100644 assigntment-01/H071191030/Student.java 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 From 49506d7c610a443c0ef3486ca4d32321c9dc6c94 Mon Sep 17 00:00:00 2001 From: izzazzhr Date: Fri, 6 Mar 2020 23:16:19 +0800 Subject: [PATCH 2/6] added Assigntment2 --- assigntment-02/App.java | 12 +++++ assigntment-02/DataSource.java | 99 ++++++++++++++++++++++++++++++++++ assigntment-02/Login.java | 53 ++++++++++++++++++ assigntment-02/User.java | 37 +++++++++++++ assigntment-02/User.txt | 5 ++ assigntment-02/UserDetail.java | 33 ++++++++++++ assigntment-02/UserDetail.txt | 5 ++ 7 files changed, 244 insertions(+) create mode 100644 assigntment-02/App.java create mode 100644 assigntment-02/DataSource.java create mode 100644 assigntment-02/Login.java create mode 100644 assigntment-02/User.java create mode 100644 assigntment-02/User.txt create mode 100644 assigntment-02/UserDetail.java create mode 100644 assigntment-02/UserDetail.txt diff --git a/assigntment-02/App.java b/assigntment-02/App.java new file mode 100644 index 0000000..3b1944e --- /dev/null +++ b/assigntment-02/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/DataSource.java b/assigntment-02/DataSource.java new file mode 100644 index 0000000..098c074 --- /dev/null +++ b/assigntment-02/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/Login.java b/assigntment-02/Login.java new file mode 100644 index 0000000..94eb00e --- /dev/null +++ b/assigntment-02/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/User.java b/assigntment-02/User.java new file mode 100644 index 0000000..7ab8c6c --- /dev/null +++ b/assigntment-02/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/User.txt b/assigntment-02/User.txt new file mode 100644 index 0000000..3dc2197 --- /dev/null +++ b/assigntment-02/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/UserDetail.java b/assigntment-02/UserDetail.java new file mode 100644 index 0000000..35b98f2 --- /dev/null +++ b/assigntment-02/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/UserDetail.txt b/assigntment-02/UserDetail.txt new file mode 100644 index 0000000..908948c --- /dev/null +++ b/assigntment-02/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 From 14a415b034cb3c14f91cf0bcb9732d33c3939a34 Mon Sep 17 00:00:00 2001 From: izzazzhr Date: Fri, 6 Mar 2020 23:27:21 +0800 Subject: [PATCH 3/6] Removed folder --- assigntment-02/App.java | 12 ----- assigntment-02/DataSource.java | 99 ---------------------------------- assigntment-02/Login.java | 53 ------------------ assigntment-02/User.java | 37 ------------- assigntment-02/User.txt | 5 -- assigntment-02/UserDetail.java | 33 ------------ assigntment-02/UserDetail.txt | 5 -- 7 files changed, 244 deletions(-) delete mode 100644 assigntment-02/App.java delete mode 100644 assigntment-02/DataSource.java delete mode 100644 assigntment-02/Login.java delete mode 100644 assigntment-02/User.java delete mode 100644 assigntment-02/User.txt delete mode 100644 assigntment-02/UserDetail.java delete mode 100644 assigntment-02/UserDetail.txt diff --git a/assigntment-02/App.java b/assigntment-02/App.java deleted file mode 100644 index 3b1944e..0000000 --- a/assigntment-02/App.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * 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/DataSource.java b/assigntment-02/DataSource.java deleted file mode 100644 index 098c074..0000000 --- a/assigntment-02/DataSource.java +++ /dev/null @@ -1,99 +0,0 @@ -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/Login.java b/assigntment-02/Login.java deleted file mode 100644 index 94eb00e..0000000 --- a/assigntment-02/Login.java +++ /dev/null @@ -1,53 +0,0 @@ -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/User.java b/assigntment-02/User.java deleted file mode 100644 index 7ab8c6c..0000000 --- a/assigntment-02/User.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * 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/User.txt b/assigntment-02/User.txt deleted file mode 100644 index 3dc2197..0000000 --- a/assigntment-02/User.txt +++ /dev/null @@ -1,5 +0,0 @@ -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/UserDetail.java b/assigntment-02/UserDetail.java deleted file mode 100644 index 35b98f2..0000000 --- a/assigntment-02/UserDetail.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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/UserDetail.txt b/assigntment-02/UserDetail.txt deleted file mode 100644 index 908948c..0000000 --- a/assigntment-02/UserDetail.txt +++ /dev/null @@ -1,5 +0,0 @@ -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 From 56e9c3fd5629245865ef259c0f30104559643986 Mon Sep 17 00:00:00 2001 From: izzazzhr Date: Fri, 6 Mar 2020 23:30:00 +0800 Subject: [PATCH 4/6] added assigntment02 --- assigntment-02/H071191030/App.java | 12 +++ assigntment-02/H071191030/DataSource.java | 99 +++++++++++++++++++++++ assigntment-02/H071191030/Login.java | 53 ++++++++++++ assigntment-02/H071191030/User.java | 37 +++++++++ assigntment-02/H071191030/User.txt | 5 ++ assigntment-02/H071191030/UserDetail.java | 33 ++++++++ assigntment-02/H071191030/UserDetail.txt | 5 ++ 7 files changed, 244 insertions(+) create mode 100644 assigntment-02/H071191030/App.java create mode 100644 assigntment-02/H071191030/DataSource.java create mode 100644 assigntment-02/H071191030/Login.java create mode 100644 assigntment-02/H071191030/User.java create mode 100644 assigntment-02/H071191030/User.txt create mode 100644 assigntment-02/H071191030/UserDetail.java create mode 100644 assigntment-02/H071191030/UserDetail.txt 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 From 6231a310117b2fba055a3ee82a9aed00371a4992 Mon Sep 17 00:00:00 2001 From: izzazzhr Date: Fri, 6 Mar 2020 23:37:04 +0800 Subject: [PATCH 5/6] removed --- assigntment-02/H071191030/App.java | 12 --- assigntment-02/H071191030/DataSource.java | 99 ----------------------- assigntment-02/H071191030/Login.java | 53 ------------ assigntment-02/H071191030/User.java | 37 --------- assigntment-02/H071191030/User.txt | 5 -- assigntment-02/H071191030/UserDetail.java | 33 -------- assigntment-02/H071191030/UserDetail.txt | 5 -- 7 files changed, 244 deletions(-) delete mode 100644 assigntment-02/H071191030/App.java delete mode 100644 assigntment-02/H071191030/DataSource.java delete mode 100644 assigntment-02/H071191030/Login.java delete mode 100644 assigntment-02/H071191030/User.java delete mode 100644 assigntment-02/H071191030/User.txt delete mode 100644 assigntment-02/H071191030/UserDetail.java delete mode 100644 assigntment-02/H071191030/UserDetail.txt diff --git a/assigntment-02/H071191030/App.java b/assigntment-02/H071191030/App.java deleted file mode 100644 index 3b1944e..0000000 --- a/assigntment-02/H071191030/App.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * 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 deleted file mode 100644 index 098c074..0000000 --- a/assigntment-02/H071191030/DataSource.java +++ /dev/null @@ -1,99 +0,0 @@ -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 deleted file mode 100644 index 94eb00e..0000000 --- a/assigntment-02/H071191030/Login.java +++ /dev/null @@ -1,53 +0,0 @@ -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 deleted file mode 100644 index 7ab8c6c..0000000 --- a/assigntment-02/H071191030/User.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * 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 deleted file mode 100644 index 3dc2197..0000000 --- a/assigntment-02/H071191030/User.txt +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index 35b98f2..0000000 --- a/assigntment-02/H071191030/UserDetail.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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 deleted file mode 100644 index 908948c..0000000 --- a/assigntment-02/H071191030/UserDetail.txt +++ /dev/null @@ -1,5 +0,0 @@ -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 From ad15fc99c76d2e488477e0138312c4b009975492 Mon Sep 17 00:00:00 2001 From: izzazzhr Date: Fri, 6 Mar 2020 23:38:40 +0800 Subject: [PATCH 6/6] added assigntment2 --- assigntment-02/H071191030/App.java | 12 +++ assigntment-02/H071191030/DataSource.java | 99 +++++++++++++++++++++++ assigntment-02/H071191030/Login.java | 53 ++++++++++++ assigntment-02/H071191030/User.java | 37 +++++++++ assigntment-02/H071191030/User.txt | 5 ++ assigntment-02/H071191030/UserDetail.java | 33 ++++++++ assigntment-02/H071191030/UserDetail.txt | 5 ++ 7 files changed, 244 insertions(+) create mode 100644 assigntment-02/H071191030/App.java create mode 100644 assigntment-02/H071191030/DataSource.java create mode 100644 assigntment-02/H071191030/Login.java create mode 100644 assigntment-02/H071191030/User.java create mode 100644 assigntment-02/H071191030/User.txt create mode 100644 assigntment-02/H071191030/UserDetail.java create mode 100644 assigntment-02/H071191030/UserDetail.txt 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