From 444473a1b166db264ade56c6419a92d581b43733 Mon Sep 17 00:00:00 2001 From: annisaputriaulia Date: Tue, 25 Feb 2020 07:43:45 +0800 Subject: [PATCH 1/2] assignment-01 --- assigntment-01/H071191029/mainTugasPBO.java | 65 ++++++++++++++ assigntment-01/H071191029/studentPBO.java | 99 +++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 assigntment-01/H071191029/mainTugasPBO.java create mode 100644 assigntment-01/H071191029/studentPBO.java diff --git a/assigntment-01/H071191029/mainTugasPBO.java b/assigntment-01/H071191029/mainTugasPBO.java new file mode 100644 index 0000000..b0ccaf6 --- /dev/null +++ b/assigntment-01/H071191029/mainTugasPBO.java @@ -0,0 +1,65 @@ +import java.util.HashMap; +import java.util.Map; + +public class mainTugasPBO { + + 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("Ilmu Sosial dan Ilmu Politik", "E"); + facultyMap.put("Ilmu Budaya", "F"); + facultyMap.put("Pertanian", "G"); + facultyMap.put("MIPA", "H"); + majorMap.put("Matematika", "01"); + majorMap.put("Statistika", "02"); + majorMap.put("Kimia", "03"); + majorMap.put("Fisika", "04"); + majorMap.put("Biologi", "05"); + majorMap.put("Geofisika", "06"); + majorMap.put("Ilmu Komputer", "07"); + + // Student student1 = new Student(); + // Student student2 = new Student(); + // Student student3 = new Student(); + + studentPBO student1 = new studentPBO(); + studentPBO student2 = new studentPBO(); + studentPBO student3 = new studentPBO(); + + student1.setFirstName("Annisa"); + student1.setLastName("Putri Aulia"); + student1.setRegisterYear(2019); + student1.setFaculty("MIPA"); + student1.setDepartment("Matematika"); + student1.setMajor("Ilmu Komputer"); + student1.setId(facultyMap, majorMap); + student1.setEmail(facultyMap); + + student2.setFirstName("Fitrah"); + student2.setLastName(""); + student2.setRegisterYear(2017); + student2.setFaculty("MIPA"); + student2.setDepartment("Matematika"); + student2.setMajor("Ilmu Komputer"); + student2.setId(facultyMap, majorMap); + student2.setEmail(facultyMap); + + student3.setFirstName("Kharitzmi"); + student3.setLastName(""); + student3.setRegisterYear(2017); + student3.setFaculty("MIPA"); + student3.setDepartment("Matematika"); + student3.setMajor("Ilmu Komputer"); + student3.setId(facultyMap, majorMap); + student3.setEmail(facultyMap); + + student1.description(); + student2.description(); + student3.description(); + + } +} \ No newline at end of file diff --git a/assigntment-01/H071191029/studentPBO.java b/assigntment-01/H071191029/studentPBO.java new file mode 100644 index 0000000..b4f0d32 --- /dev/null +++ b/assigntment-01/H071191029/studentPBO.java @@ -0,0 +1,99 @@ +import java.util.Random; +import java.util.Map; + +public class studentPBO{ + private String id; + private String firstName; + private String lastName; + private String email; + private int registerYear; + private String faculty; + private String department; + private String major; + + //SET + + 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 void setFaculty (String faculty){ + this.faculty = faculty; + } + public void setDepartment (String department){ + this.department = department; + } + public void setMajor (String major){ + this.major = major; + } + + //GET + + public String getId(){ + return id; + } + public String getEmail(){ + return email; + } + public String getFaculty (){ + return faculty; + } + public String getDepartement(){ + return department; + } + public String getMajor(){ + return major; + } + + //BEHAVIOUR + + public void setId(Map facultyMap,Map majorMap){ + String facultyCode = facultyMap.get(faculty); + String majorCode = majorMap.get(major); + int lastDigit = registerYear % 100; + + Random rand = new Random(); + int randDigit = rand.nextInt(60) + 1; + id = String.format("%s%s1%d1%03d", facultyCode,majorCode,lastDigit,randDigit); + } + public void setEmail(Map facultyMap ){ + String fullName = (firstName +" "+lastName).toLowerCase(); + String [] splitName = fullName.split(" "); + email = splitName[splitName.length - 1]; + for(int i = 0; i < splitName.length - 1; i++){ + email += splitName[i].charAt(0); + } + email += (registerYear % 100) + facultyMap.get(faculty).toLowerCase()+"@student.unhas.ac.id"; + } + + public String getFullName(){ + String fullName = (firstName + " " + lastName).toLowerCase(); + String [] splitName = fullName.split(" "); + String finalName = ""; + for (int i = 0; i < splitName.length; i++) { + finalName += splitName[i].substring(0, 1).toUpperCase() + splitName[i].substring(1, splitName[i].length()) + " "; + } + return finalName; + } + + public void description(){ + System.out.println("Nama : " + getFullName()); + System.out.println("NIM : " + getId()); + System.out.println("Email Mahasiswa : " + getEmail()); + System.out.println("Fakultas : " + getFaculty()); + System.out.println("Department : " + getDepartement()); + System.out.println("Program Studi : " + getMajor()); + System.out.println(); + } +} From 659047a930a588c91682916254602ee6ee6fab80 Mon Sep 17 00:00:00 2001 From: annisaputriaulia Date: Sat, 7 Mar 2020 00:14:43 +0800 Subject: [PATCH 2/2] tugas pbo --- PBO/oop-classroom-2020 | 1 + assigntment-01/H071191029/DataSource.java | 77 +++++++++++++++++++++++ assigntment-01/H071191029/Login.java | 40 ++++++++++++ assigntment-01/H071191029/Main.java | 7 +++ assigntment-01/H071191029/User.java | 29 +++++++++ assigntment-01/H071191029/UserDetail.java | 29 +++++++++ 6 files changed, 183 insertions(+) create mode 160000 PBO/oop-classroom-2020 create mode 100644 assigntment-01/H071191029/DataSource.java create mode 100644 assigntment-01/H071191029/Login.java create mode 100644 assigntment-01/H071191029/Main.java create mode 100644 assigntment-01/H071191029/User.java create mode 100644 assigntment-01/H071191029/UserDetail.java diff --git a/PBO/oop-classroom-2020 b/PBO/oop-classroom-2020 new file mode 160000 index 0000000..cecf703 --- /dev/null +++ b/PBO/oop-classroom-2020 @@ -0,0 +1 @@ +Subproject commit cecf703103417284f3447caa84bf56eb16a344e4 diff --git a/assigntment-01/H071191029/DataSource.java b/assigntment-01/H071191029/DataSource.java new file mode 100644 index 0000000..1af95f9 --- /dev/null +++ b/assigntment-01/H071191029/DataSource.java @@ -0,0 +1,77 @@ +import java.util.HashMap; +import java.util.ArrayList; +import java.util.Arrays; +import java.io.*; + +class DataSource { + static DataSource instance = null; + private HashMap userMap = new HashMap<>(); + private HashMap userDetailMap = new HashMap<>(); + + private DataSource() { + putUserDetail(); + putUser(); + } + + static public DataSource getInstance() { + if (instance == null) + instance = new DataSource(); + return instance; + } + + private void putUserDetail() { + BufferedReader reader = null; + try { + reader = new BufferedReader(new FileReader("src/userdetail.txt")); + String s; + while ((s = reader.readLine()) != null) { + ArrayList sList = new ArrayList(Arrays.asList(s.split(";"))); + UserDetail userDetail = new UserDetail(Integer.valueOf(sList.get(0)), sList.get(1), sList.get(2), + sList.get(3)); + userDetailMap.put(Integer.valueOf(sList.get(0)), userDetail); + } + } catch (IOException e) { + System.out.println(e.getMessage()); + } finally { + try { + if (reader != null) { + reader.close(); + } + } catch (IOException e) { + System.out.println(e); + } + } + } + + private void putUser() { + BufferedReader reader = null; + try { + reader = new BufferedReader(new FileReader("src/user.txt")); + String s; + while ((s = reader.readLine()) != null) { + ArrayList sList = new ArrayList(Arrays.asList(s.split(";"))); + User user = new User(Integer.valueOf(sList.get(0)), sList.get(1), sList.get(2), + userDetailMap.get(Integer.valueOf(sList.get(0)))); + userMap.put(sList.get(1), user); + } + } catch (IOException e) { + System.out.println(e.getMessage()); + } finally { + try { + if (reader != null) { + reader.close(); + } + } catch (IOException e) { + System.out.println(e); + } + } + } + + public User getUser(String key) { + return userMap.get(key); + } + + public UserDetail getUserDetail(Integer key) { + return userDetailMap.get(key); + } +} \ No newline at end of file diff --git a/assigntment-01/H071191029/Login.java b/assigntment-01/H071191029/Login.java new file mode 100644 index 0000000..25954d0 --- /dev/null +++ b/assigntment-01/H071191029/Login.java @@ -0,0 +1,40 @@ +import java.util.NoSuchElementException; + +class Login { + static Login instance = null; + private User user; + private UserDetail userDetail; + private DataSource dataSource; + + private Login() { + + } + + static public Login getInstance() { + if (instance == null) + instance = new Login(); + return instance; + } + + public void auth(String name, String pass) throws NoSuchElementException { + dataSource = DataSource.getInstance(); + try { + user = dataSource.getUser(name); + if (user.getPassword().equals(pass)) { + userDetail = user.getUserDeteail(); + } else { + System.out.println("wrong password"); + } + } catch (Exception e) { + throw new NoSuchElementException("user not found: " + name); + } + } + + public void status() { + if (userDetail != null) { + System.out.println(userDetail.getName()); + System.out.println(userDetail.getEmail()); + System.out.println(userDetail.getDateOfBirth()); + } + } +} \ No newline at end of file diff --git a/assigntment-01/H071191029/Main.java b/assigntment-01/H071191029/Main.java new file mode 100644 index 0000000..cb92df1 --- /dev/null +++ b/assigntment-01/H071191029/Main.java @@ -0,0 +1,7 @@ +public class Main { + public static void main(String[] args) { + Login login = Login.getInstance(); + login.auth("naim", "Naim"); + login.status(); + } +} \ No newline at end of file diff --git a/assigntment-01/H071191029/User.java b/assigntment-01/H071191029/User.java new file mode 100644 index 0000000..2007baa --- /dev/null +++ b/assigntment-01/H071191029/User.java @@ -0,0 +1,29 @@ +class User { + private Integer id; + private String username; + private String password; + private UserDetail userDetail; + + User(Integer id, String userName, String password, UserDetail userDetail) { + this.id = id; + this.username = userName; + this.password = password; + this.userDetail = userDetail; + } + + public Integer getId() { + return id; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public UserDetail getUserDeteail() { + return userDetail; + } +} \ No newline at end of file diff --git a/assigntment-01/H071191029/UserDetail.java b/assigntment-01/H071191029/UserDetail.java new file mode 100644 index 0000000..76ff1d6 --- /dev/null +++ b/assigntment-01/H071191029/UserDetail.java @@ -0,0 +1,29 @@ +public class UserDetail { + private Integer id; + private String name; + private String dateOfBirth; + private String email; + + UserDetail(Integer id, String name, String dateOfBirth, String email) { + this.id = id; + this.name = name; + this.dateOfBirth = dateOfBirth; + this.email = email; + } + + public Integer 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