Question

Item 1 – View my balance, 2 – Withdraw cash, and 3 – Deposit funds are...

Item 1 – View my balance, 2 – Withdraw cash, and 3 – Deposit funds are modules of the ATM program. You are requested to extend the program by writing the pseudocode that includes the three modules above. Please include all the parameters expected in each module. Please note that some methods might be required to return data while others not. Your solution should satisfy the following requirements: • The solution must illustrate the use of good programming practices. • The solution must make use of a loop. • The loop must make use of a sentinel value. Assume that a customer will start with a balance of R250 in the account and that account is not allowed to have less than R0.

PLEASE HELP ME WITH THIS PROGRAMMING LOGIC AND DESIGN QUESTION

JAVA LANGUAGE

THANK YOU

Homework Answers

Answer #1


// to import scanner class for input
import java.util.Scanner;

public class Account {

        double balance; // variable to store current balance

        Account() {
                balance = 250; // initial balance is R250
        }

        public double viewBalance() { // function to view your balance in account
                return balance;
        }

        public boolean withdraw(double b) { // function to withdraw from your account
                if ((balance - b) < 0) { // since balance can't be less then zero
                        System.out.println("Enter valid amount to withdraw, it should be less than your balance"); // this will
                                                                                                                                                                                                                // output to
                                                                                                                                                                                                                // screen if
                                                                                                                                                                                                                // condition is
                                                                                                                                                                                                                // met
                        return false; // to denote amount didn't get withdrawn
                } else {
                        balance = balance - b; // update balance
                        return true; // to show transaction is complete
                }
        }

        public void deposit(double b) { // function to deposit money into your account
                balance = balance + b;
        }

        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in); // creating an instance of scanner class
                System.out.println("Enter no 1 for viewing your balance , 2 for withdraw, 3 for deposit and 4 for quit");
                int n = sc.nextInt(); // taking user input
                double b = 0; // variable to store balance to withdraw or deposit
                Account a = new Account(); // creating an instance of account class
                while (n != 4) {
                        if (n == 1) {
                                System.out.println("Your balance is:" + a.viewBalance()); // calling viewBalance function
                        } else if (n == 2) {
                                System.out.println("Enter amount to withdraw:");
                                b = sc.nextDouble(); // taking input from the user
                                boolean f = a.withdraw(b); // calling withdraw function
                                if (f) {
                                        System.out.println("Transaction successful");
                                }
                        } else if (n == 3) {
                                System.out.println("Enter amount to deposit:");
                                b = sc.nextDouble(); // taking input from the user
                                a.deposit(b); // calling deposit function
                                System.out.println("Your balance has been updated");
                        }
                        System.out.println("Enter no 1 for viewing your balance , 2 for withdraw, 3 for deposit and 4 for quit");
                        n = sc.nextInt(); // taking user input

                }
                System.out.println("Thank you for using our system"); // this will output to the screen

        }

}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions