diff --git a/H071191018/Main.java b/H071191018/Main.java new file mode 100644 index 0000000..3187be6 --- /dev/null +++ b/H071191018/Main.java @@ -0,0 +1,58 @@ +import java.util.*; +class Main{ + public static void main(String[] args) { + Map facultyMap = new HashMap<>(); + Map majorMap = new HashMap<>(); + facultyMap.put("EKONOMI DAN BISNIS", "A"); + facultyMap.put("KEDOKTERAN", "B"); + facultyMap.put("PETERNAKAN", "C"); + facultyMap.put("HUKUM", "D"); + facultyMap.put("FARMASI", "E"); + facultyMap.put("KEPERAWATAN", "F"); + facultyMap.put("PERTANIAN", "G"); + facultyMap.put("MIPA", "H"); + majorMap.put("Biologi", "01"); + majorMap.put("Fisika", "02"); + majorMap.put("Kimia", "03"); + majorMap.put("Geofisika", "04"); + majorMap.put("Statistika", "05"); + majorMap.put("Aktuaria", "06"); + majorMap.put("Ilmu Komputer", "07"); + + Student student1 = new Student(); + Student student2 = new Student(); + Student student3 = new Student(); + + student1.setFirstName("mUHammAd"); + student1.setLastName("fITRAH"); + student1.setRegisterYear(2017); + student1.setFaculty("MIPA"); + student1.setDepartment("Matematika"); + student1.setMajor("Ilmu Komputer"); + student1.setId(facultyMap, majorMap); + student1.setEmail(facultyMap); + + student2.setFirstName("KENNEDY"); + student2.setLastName(""); + student2.setRegisterYear(2017); + student2.setFaculty("MIPA"); + student2.setDepartment("Matematika"); + student2.setMajor("Ilmu Komputer"); + student2.setId(facultyMap, majorMap); + student2.setEmail(facultyMap); + + student3.setFirstName("Khawaritzmi"); + student3.setLastName("abdallah ahmad"); + 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/H071191018/Student.java b/H071191018/Student.java new file mode 100644 index 0000000..83bc5cd --- /dev/null +++ b/H071191018/Student.java @@ -0,0 +1,130 @@ +import java.util.*; + + +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 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 this.id; + } + public String getFirstName(){ + return this.firstName; + } + + public String getLastName(){ + return this.lastName; + } + + public String getEmail(){ + return this.email; + } + + public int getRegisterYear(){ + return this.registerYear; + } + + public String getDepartment(){ + return this.department; + + } + + public String getFaculty(){ + return this.faculty; + } + + public String getMajor(){ + return this.major; + } + + public void setId( Map facultyMap , Map majorMap){ + Random rand = new Random(); + this.id = String.format("%s%s1%d1%03d" , + facultyMap.get(getFaculty()) , + majorMap.get(getMajor()), + this.registerYear % 100, + rand.nextInt(60) + 1 + ); + + } + + public void setEmail(Map facultyMap){ + String fullname = (this.firstName + " " + this.lastName).toLowerCase(); + String[] splitName = fullname.split(" "); + this.email = splitName[splitName.length - 1]; + + for (int i = 0; i < splitName.length - 1 ; i++) { + this.email += splitName[i].charAt(0); + } + this.email += String.format("%d%s@student.unhas.ac.id", + this.registerYear % 100, + facultyMap.get(getFaculty()) + ); + + + // String fullName[] = (firstName.toLowerCase() + " " + lastName.toLowerCase()).split(" "); + // String lastName = fullName[fullName.length - 1]; + // String firstTw = ""; + // for (int i = 0; i < fullName.length - 1; i++) { + // firstTw += fullName[i].charAt(0); + // } + // email = String.format("%s%s%s@student.unhas.ac.id", + // lastName, firstTw,this.registerYear,facultyMap.get(faculty).toLowerCase()); + } + + public String getFullName(){ + String fullName = (this.firstName + " " + this.lastName).toLowerCase(); + String[] splittedName = fullName.split(" "); + String name = ""; + for (int i = 0; i < splittedName.length; i++) { + name += splittedName[i].substring(0, 1).toUpperCase() + splittedName[i].substring(1, splittedName[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()); + + } + + +} +