diff --git a/H071191020/Praktikum-2/Box.java b/H071191020/Praktikum-2/Box.java new file mode 100644 index 0000000..c1a9ee2 --- /dev/null +++ b/H071191020/Praktikum-2/Box.java @@ -0,0 +1,29 @@ +class Box { + + private double width; + private double height; + private double depth; + private double mass; + private double density; + + public Box (double width, double height, double depth) { + this.width = width; + this.height = height; + this.depth = depth; + } + public void setWidth(double width) { + this.width = width; + } + public void setHeight(double height) { + this.height = height; + } + public void setDepth (double depth) { + this.depth = depth; + } + public void setMass (double mass) { + this.mass = mass; + } + public double getDensity() { + return mass/(width*height*depth); + } +} \ No newline at end of file diff --git a/H071191020/Praktikum-2/BoxMain.java b/H071191020/Praktikum-2/BoxMain.java new file mode 100644 index 0000000..9ebe019 --- /dev/null +++ b/H071191020/Praktikum-2/BoxMain.java @@ -0,0 +1,17 @@ +import java.util.Scanner; + +public class BoxMain { + + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + double width = input.nextDouble(); + double height = input.nextDouble(); + double depth = input.nextDouble(); + double mass = input.nextDouble(); + Box box = new Box(width, height, depth); + box.setMass(mass); + System.out.println("Massa Jenis = " + box.getDensity()); + box.setMass(mass*2); + System.out.println("Massa Jenis = " + box.getDensity()); + } +} \ No newline at end of file diff --git a/H071191020/Praktikum-2/Main.java b/H071191020/Praktikum-2/Main.java new file mode 100644 index 0000000..4752d85 --- /dev/null +++ b/H071191020/Praktikum-2/Main.java @@ -0,0 +1,16 @@ +public class Main { + + public static void main(String[] args) { + int defense = 15; + int attack = 30; + Player player1 = new Player ("Mino", attack, defense); + Player player2 = new Player ("Hilda", defense); + + player2.setAttackPower(35); + + player1.getDamage(player2); + player2.getDamage(player1); + player1.status(); + player2.status(); + } +} \ No newline at end of file diff --git a/H071191020/Praktikum-2/Player.java b/H071191020/Praktikum-2/Player.java new file mode 100644 index 0000000..394e24c --- /dev/null +++ b/H071191020/Praktikum-2/Player.java @@ -0,0 +1,39 @@ +class Player { + + private final String name; + private int hp; + private int attackPower; + private final int defense = 100; + defense = 10; + + public Player(final String name, final int defense) { + this.name = name; + this.defense = defense; + hp = 100; + } + + public Player(final String name, final int attackPower, final int defense) { + this.name = name; + this.attackPower = attackPower; + this.defense = defense; + hp = 100; + } + + public void setAttackPower(final int attackPower) { + this.attackPower = attackPower; + } + + public int getAttackPower() { + return attackPower; + } + + public void getDamage(final Player enemy) { + hp = hp - (enemy.getAttackPower()-defense); + } + public void status () { + System.out.println(name + " Status"); + System.out.println("HP = " + hp); + System.out.println("Defense = " + defense); + System.out.println("Attack = " + attackPower); + } +} \ No newline at end of file diff --git a/H071191020/Praktikum_1/Lampu.class b/H071191020/Praktikum_1/Lampu.class new file mode 100644 index 0000000..97c1958 Binary files /dev/null and b/H071191020/Praktikum_1/Lampu.class differ diff --git a/H071191020/Praktikum_1/Lampu.java b/H071191020/Praktikum_1/Lampu.java new file mode 100644 index 0000000..ee08c8e --- /dev/null +++ b/H071191020/Praktikum_1/Lampu.java @@ -0,0 +1,28 @@ +class Lampu { + + private boolean blueIsOn; + private boolean redIsOn; + + public void turnOn() { + if (blueIsOn && redIsOn) { + blueIsOn = true; + redIsOn= false; + } else if(blueIsOn && !redIsOn) { + blueIsOn = false; + redIsOn = true; + } else { + blueIsOn = true; + redIsOn = false; + } + } + public void turnOff() { + blueIsOn = false; + redIsOn = false; + } + + public void getState() { + System.out.println(blueIsOn ? "Biru ON" : "Biru OFF"); + System.out.println(redIsOn ? "Merah ON" : "Merah OFF"); + System.out.println(); + } +} \ No newline at end of file diff --git a/H071191020/Praktikum_1/Main.class b/H071191020/Praktikum_1/Main.class new file mode 100644 index 0000000..0fadf1d Binary files /dev/null and b/H071191020/Praktikum_1/Main.class differ diff --git a/H071191020/Praktikum_1/Main.java b/H071191020/Praktikum_1/Main.java new file mode 100644 index 0000000..c82e599 --- /dev/null +++ b/H071191020/Praktikum_1/Main.java @@ -0,0 +1,19 @@ +/** + * Main + */ +public class Main { + + public static void main(String[] args) { + Lampu lampu1 = new Lampu(); + lampu1.turnOn(); + lampu1.getState(); + lampu1.turnOn(); + lampu1.getState(); + lampu1.turnOn(); + lampu1.getState(); + lampu1.turnOn(); + lampu1.getState(); + lampu1.turnOff(); + lampu1.getState(); + } +} \ No newline at end of file diff --git a/assigntment-01/H071191020/Main.class b/assigntment-01/H071191020/Main.class new file mode 100644 index 0000000..3fd357b Binary files /dev/null and b/assigntment-01/H071191020/Main.class differ diff --git a/assigntment-01/H071191020/Main.java b/assigntment-01/H071191020/Main.java new file mode 100644 index 0000000..2d9cf61 --- /dev/null +++ b/assigntment-01/H071191020/Main.java @@ -0,0 +1,58 @@ +import java.util.*; +public class Main{ + public static void main(String[] args) { + Map facultyMap = new HashMap<>(); + Map majorMap = new HashMap<>(); + facultyMap.put("Nama Fakultas Lain", "A"); + facultyMap.put("Nama Fakultas Lain", "B"); + facultyMap.put("Nama Fakultas Lain", "C"); + facultyMap.put("Nama Fakultas Lain", "D"); + facultyMap.put("Nama Fakultas Lain", "E"); + facultyMap.put("Nama Fakultas Lain", "F"); + facultyMap.put("Nama Fakultas Lain", "G"); + facultyMap.put("MIPA", "H"); + majorMap.put("Prodi Lain", "01"); + majorMap.put("Prodi Lain", "02"); + majorMap.put("Prodi Lain", "03"); + majorMap.put("Prodi Lain", "04"); + majorMap.put("Prodi Lain", "05"); + majorMap.put("Prodi Lain", "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/assigntment-01/H071191020/Student.class b/assigntment-01/H071191020/Student.class new file mode 100644 index 0000000..9e370b3 Binary files /dev/null and b/assigntment-01/H071191020/Student.class differ diff --git a/assigntment-01/H071191020/Student.java b/assigntment-01/H071191020/Student.java new file mode 100644 index 0000000..49f5dc9 --- /dev/null +++ b/assigntment-01/H071191020/Student.java @@ -0,0 +1,77 @@ +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 departemen; + private String major; + + public void setId(MapfacultyMap, MapmajorMap){ + Random randoms = new Random(); + this.id = facultyMap.get(faculty) + majorMap.get(major) + "1" + String.valueOf(registerYear).substring(2) + "1" + String.format("%03d", randoms.nextInt(061)); + } + public String getId(){ + return id; + } + public void setFirstName(String firstName){ + + this.firstName = firstName; + } + public void setLastName(String lastName){ + this.lastName = lastName; + } + 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) + " "; + } + return Name; + } + public void setEmail(MapfacultyMap){ + String fullName[] = (firstName.toLowerCase() + " " + lastName.toLowerCase()).split(" "); + String Name = ""; + for (int i = 0; i < fullName.length -1;i++) { + Name+= fullName[i].substring(0,1); + } + this.email = (fullName[fullName.length - 1]+ Name + String.valueOf(registerYear).substring(2) + facultyMap.get(faculty) + "@student.unhas.ac.id").toLowerCase(); + } + public String getEmail(String email){ + return email; + } + public void setRegisterYear(Integer registerYear){ + this.registerYear = registerYear; + } + public void setFaculty(String faculty){ + this.faculty = faculty; + } + public String getFaculty(String faculty){ + return faculty; + } + public void setDepartment(String departemen){ + this.departemen = departemen; + } + public String getDepartment(String departemen){ + return departemen; + } + public void setMajor(String major){ + this.major = major; + } + public String getMajor(){ + return major; + } + public void description() { + System.out.println("Nama : " + getFullName() ); + System.out.println("NIM : " + getId()); + System.out.println("Email Mahasiswa : " + getEmail(email)); + System.out.println("Fakultas : " + getFaculty(faculty)); + System.out.println("Departemen : " + getDepartment(departemen)); + System.out.println("Program Studi : " + getMajor()); + System.out.println(); + } +} \ No newline at end of file