-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.java
More file actions
115 lines (104 loc) · 3.84 KB
/
test.java
File metadata and controls
115 lines (104 loc) · 3.84 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package SimpleAtmProject;
import java.util.Scanner;
/**
* @author Fatih ARI - 19.08.2021
*
* An ATM project is designed with loops, where the user can manage their bank account.
*
* General Rules:
* The user has an initial balance of $1500.
* The default username is "test" and the password is "123".
* User will be able to login to the system with username and password,
* Every time you enter your password incorrectly, it will show the remaining rights on the screen. If user enters incorrectly three times, user's account will be blocked,
* User able to deposit money,
* able to withdraw money,
* can inquire about the balance,
* be able to log out of the system,
* The system will leave a message when logging out.
*/
public class test {
static Scanner input = new Scanner (System.in);
static int balance = 1500; //changeable variable
static int amountOfMoney;
static boolean flagMenu = false;
public static void main(String[] args) {
String username = "test", password = "123";
String inputUsername="", inputPassword="";
byte remainingRight = 3;
do
{
System.out.print("\nEnter your username: ");
inputUsername = input.nextLine();
System.out.print("Enter your password: ");
inputPassword = input.nextLine();
if(inputUsername.equals(username) && inputPassword.equals(password))
{
System.out.println("\nHello \" "+ inputUsername + "\"! You have successfully logged into the system. ");
flagMenu = true;
break;
}
else
{
remainingRight--;
System.out.println("\nWrong username or password. Your remaining right is \""+ remainingRight + "\"");
if(remainingRight==0)
System.out.println("Your account has been blocked.");
}
}
while (remainingRight>0);
while(flagMenu)
{
mainMenu();
}
}
private static void mainMenu()
{
Scanner inputMenu = new Scanner(System.in);
System.out.println("This is main menu.");
System.out.println("1-Deposit\n" +
"2-Withdraw\n" +
"3-Balance Query \n" +
"4-Log Out");
System.out.print("Please select the action you want to take: ");
String key = inputMenu.nextLine();
switch (key) {
case "1":
deposit();
break;
case "2":
withdraw();
break;
case "3":
balanceQuery();
break;
case "4":
System.out.println("\nSee you again.\n");
flagMenu = false;
break;
default:
break;
}
}
private static void deposit()
{
System.out.print("Enter the amount of money to deposit: ");
amountOfMoney = input.nextInt();
balance += amountOfMoney;
System.out.println("\nThe deposit was successful. \n");
}
private static void withdraw()
{
System.out.print("Enter the amount of money to withdraw: ");
amountOfMoney = input.nextInt();
if(balance - amountOfMoney >= 0){
balance -= amountOfMoney;
System.out.println("\nThe withdraw was successful. \n");
}
else
System.out.println("\nThe withdrawal could not be made because you do not have enough balance. \n");
}
private static void balanceQuery()
{
System.out.println("\nYour balance is: " + balance +"\n");
}
}