Write a client-server program to work like an ATM machine using UDP protocol. Th
ID: 3752376 • Letter: W
Question
Write a client-server program to work like an ATM machine using UDP protocol. The client program should have the ability to choose operations, such as deposit, withdraw and balance check of the user if he is a valid user. And server program maintains a file with user details for authentication. For each row we would have user details including name, pin, and available balance. When a client requests to deposit or withdraw money, then the server should prompt them for their id and pin and after their validation, the server should allow them to deposit or withdraw money (On deposit add the money to the available balance and on withdraw deduct the available balance by the amount given and save this information to the file, and also provide some sentence to client program that the operation is successfully done). Test the operations from client program like deposit + balance check, withdraw + balance check, invalid user trying to withdraw/deposit/checking balance (show an error message that he is not a user) and provide screenshots of their output. NOTE: Maintain a txt file with predefined user details with a space/tab separating their details or you can add one more operation that will create a new account with the details as above also.
Explanation / Answer
IF YOU WANT ANY EXTRA INFORMATION FROM ME COMMENT BELOW
ANS:
CODE:
Please take the account number and password from program code and try it.
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import java.util.ArrayList;
import java.util.Scanner;
public class ATM {
static Scanner keyboard = new Scanner(System.in);
static String acctNum, pwd, result;
static double oldbal, newbal, deposit, withdraw,currentBalance;
static int choose;
public static void main(String[] args) {
for (int run = 0; run < 3; run++) {
System.out.println("Please enter your account number");
acctNum = keyboard.nextLine();
System.out.println("Please enter your password");
pwd = keyboard.nextLine();
result = checkID(acctNum, pwd);
if (!result.equals("ERROR")) {
break;
} else if (run == 2) {// You can't give wrong details more than 3
// times
System.out.println("MAXIMUM TRIES EXCEEDED");
return;
}
}
menu();
}
public static String checkID(String acctNum, Object pwd) {
String result = "ERROR";
String a = "44567-5 mypassword 520.36";
String b = "1234567-6 anotherpassword 48.20";
String c = "4321-0 betterpassword 96.74";
if (acctNum.equals("2345") && pwd.equals("2345")) {
result = "520.36";
} else if (acctNum.equals("1234567-6") && pwd.equals("anotherpassword")) {
result = "48.20";
} else if (acctNum.equals("4321-0") && pwd.equals("betterpassword")) {
result = "96.74";
}
System.out.println(result);
return result;
}
public static int menu() {
System.out.println("Choose one of the following: 1.Display Balance 2.Deposit 3.Withdraw 4.Log Out");
choose = keyboard.nextInt();
if (choose == 1) {// 1. Display Balance
displayBalance();
menu();
return 1;
}
if (choose == 2) {// 2. Deposit
deposit();
menu();
return 2;
}
if (choose == 3) {// 3. Withdraw
withdraw();
menu();
return 3;
}
if (choose == 4) {// 4. Log out
System.out.println("You are logged out.");
return 4;
}
if (choose <= 5) {// type in anything greater than 4 and you will get a
// system error
System.out.println("System Error");
menu();
return 5;
}
if (choose >= 1) {// type in anything less than 1 and you will get a
// system error
System.out.println("System Error");
menu();
return 6;
}
return choose;
}
public static void deposit()
{
Scanner input = new Scanner(System.in);
System.out.println("Enter deposit amount:");
double amount = input.nextDouble();
System.out.println("Your deposit amount: " + amount);
currentBalance += amount;
System.out.println("Your new balance is: " + currentBalance);
}
public static double displayBalance() {
System.out.println("Total balance is: $" + currentBalance);
oldbal = 0.00;
return 1;
}
public static void withdraw()
{
Scanner input = new Scanner(System.in);
System.out.println("Enter withdrawal amount: ");
double amount = input.nextDouble();
System.out.println("Your withdrawal amount: " + amount);
currentBalance -= amount;
System.out.println("Your new balance is: " + currentBalance);
}
}
THANK YOU
RATE THUMBSUP PLZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.