-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbankSystem.java
More file actions
77 lines (59 loc) · 1.62 KB
/
bankSystem.java
File metadata and controls
77 lines (59 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import java.util.Scanner;
class Main{
public static void main(String args[]){
Scanner input = new Scanner(System.in);
System.out.println("Welcome to my bank lol :D\n1.balance\n2.deposit\n3.withdraw");
System.out.print("enter number: ");
int userInput = input.nextInt();
Person c1 = new Person("a", 1000);
userInput(userInput, c1, input);
}
public static void userInput(int user, Person person, Scanner input){
if(user <= 3 && user > 0 ){
switch(user){
case 1:
person.showBalance();
break;
case 2:
System.out.print("enter number to deposit: ");
int enterNumber = input.nextInt();
if(enterNumber > 0){
person.addBalance(enterNumber);
person.showBalance();
}
break;
case 3:
System.out.print("enter number to withdraw: ");
int sumToWithDraw = input.nextInt();
if(sumToWithDraw > 0) person.withDraw(sumToWithDraw);
break;
}
}else{
System.out.println("wrong number");
return;
}
}
}
class Person{
private String name;
private int balance;
public Person(String name, int balance){
this.name = name;
this.balance = balance;
}
public void showBalance(){
System.out.println("your current balance: " + balance + "$");
}
public void addBalance(int add){
balance += add;
System.out.println(add + "$ was added to your balance");
}
public void withDraw(int withDraw){
if(balance - withDraw < 0){
System.out.println("not enought money on balance");
}else{
balance -= withDraw;
System.out.println(withDraw + "$ was withdrawed");
}
}
}