Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hands on OOP submission by Mesach Harmasendro #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/Hands-On-OOP-2022.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
242 changes: 242 additions & 0 deletions Mesach Harmasendro_ITB/src/App.java
Original file line number Diff line number Diff line change
@@ -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<User> 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");
}
}
}
}
60 changes: 60 additions & 0 deletions Mesach Harmasendro_ITB/src/GoldUser.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
Loading