C++ ONLY Assignment Description: In this assignment you will create a program th
ID: 3690289 • Letter: C
Question
C++ ONLY
Assignment Description:
In this assignment you will create a program that allows a user to choose one of the following main menu items:
C) Create new user account (Create an account with userId/password)
L) Login
V) View promotions
Q) Quit the program
If User enters an option other than (uppercase or lowercase) C, L, V, or Q, the program does not do anything and shows a message wrong option and displays the menu again.
When user enters option C, the program asks the user to enter a userId and a password and successfully returns back to the main menu. The login and password should be stored in a file.
If the user chooses option L, the program will display the login prompt and then, it will ask for the password. At this stage, the entered login and password are compared to the stored login/password pair and proper message will show up if the match was not found which takes the user back to the main menu.
If the user chooses option V, the program will display the message: Thank you for using our bank and Future Computer Programmer ATM Machine! For your continued support, we are offering 3% cash back on all debit purchases.
Now, if login was successful, the following banking menu will be display to let the user choose one of the following tasks:
W) Withdraw money.
D) Deposit money.
B) Request balance.
Q) Quit the program.
(again, remember that if the user enters an option other than (uppercase or lowercase) W, D, B, Q, the program should show a message and display the menu again.)
The initial balance for the user account should be $0.00
If the user chooses option W, the program should ask the user to enter amount user wishes to withdraw.
Validation: In the case of withdraw, if the amount is more than balance the user should be notified and no withdraw will occur.
If the user chooses option D, the program should ask the user how much amount the user wishes to deposit and add it to initial balance.
If the user chooses option B, the program should display the balance amount in the user account.
Sample Output:
Hi! Welcome to Future Computer Programmer ATM Machine!
Please select an option from the menu below:
l -> Login
c -> Create New Account
v -> View promotions
q -> Quit
Enter your choice: L
Please enter your user id: 12
Please enter your password: 2345
No match was found! Login Failed!
Please select an option from the menu below:
l -> Login
c -> Create New Account
v -> View promotions
q -> Quit
Enter your choice: c
Please enter your user name: 12
Please enter your password: 2345
Thank You! Your account has been created!
Please select an option from the menu below:
l -> Login
c -> Create New Account
v -> View promotions
q -> Quit
Enter your choice: l
Please enter your user id: 12
Please enter your password: 2345
Access Granted! Transferring to Account Menu!
Please select an option from the menu below
d -> Deposit Money
w -> Withdraw Money
b -> Check Balance
r -> Review Account Activities History
q -> Quit
Enter your choice: d
Enter amount of deposit: $20
$20 was deposited.
Please select an option from the menu below
d -> Deposit Money
w -> Withdraw Money
b -> Check Balance
r -> Review Account Activities History
q -> Quit
Enter your choice: B
Your balance is $20.
Please select an option from the menu below
d -> Deposit Money
w -> Withdraw Money
b -> Check Balance
r -> Review Account Activities History
q -> Quit
Enter your choice: W
Enter amount of withdrawal: $25
Sorry withdrawal amount exceeds the balance. Can’t withdraw !
Please select an option from the menu below
d -> Deposit Money
w -> Withdraw Money
b -> Check Balance
r -> Review Account Activities History
q -> Quit
Enter your choice: W
Enter amount of withdrawal: $2.5
$2.5 was withdrawn
Please select an option from the menu below
d -> Deposit Money
w -> Withdraw Money
b -> Check Balance
r -> Review Account Activities History
q -> Quit
Enter your choice: b
Your balance is $17.5.
Please select an option from the menu below
d -> Deposit Money
w -> Withdraw Money
b -> Check Balance
r -> Review Account Activities History
q -> Quit
Enter your choice: R
Date and Time Transaction Amount Status
Sun Mar 20 12:48:18 2016 Deposit $20 OK
Sun Mar 20 12:52:41 2016 Check Balance $20 OK
Sun Mar 20 12:54:31 2016 Withdraw Req $25 Not OK
Sun Mar 20 12:55:57 2016 Withdraw Req $2.5 OK
Sun Mar 20 12:57:08 2016 Check Balance $17.5 OK
Please select an option from the menu below
d -> Deposit Money
w -> Withdraw Money
b -> Check Balance
r -> Review Account Activities History
q -> Quit
Enter your choice: Q
Log Out Successful!
Please select an option from the menu below:
l -> Login
c -> Create New Account
v -> View promotions
q -> Quit
Enter your choice: Q
Thanks for stopping by!
Additional Instructions:
All transactions should be stored in a file called transHistory.output as shown above for the Review Account Activities History.
NOTE: Do Not Use Excessive Global Variables. Using Global Variables in most functions may result in losing points for the designated function.
Choose the parameters and return types that you feel are right for the appropriate methods. Again, do not use an excessive amount of Global Variables, as you will lose points.
Please make sure your code has following functions:
char mainMenu(); //main menu, first thing the user sees. Displays the menu and gets the value for selection
void createAccount(); //will only display if the user has selected to create an account. Allows the user to enter his/her ID and password and then stores this login information in a file called accounts.txt
void login(); //this function gets the user name and password from the user. Must then match this account info, by comparing it to every item in the file accounts.txt, to indicate whether or not login was successful
char bankingMenu(): //will only display if the user has selected to log in.
void deposit (); //allows the user to put money into their accounts, prints success or fail upon deposit
void withdraw(); //allows the user to get money from their accounts, prints success or fail upon deposit
void displayBalance(); //shows the balance on the screen
void ShowTransHist(); //get the transaction history from the file path string and display
You can use additional functions (optional) for input validation and withdrawal amount validation. Your program should make use appropriate switch and if-else statements where necessary.
Make sure you work out an algorithm and submit it as well either in the form of pseudo-code or flowchart before you start implementing the code. You can include your pseudo code within the block comment/header documentation part of the code. A pseudo code/algorithm should consist of clear and concise steps that mirror your implementation logic.
Explanation / Answer
package com.chegg.test;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import java.util.StringTokenizer;
public class ATMMachine {
static boolean login = false;
static boolean acctCreated = false;
public static void main(String[] args) {
@SuppressWarnings("unused")
Scanner sc = new Scanner(System.in);
System.out
.println("Hi! Welcome to Future Computer Programmer ATM Machine!");
mainMenu();
}
/**
* Method to display main menu
*/
private static void mainMenu() {
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
char choice = 0;
do {
System.out.println("Please select an option from the menu below:"
+ " l -> Login" + " c -> Create New Account"
+ " v -> View promotions" + " q -> Quit"
+ " Enter your choice:");
choice = sc.next().toLowerCase().charAt(0);
switch (choice) {
case 'l':
login();
if (login) {
char ch = 0;
do {
ch = bankingMenu();
switch (ch) {
case 'w':
withdraw();
break;
case 'd':
deposit();
break;
case 'b':
displayBalance();
break;
case 'r':
ShowTransHist();
break;
case 'q':
System.out.println("Log Out Successful!");
mainMenu();
break;
default:
System.out.println("Wrong choice entered:");
}
} while (ch != 'w' && ch != 'd' && ch != 'b' && ch != 'q');
} else {
System.out.println("Login Unsuccessful!");
mainMenu();
}
break;
case 'c':
createAccount();
mainMenu();
break;
case 'v':
System.out
.println("Thank you for using our bank and Future Computer Programmer"
+ " ATM Machine! For your continued support,"
+ " we are offering 3% cash back on all debit purchases.");
mainMenu();
break;
case 'q':
System.out.println("Thanks for stopping by!");
break;
default:
System.out.println("Entered wrong option");
}
} while (choice != 'l' && choice != 'c' && choice != 'v'
&& choice != 'q');
}
/**
* Method to show transaction history
*/
private static void ShowTransHist() {
// TODO Auto-generated method stub
}
/**
* Method to show account balance
*/
private static void displayBalance() {
// TODO Auto-generated method stub
}
/**
* Method to deposit the amount
*/
private static void deposit() {
// TODO Auto-generated method stub
}
/**
* Method to withdraw the amount
*/
private static void withdraw() {
// TODO Auto-generated method stub
}
/**
* Method to validate the user
*
* @param userName
* @param password
*/
private static void login() {
Scanner sc = new Scanner(System.in);
System.out.println("Please enter your user id:");
String userName = sc.next();
System.out.println("Please enter your password:");
String password = sc.next();
try {
FileReader fr = new FileReader("accounts.txt");
BufferedReader br = new BufferedReader(fr);
String data;
while ((data = br.readLine()) != null) {
StringTokenizer st = new StringTokenizer(data, ",");
String user = null;
String pass = null;
while (st.hasMoreTokens()) {
user = st.nextToken();
pass = st.nextToken();
}
if (userName.equals(user) && password.equals(pass)) {
System.out
.println("Access Granted! Transferring to Account Menu!");
login = true;
}
}
br.close();
} catch (FileNotFoundException fnfe) {
System.out.println("File Not found");
System.exit(0);
} catch (IOException ioe) {
System.out.println("Exception occured while reading from file");
System.exit(0);
} finally {
}
}
/**
* Account Menu
*/
private static char bankingMenu() {
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
System.out.println("d -> Deposit Money" + " w -> Withdraw Money"
+ " b -> Check Balance"
+ " r -> Review Account Activities History" + " q -> Quit");
char choice = sc.next().toLowerCase().charAt(0);
return choice;
}
/**
* Method to create new account
*
* @param user
* @param pass
*/
private static void createAccount() {
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
System.out.println("Please enter your user id:");
String user = sc.next();
System.out.println("Please enter your password:");
String pass = sc.next();
try {
FileWriter fw = new FileWriter("accounts.txt", true);
fw.write(user);// appends the string to the file
fw.write(",");
fw.write(pass);
fw.write(" ");
fw.close();
acctCreated = true;
System.out.println("Thank You! Your account has been created! ");
} catch (FileNotFoundException fnfe) {
System.out.println("File Not found");
} catch (IOException ioe) {
System.out.println("Exception occured while reading from file");
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.