Create a flowchart and a java program of the problem stated as follows. Create
user-defined methods that will perform 4 functionalities of an Automated Teller
Machine(Withdraw, Deposit, Transfer, Balance Check)
1. Withdraw (method name: withdraw)
* Input the amount to be withdrawn. Compute for the remaining balance after
the operation (balance = balance - withdrawn)
2. Deposit (method name: deposit)
* Input the amount to be deposited. Compute for the updated balance after
the operation (balance = balance + deposit)
3. Transfer (method name: transfer)
*Input the account number and the amount to be transferred. Compute for the
updated balance after the operation (balance = balance – moneySent)
4. Balance Check (method name: balanceCheck)
* Display the remaining balance.
import java.util.Scanner;
public class Main {
private static double balance = 1000;
public static void withdraw(Scanner in) {
System.out.println("Input the amount to be withdrawn:");
balance -= in.nextDouble();
}
public static void deposit(Scanner in) {
System.out.println("Input the amount to be deposit:");
balance += in.nextDouble();
}
public static void transfer(Scanner in) {
System.out.println("Input the account number and the amount to be transferred:");
int accountNumber = in.nextInt();
balance -= in.nextDouble();
}
public static void balanceCheck() {
System.out.println("Balance: " + balance);
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("1. Withdraw\n2. Deposit\n3. Transfer\n4. Balance check");
switch (in.nextInt()) {
case 1:
withdraw(in);
break;
case 2:
deposit(in);
break;
case 3:
transfer(in);
break;
case 4:
balanceCheck();
break;
}
}
}
Comments
Leave a comment