Question

Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type int Name of type String Balance of type float Public members void Init) method to enter the values of data members void Show) method to display the values of data members void Deposit(int Amt) method to increase Balance by Amt void Withdraw(int Amt) method to reduce Balance by Amt (only if required balance exists in account) float RBalance() member function that returns the value of Balance Create a class ACCOUNT DATA, that has a An array of type Account to store records of multiple accounts. methodRegister0, to take the input of details of ACCOUNTs entered by a user. methodTransact(), to perform a transaction i.e. Deposit or Withdraw an Amount in an Account Holders Balance whose Acno is entered by the user. Note that an Account Holder must always have a minimum Balance of Rs 500 in his Account. method DisplayAll) to display the details of all Account Holders. Write a menu driven program, which uses all the above methods. Add get methods if required

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Account.Java:

package accounts;

public class account {
    private int acno;
    private String name;
    private float balance;
    public void init() {
        acno = 0;
        name = "";
        balance = 0;
    }

    public int getAcno() {
        return acno;
    }

    public String getName() {
        return name;
    }

    public float RBalance() {
        return balance;
    }

    public void setAcno(int acno) {
        this.acno = acno;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setBalance(float balance) {
        this.balance = balance;
    }

    public void show() {
        System.out.println(String.format("Account number : %d", getAcno()));
        System.out.println("Name : " + getName());
        System.out.println("Balance : "  + balance);
    }
    public void deposit(int amt){
        balance += amt;
    }
    public void withdraw(int amt) {
        if (amt > balance)
            System.out.println("Not enough balance in account.");
        else balance -= amt;
    }

}

Account_data.Java

package accounts;

import java.util.Scanner;

public class Account_data {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        account a = new account();
        System.out.println("Enter account number: ");
        int acc_no = input.nextInt();
        System.out.println("Enter name: ");
        String name = input.next();
        System.out.println("Enter balance :");
        float bal = input.nextFloat();
        a.setAcno(acc_no);
        a.setName(name);
        a.setBalance(bal);

        while (true) {
            System.out.println("MENU");
            System.out.println("Press 1 to deposit");
            System.out.println("Press 2 to withdraw");
            System.out.println("Press 3 to view details");
            System.out.println("Press 4 to view balance");
            System.out.println("Press 5 to exit");
            System.out.println("Enter choice: ");
            int choice = input.nextInt();
            switch (choice) {
                case 1:
                    System.out.println("Emter amount to deposit: ");
                    int amt = input.nextInt();
                    a.deposit(amt);
                    break;
                case 2:
                    System.out.println("Emter amount to withdraw: ");
                    int wamt = input.nextInt();
                    a.withdraw(wamt);
                    break;
                case 3:
                    a.show();
                    break;
                case 4:
                    System.out.println("Balance is : " + a.RBalance());
                    break;
                case 5:
                    System.exit(1);
                default:
                    System.out.println("Wrong choice");
            }
        }
    }
}

Output:

Enter account number: Enter name: nter balance MENU Press 1 to deposit Press 2 to withdraw Press 3 to view details Press 4 to view balance Press 5 to exit Enter choice: Emter amount to withdraw: MENU Press 1 to deposit Press 2 to withdraw Press 3 to view details Press 4 to view balance Press 5 to exit Enter choice: Account numbe rZ0 Name : Arka Balance 5049.0 MENU Press 1 to deposit Press 2 to withdraw Press 3 to view details Press 4 to view balance Press 5 to exi Enter choice: Process finished with exit code 1

