Notes
Notes - notes.io |
public class Main {
// This defines savings and current account balances so the amount of money withdrawn or deposited by the user will be
// stored throughout the program's execution
static double savingbalance = 1000;
static double currentbalance = 5000;
public static void main(String[] args) {
String Username = "idiot";
String Password = "6969";
Scanner input = new Scanner(System.in);
int attempts = 0;
boolean isLoggedIn = false;
System.out.println("*************************************************************************************************");
System.out.println("Registration successful!");
System.out.println("Welcome to Tiered Banking Management System!");
System.out.println("Please log in using your credentials");
System.out.println("*************************************************************************************************");
while (attempts < 3 && !isLoggedIn) {
//checks if user attempts is less than 3 and if the isLoggedIn status is false
//while user attempts is less than 3, allow user to try again
//while isLoggedIn status is false, allow user to try again
//if attempts exceeds 3, then program will exit
//if isLoggedIn status becomes true and attempts is less then 3, then let user log in
System.out.println("Enter Username: ");
String username = input.next();
System.out.println("Enter Password: ");
String password = input.next();
System.out.println("*************************************************************************************************");
if (username.equals(Username) && password.equals(Password)) {
//if user input for name and pass is right, then isLoggedIn will become true and will let you in
System.out.println("Access Granted! Welcome!");
isLoggedIn = true;
menu();
} else {
attempts++;
// if user input for name or pass is wrong, adds 1 to attempt counter and makes user try again
if (attempts < 3) {
System.out.println("Invalid Username or Password! Please try again.");
System.out.println("*************************************************************************************************");
}
}
}
if (!isLoggedIn) {
//if total attempts reaches 3, then exit program
System.out.println("Program exit; You have exceeded the maximum login attempts.");
}
input.close();
}
//display the menu
public static void menu() {
System.out.println("*************************************************************************************************");
System.out.println("Welcome to the Account Menu!");
System.out.println("Please select the number corresponding to the account you would like to use!");
System.out.println("1.) Savings Account");
System.out.println("2.) Current Account");
System.out.println("3.) Exit Program");
System.out.println("*************************************************************************************************");
Scanner scanner = new Scanner(System.in);
int acctype = scanner.nextInt();
int accattempt = 0;
boolean isAccSelected = false;
while (accattempt < 3 && !isAccSelected) {
//idk why acc selection is also limited to 3 but whatever
switch (acctype) {
case 1:
System.out.println("*************************************************************************************************");
System.out.println("Welcome to your Savings Account! What would you like to do today?");
isAccSelected = true;
savingAccount(); // directs user to savings account method
break;
case 2:
System.out.println("*************************************************************************************************");
System.out.println("Welcome to your Current Account! What would you like to do today?");
isAccSelected = true;
currentAccount(); // directs user to current account method
break;
case 3:
isAccSelected = true; // if this is not here, then program will continuesly loop
exit(); // stops program
break;
default:
System.out.println("Unfortunately that is not in the options, please try again!");
accattempt++;
break;
}
}
}
public static void savingAccount() {
System.out.println("*************************************************************************************************");
System.out.println("1.) Check Balance");
System.out.println("2.) Deposit Money");
System.out.println("3.) Withdraw Money");
System.out.println("4.) Calculate Interest (Savings Only)");
System.out.println("5.) Logout");
System.out.println("*************************************************************************************************");
Scanner scanner = new Scanner(System.in);
int savingsAccountOption = scanner.nextInt();
switch (savingsAccountOption) {
case 1:
System.out.println("*************************************************************************************************");
System.out.println("Your current balance is " + savingbalance);
pausesavingAccount();
break;
case 2:
System.out.println("*************************************************************************************************");
// will loop until user inputs a valid deposit amount
double deposit = -1;
while (deposit <= 0) {
System.out.println("How much money would you like to deposit to your account?");
deposit = scanner.nextDouble();
if (deposit <= 0) {
System.out.println("Input error: Please enter a positive amount for deposit.");
}
}
savingbalance += deposit; // updates savings balance so it will be stored in memory throughout the whole program
System.out.println("*************************************************************************************************");
System.out.println("Transaction completed!");
pausesavingAccount();
break;
case 3:
System.out.println("*************************************************************************************************");
double withdrawAmount = -1;
while (withdrawAmount <= 0) {
System.out.println("How much money would you like to withdraw from your account?");
withdrawAmount = scanner.nextDouble();
if (withdrawAmount <= 0) { //if withdrawAmount is negative, then ask user to try again
System.out.println("Error: Please enter a positive amount to withdraw.");
} else if (withdrawAmount > 20000) { //if withdrawAmount is greater than20k, then ask user to try again
System.out.println("Error: Withdrawal limit is 20,000 per transaction.");
withdrawAmount = -1; // Reset so user can try again
} else if (withdrawAmount > savingbalance) { //if user withdraws money that is greater than in acc, asks user to try again
System.out.println("Error: Insufficient funds.");
withdrawAmount = -1; // resets for retry
}
}
savingbalance -= withdrawAmount; // will update savings balance
System.out.println("*************************************************************************************************");
System.out.println("Transaction completed!");
pausesavingAccount();
break;
case 4:
System.out.println("*************************************************************************************************");
System.out.println("Your interest is: " + (savingbalance * 0.03)); // calculates interest based on current amount of account balance
pausesavingAccount();
break;
case 5:
System.out.println("*************************************************************************************************");
System.out.println("You have logged out and returned to the menu.");
menu();
break;
default:
System.out.println("Unfortunately that is not in the options, please try again!");
savingAccount();
break;
}
}
// I'm tired of putting notes, same thing here also happens on savings account anyways
public static void currentAccount() {
System.out.println("*************************************************************************************************");
System.out.println("1.) Check Balance");
System.out.println("2.) Deposit Money");
System.out.println("3.) Withdraw Money");
System.out.println("4.) Logout");
System.out.println("*************************************************************************************************");
Scanner scanner = new Scanner(System.in);
int currentAccountOption = scanner.nextInt();
switch (currentAccountOption) {
case 1:
System.out.println("*************************************************************************************************");
System.out.println("Your current balance is " + currentbalance);
pausecurrentAccount();
break;
case 2:
System.out.println("*************************************************************************************************");
System.out.println("How much money would you like to deposit to your account?");
double deposit = scanner.nextDouble();
currentbalance += deposit;
System.out.println("*************************************************************************************************");
System.out.println("Transaction completed!");
pausecurrentAccount();
break;
case 3:
System.out.println("*************************************************************************************************");
double withdrawAmount = -1;
while (withdrawAmount <= 0) {
System.out.println("How much money would you like to withdraw from your account?");
withdrawAmount = scanner.nextDouble();
if (withdrawAmount <= 0) {
System.out.println("Error: Please enter a positive amount to withdraw.");
} else if (withdrawAmount > currentbalance) {
System.out.println("Error: Insufficient funds.");
withdrawAmount = -1;
}
}
currentbalance -= withdrawAmount;
System.out.println("*************************************************************************************************");
System.out.println("Transaction completed!");
pausecurrentAccount();
break;
case 4:
System.out.println("*************************************************************************************************");
System.out.println("You have logged out and have been returned to the menu.");
menu();
break;
default:
System.out.println("Unfortunately that is not in the options, please try again!");
currentAccount();
break;
}
}
// self explanatory
public static void pausesavingAccount() {
System.out.println("*************************************************************************************************");
System.out.println("If you would like to go back, please type 1, but if you would like to exit, please press any number that is not 1");
Scanner scanner = new Scanner(System.in);
int pauseOption = scanner.nextInt();
if (pauseOption == 1) {
savingAccount();
} else {
exit();
}
}
// same here
public static void pausecurrentAccount() {
System.out.println("*************************************************************************************************");
System.out.println("If you would like to go back, please type 1, but if you would like to exit, please press any number that is not 1");
Scanner scanner = new Scanner(System.in);
int pauseOption = scanner.nextInt();
if (pauseOption == 1) {
currentAccount();
} else {
exit();
}
}
// exits the program, only located on account options
public static void exit() {
System.out.println("*************************************************************************************************");
System.out.println("Thank you for using Tiered Banking Management System, have a nice day!");
}
}
//FINALLY I'M FREE AUGHAGSDAIUSGAHGSAH
|
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team