diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Hands-On-OOP-2022.iml b/.idea/Hands-On-OOP-2022.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/.idea/Hands-On-OOP-2022.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..c07f4d8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..72f34db --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Mesach Harmasendro_ITB/out/production/Hands-On-OOP-2022/App.class b/Mesach Harmasendro_ITB/out/production/Hands-On-OOP-2022/App.class new file mode 100644 index 0000000..d9f6aa1 Binary files /dev/null and b/Mesach Harmasendro_ITB/out/production/Hands-On-OOP-2022/App.class differ diff --git a/Mesach Harmasendro_ITB/out/production/Hands-On-OOP-2022/GoldUser.class b/Mesach Harmasendro_ITB/out/production/Hands-On-OOP-2022/GoldUser.class new file mode 100644 index 0000000..61d5579 Binary files /dev/null and b/Mesach Harmasendro_ITB/out/production/Hands-On-OOP-2022/GoldUser.class differ diff --git a/Mesach Harmasendro_ITB/out/production/Hands-On-OOP-2022/PlatinumUser.class b/Mesach Harmasendro_ITB/out/production/Hands-On-OOP-2022/PlatinumUser.class new file mode 100644 index 0000000..5237785 Binary files /dev/null and b/Mesach Harmasendro_ITB/out/production/Hands-On-OOP-2022/PlatinumUser.class differ diff --git a/Mesach Harmasendro_ITB/out/production/Hands-On-OOP-2022/User.class b/Mesach Harmasendro_ITB/out/production/Hands-On-OOP-2022/User.class new file mode 100644 index 0000000..2a9d849 Binary files /dev/null and b/Mesach Harmasendro_ITB/out/production/Hands-On-OOP-2022/User.class differ diff --git a/Mesach Harmasendro_ITB/out/production/Hands-On-OOP-2022/UserInterface.class b/Mesach Harmasendro_ITB/out/production/Hands-On-OOP-2022/UserInterface.class new file mode 100644 index 0000000..deb44c4 Binary files /dev/null and b/Mesach Harmasendro_ITB/out/production/Hands-On-OOP-2022/UserInterface.class differ diff --git a/Mesach Harmasendro_ITB/src/App.java b/Mesach Harmasendro_ITB/src/App.java new file mode 100644 index 0000000..18da350 --- /dev/null +++ b/Mesach Harmasendro_ITB/src/App.java @@ -0,0 +1,242 @@ +import java.util.LinkedList; +import java.util.List; +import java.util.Scanner; + +// Program bank sederhana +// +// Terdapat fitur login dan register lalu setelah login akan ada pilihan menu +// cek saldo, deposit, dan tarik tunai. +// +// Implementasi OOP ada pada user dimana user terdapat tiga jenis yaitu standard, gold, dan platinum +// +// Tersedia 3 akun/user bawaan untuk tes: +// - mch123, 1234 (standard) +// - abg123, 1234 (gold) +// - dxg123, 1234 (platinum) +// +// Program berbasis terminal jadi dijalankan di terminal + +public class App { + + public static Scanner sc = new Scanner(System.in); + public static User user = null; + public static List users = new LinkedList<>(); + + public static void main(String[] args) { + + users.addAll(List.of(new User(500, "mch123", 1234), new GoldUser(500, "abg123", 1234), new PlatinumUser(500, "dxg123", 1234))); + + while (user == null) { + loginPage(); + } + + while (true) { + mainPage(); + int input = sc.nextInt(); + if (input == 1){ + while (true) { + user.cekSaldo(); + String input2 = sc.next(); + if (input2.equals("y")){ + break; + } + } + } else if (input == 2) { + try { + Boolean a = user.tarikTunai(); + while (!a) { + a = user.tarikTunai(); + } + } catch (Exception e){ + + } + } else if (input == 3) { + try { + Boolean a = user.deposit(); + while (!a) { + a = user.deposit(); + } + } catch (Exception e){ + + } + }else if (input == 4) { + user = null; + loginPage(); + } + } + } + + public static void loginPage(){ + System.out.println("LOGIN"); + System.out.println("=====\n"); + System.out.println("1.\tSign in"); + System.out.println("2.\tRegister"); + System.out.println("3.\tExit\n"); + System.out.print("Masukan pilihan : "); + int input = sc.nextInt(); + + if (input == 2){ + register(); + } else if (input == 1){ + signIn(); + } else if (input == 3) { + System.exit(0); + } + } + + public static void signIn(){ + System.out.println("\nSIGN IN"); + System.out.println("=========================\n"); + System.out.print("Username: "); + String username = sc.next(); + sc.nextLine(); + System.out.print("Password: "); + int pass = sc.nextInt(); + sc.nextLine(); + System.out.println(""); + + for (User u: users){ + if (u.getUsername().equals(username)){ + if (u.getPass() == pass){ + user = u; + return; + } else if (u.getPass() != pass) { + System.out.println("password salah"); + loginPage(); + } + } + } + System.out.println("username salah"); + loginPage(); + } + + public static void mainPage(){ + System.out.println("\nWELCOME TO BANKING APP"); + System.out.println("=========================\n"); + System.out.println("1.\tCek saldo"); + System.out.println("2.\tTarik tunai"); + System.out.println("3.\tTambah deposit"); + System.out.println("4.\tKeluar\n"); + System.out.print("Masukan pilihanmu : "); + } + + public static void register(){ + String username; + int password; + int deposit; + while (true) { + System.out.println("REGISTER"); + System.out.println("=====\n"); + System.out.print("1.\tUsername (6 karakter): "); + username = sc.next(); + sc.nextLine(); + System.out.print("2.\tPassword (4 angka):"); + password = sc.nextInt(); + sc.nextLine(); + System.out.print("3.\tConfirm password : "); + int cpass = sc.nextInt(); + sc.nextLine(); + + boolean b = true; + for (User u: users){ + if (u.getUsername().equals(username)){ + System.out.println("Username telah digunakan"); + b = false; + break; + } + } + + if (username.length() <= 6 && password <= 9999 && password == cpass && b){ + break; + } + + if (username.length() > 6) { + System.out.println("Invalid username"); + } + if (password > 9999) { + System.out.println("Invalid password"); + } + if (password != cpass) { + System.out.println("password dan confirm password harus sama"); + } + + + System.out.print("Apakah mau mengulang? (y/n): "); + String inp = sc.next(); + if (!inp.equals("y")){ + loginPage(); + return; + } + } + + while (true){ + System.out.println("REGISTER"); + System.out.println("PEMILIHAN MEMBER"); + System.out.println("================\n"); + System.out.println("1.\tSTANDARD"); + System.out.println("2.\tGOLD"); + System.out.println("3.\tPLATINUM"); + System.out.println("4.\tKembali\n"); + System.out.print("Masukan pilihan : "); + int inp2 = sc.nextInt(); + + if (inp2 == 1){ + while(true) { + System.out.println("STANDARD MEMBER"); + System.out.println("================\n"); + System.out.println("Minimal deposit $50"); + System.out.print("Deposit awal ('-1' untuk kembali): "); + deposit = sc.nextInt(); + if (deposit >= 50) { + User newUser = new User(deposit, username, password); + users.add(newUser); + System.out.println("*** REGISTRASI BERHASIL ***"); + loginPage(); + return; + } else if (deposit == -1){ + break; + } + } + } else if (inp2 == 2){ + while(true) { + System.out.println("GOLD MEMBER"); + System.out.println("================\n"); + System.out.println("Minimal deposit $250"); + System.out.println("Deposit awal ('-1' untuk kembali): "); + deposit = sc.nextInt(); + if (deposit >= 250) { + User newUser = new GoldUser(deposit, username, password); + users.add(newUser); + System.out.println("*** REGISTRASI BERHASIL ***"); + loginPage(); + return; + } else if (deposit == -1){ + break; + } + } + } else if (inp2 == 3){ + while(true) { + System.out.println("PLATINUM MEMBER"); + System.out.println("================\n"); + System.out.println("Minimal deposit $500"); + System.out.println("Deposit awal ('-1' untuk kembali): "); + deposit = sc.nextInt(); + if (deposit >= 500) { + User newUser = new PlatinumUser(deposit, username, password); + users.add(newUser); + System.out.println("*** REGISTRASI BERHASIL ***"); + loginPage(); + return; + } else if (deposit == -1){ + break; + } + } + } else if (inp2 == 4){ + loginPage(); + return; + } else { + System.out.println("Input salah silahkan ulangi kembali"); + } + } + } +} diff --git a/Mesach Harmasendro_ITB/src/GoldUser.java b/Mesach Harmasendro_ITB/src/GoldUser.java new file mode 100644 index 0000000..f411dca --- /dev/null +++ b/Mesach Harmasendro_ITB/src/GoldUser.java @@ -0,0 +1,60 @@ +public class GoldUser extends User{ + public GoldUser(int saldo, String name, int pass) { + super(saldo, name, pass); + } + + @Override + public void cekSaldo() { + System.out.println("CEK SALDO"); + System.out.println(" ** GOLD MEMBER **"); + System.out.println("========\n"); + System.out.println("Saldo : $" + super.getSaldo()); + System.out.print("Apakah mau kembali ke halaman utama (y/n) : "); + } + + @Override + public Boolean tarikTunai() { + System.out.println("TARIK TUNAI"); + System.out.println(" ** GOLD MEMBER **"); + System.out.println("========\n"); + System.out.println("Maksimal penarikan $1000"); + System.out.print("Masukan jumlah uang ('q untuk keluar'): "); + String input = App.sc.next(); + if (input.equals("q")) return null; + if (Integer.parseInt(input) > 1000){ + System.out.println("Melebihi batas penarikan tunai ($1000)"); + return false; + } else { + super.setSaldo(super.getSaldo() - Integer.parseInt(input)); + System.out.println("Tarik tunai berhasil"); + System.out.println("========"); + System.out.print("Apakah mau kembali ke halaman utama (y/n) : "); + String input2 = App.sc.next(); + return input2.equals("y"); + + } + } + + @Override + public Boolean deposit() { + System.out.println("DEPOSIT"); + System.out.println(" ** GOLD MEMBER **"); + System.out.println("========\n"); + System.out.println("Minimal deposit $50"); + System.out.print("Masukan jumlah uang ('q untuk keluar'): "); + String input = App.sc.next(); + if (input.equals("q")) return null; + if (Integer.parseInt(input) < 50) { + System.out.println("Deposit gagal!!!"); + System.out.println("Minimal deposit $50"); + return false; + } else { + super.setSaldo(super.getSaldo() + Integer.parseInt(input)); + System.out.println("deposit berhasil"); + System.out.println("========"); + System.out.print("Apakah mau kembali ke halaman utama (y/n) : "); + String input2 = App.sc.next(); + return input2.equals("y"); + } + } +} diff --git a/Mesach Harmasendro_ITB/src/PlatinumUser.java b/Mesach Harmasendro_ITB/src/PlatinumUser.java new file mode 100644 index 0000000..e33a356 --- /dev/null +++ b/Mesach Harmasendro_ITB/src/PlatinumUser.java @@ -0,0 +1,62 @@ +public class PlatinumUser extends User{ + + public PlatinumUser(int saldo, String name, int pass) { + super(saldo, name, pass); + } + + @Override + public void cekSaldo() { + System.out.println("CEK SALDO"); + System.out.println(" ** PLATINUM MEMBER **"); + System.out.println("========\n"); + System.out.println("Saldo : $" + super.getSaldo()); + System.out.print("Apakah mau kembali ke halaman utama (y/n) : "); + } + + @Override + public Boolean tarikTunai() { + System.out.println("TARIK TUNAI"); + System.out.println(" ** PLATINUM MEMBER **"); + System.out.println("========\n"); + System.out.println("Maksimal penarikan $5000"); + System.out.print("Masukan jumlah uang ('q untuk keluar'): "); + String input = App.sc.next(); + if (input.equals("q")) return null; + if (Integer.parseInt(input) > 5000){ + System.out.println("Melebihi batas penarikan tunai ($5000)"); + return false; + } else { + super.setSaldo(super.getSaldo() - Integer.parseInt(input)); + System.out.println("Tarik tunai berhasil"); + System.out.println("========"); + System.out.print("Apakah mau kembali ke halaman utama (y/n) : "); + String input2 = App.sc.next(); + return input2.equals("y"); + + } + } + + @Override + public Boolean deposit() { + System.out.println("DEPOSIT"); + System.out.println(" ** PLATINUM MEMBER **"); + System.out.println("========\n"); + System.out.println("Minimal deposit $50"); + System.out.print("Masukan jumlah uang ('q untuk keluar'): "); + String input = App.sc.next(); + if (input.equals("q")) return null; + if (Integer.parseInt(input) < 50) { + System.out.println("Deposit gagal!!!"); + System.out.println("Minimal deposit $50"); + return false; + } else { + super.setSaldo(super.getSaldo() + Integer.parseInt(input)); + System.out.println("deposit berhasil"); + System.out.println("========"); + System.out.print("Apakah mau kembali ke halaman utama (y/n) : "); + String input2 = App.sc.next(); + return input2.equals("y"); + } + } +} + diff --git a/Mesach Harmasendro_ITB/src/User.java b/Mesach Harmasendro_ITB/src/User.java new file mode 100644 index 0000000..d48032b --- /dev/null +++ b/Mesach Harmasendro_ITB/src/User.java @@ -0,0 +1,86 @@ +public class User implements UserInterface{ + + private int saldo; + private String username; + private int pass; + + public int getPass() { + return pass; + } + + public void setPass(int pass) { + this.pass = pass; + } + + public User(int saldo, String name, int pass) { + this.saldo = saldo; + this.username = name; + this.pass = pass; + } + + @Override + public Boolean deposit() { + System.out.println("DEPOSIT"); + System.out.println("========\n"); + System.out.println("Minimal deposit $50"); + System.out.print("Masukan jumlah uang ('q untuk keluar'): "); + String input = App.sc.next(); + if (input.equals("q")) return null; + if (Integer.parseInt(input) < 50) { + System.out.println("Deposit gagal!!!"); + System.out.println("Minimal deposit $50"); + return false; + } else { + this.saldo += Integer.parseInt(input); + System.out.println("deposit berhasil"); + System.out.println("========"); + System.out.print("Apakah mau kembali ke halaman utama (y/n) : "); + String input2 = App.sc.next(); + return input2.equals("y"); + } + } + + @Override + public Boolean tarikTunai() { + System.out.println("TARIK TUNAI"); + System.out.println("========\n"); + System.out.println("Maksimal penarikan $400"); + System.out.print("Masukan jumlah uang ('q untuk keluar'): "); + String input = App.sc.next(); + if (input.equals("q")) return null; + if (Integer.parseInt(input) > 400){ + System.out.println("Melebihi batas penarikan tunai ($500)"); + return false; + } else { + this.saldo -= Integer.parseInt(input); + System.out.println("Tarik tunai berhasil"); + System.out.println("========"); + System.out.print("Apakah mau kembali ke halaman utama (y/n) : "); + String input2 = App.sc.next(); + return input2.equals("y"); + } + } + + public void cekSaldo(){ + System.out.println("CEK SALDO"); + System.out.println("========\n"); + System.out.println("Saldo : $" + this.getSaldo()); + System.out.print("Apakah mau kembali ke halaman utama (y/n) : "); + } + + public int getSaldo() { + return saldo; + } + + public void setSaldo(int saldo) { + this.saldo = saldo; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } +} diff --git a/Mesach Harmasendro_ITB/src/UserInterface.java b/Mesach Harmasendro_ITB/src/UserInterface.java new file mode 100644 index 0000000..d646955 --- /dev/null +++ b/Mesach Harmasendro_ITB/src/UserInterface.java @@ -0,0 +1,6 @@ +public interface UserInterface { + + Boolean deposit(); + + Boolean tarikTunai(); +} diff --git a/README.md b/README.md index e54cdbd..54a95de 100644 --- a/README.md +++ b/README.md @@ -63,3 +63,18 @@ Karena keterbatasan di bahasa-bahasa berikut, bahasa di bawah ini tidak digunaka ## Deadline - Jumat, 27 Januari 2023, pukul 23.59 +## Deskripsi +Program bank sederhana + +Terdapat fitur login dan register lalu setelah login akan ada pilihan menu +cek saldo, deposit, dan tarik tunai. + +Implementasi OOP ada pada user dimana user terdapat tiga jenis yaitu standard, gold, dan platinum + +Tersedia 3 akun/user bawaan untuk tes: +- mch123, 1234 (standard) +- abg123, 1234 (gold) +- dxg123, 1234 (platinum) + +Program berbasis terminal jadi dijalankan di terminal +