Add a comment
Know the answer?
Add Answer to:
Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • •create a new savings account object (for choice 2). •ask the user to enter an initial...

    •create a new savings account object (for choice 2). •ask the user to enter an initial balance which should be greater than 50. If the entered amount is less than 50, the program will ask the user to enter another amount. This continues until an amount greater than 50 is entered. •Set the balance of the savings account object by calling the setBalance() method. •Ask the user to deposit an amount. Deposit that amount and display the balance of the...

  • /*Design a class BankAccount that has the following properties: * Account Number (should be static and increased every...

    /*Design a class BankAccount that has the following properties: * Account Number (should be static and increased every time an account is created. * An array of holders max 5 and a holder is a Person object * A int to rember how many holders * Balance (float) * Date opened * interest rate * Constructors * addHolder will add one more Person as a holder, if you reach 5 don't add. * Setters getters * method payInterest that add...

  • JAVA PLEASE Create a class called Account with the following instance data Integer id Double balance...

    JAVA PLEASE Create a class called Account with the following instance data Integer id Double balance Provides the following methods Default constructor (defaults balance to 100) Constructor with parameters for the ID and the starting balance Accessor and mutator methods for id and balance Method to perform a withdrawal Method to perform a deposit Create a class called Bank which has an array of Account objects. This class will manage the accounts. It must provide methods Do withdrawal Do deposits...

  • C++ Question Modify the class by changing private members to protected members and viewing Account class...

    C++ Question Modify the class by changing private members to protected members and viewing Account class as a base class. Define two derived classes Checking and RRSP. The Checking class has one additional private data: total(double). It has five public member functions: a constructor Checking (string n, string addr, double b, int p, double tot) (note you must call base constructor by using initialization list), double getTotal() to return total, void setTotal() to updata data, void withdraw(double w) which requires...

  • In Java: DATA TYPE CLASS Create one data type class Account_yourLastName that hold the information of...

    In Java: DATA TYPE CLASS Create one data type class Account_yourLastName that hold the information of an account such as accountNumber (String), name (String), address (String), balance (float), interestRate(float) and beside the no-argument constructor, parameterized constructor, the class has method openNewAccount, method checkCurrentBalance, method deposit, method withdrawal, method changeInterestRate REQUIREMENT - DRIVER CLASS Provide the application for the Bank Service that first displays the following menu to allow users to select one task to work on. After finishing one task,...

  • c++ please    Define the class bankAccount to implement the basic properties of a bank account....

    c++ please    Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). (Store interest rate as a decimal number.) Add appropriate member func- tions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 compo- nents of...

  • Design a bank account class named Account that has the following private member variables:

    Need help please!.. C++ programDesign a bank account class named Account that has the following private member variables: accountNumber of type int ownerName of type string balance of type double transactionHistory of type pointer to Transaction structure (structure is defined below) numberTransactions of type int totalNetDeposits of type static double.The totalNetDeposits is the cumulative sum of all deposits (at account creation and at deposits) minus the cumulative sum of all withdrawals. numberAccounts of type static intand the following public member...

  • LAB1 PART 1 FOR THE DATA TYPE CLASS: If you do not have UML of class...

    LAB1 PART 1 FOR THE DATA TYPE CLASS: If you do not have UML of class Account_yourLastName, you should do that first Basesd on the UML, provide the code of data type class Account_yourLastName to hold the information of an account with account number (String), name (String), balance (double), with no-argument constructor, parameter constructor Also, define some methods to handle the tasks: open account, check current balance, deposit, withdraw, and print monthly statement. At the end of each task we...

  • PYTHON PROGRAMMING LANGUAGE Design a class named Savings Account that contains: A private int data field...

    PYTHON PROGRAMMING LANGUAGE Design a class named Savings Account that contains: A private int data field named id for the savings account. A private float data field named balance for the savings account. A private float data field named annuallnterestRate that stores the current interest rate. A_init_ that creates an account with the specified id (default 0), initial balance (default 100), and annual interest rate (default 0). . The accessor and mutator methods for id, balance, and annuallnterestRate. A method...

  • Consider the following Account class and main function: class Account: acct_num=1000 #Constructor for Account class (default...

    Consider the following Account class and main function: class Account: acct_num=1000 #Constructor for Account class (default values for balance #and annual interest rate are 100 and e, respectively). #INITIALIZER METHOD HEADER GOES HERE #MISSING CODE def getId(self): return self._id def getBalance(self): #MISSING CODE def getAnnualInterestRate(self): return self.___annualInterestRate def setBalance(self, balance): self. balance - balance def setAnnualInterestRate(self,rate): #MISSING CODE def getMonthlyInterestRate(self): return self. annualInterestRate/12 def getMonthlyInterest (self): #MISSING CODE def withdraw(self, amount): #MISSING CODE det getAnnualInterestRate(self): return self. annualInterestRate def setBalance(self,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT