Question

Class 1: Account.java Variables: 1. accountNumber (public) 2. accountName (public) 3. balance (private) In Account.java Functions:...

Class 1: Account.java

Variables:

1. accountNumber (public)

2. accountName (public)

3. balance (private)

In Account.java

Functions:

1. Fully parametrized Constructor (to initialize class variables)

2. Getter (getBalance()) and Setter (setBalance()) for the float balance, must be greater than zero.

In Account.java

Methods:

  1. checkBalance( ) to print CURRENT BALANCE.
  2. deposit(int added_amount) should add add_amount to balance
  3. withdraw(int withdraw_amount) should deduct withdraw_amount balance
  4. display( ) will print all the information (account number, name, balance).

Class 2: AccountTest.java

  1. Create an object account1 and pass variables in argument of Account function (which is a constructor)

Ask user to input values off accountNo, accountName and balance.

  1. In main class first call the display method. And then call checkBalance() method. After that deposit 40,000 in bank account and again display the balance. Now withdraw 12000 and display the balance.

Homework Answers

Answer #1

Below is your code:

Account.java

public class Account {
        public int accountNumber;
        public String accountName;
        private float balance;

        // 1. Fully parametrized Constructor (to initialize class variables)
        public Account(int accountNumber, String accountName, float balance) {
                this.accountNumber = accountNumber;
                this.accountName = accountName;
                this.balance = balance;
        }

        // 2. Getter (getBalance()) and Setter (setBalance()) for the float balance,
        // must be greater than zero.

        public float getBalance() {
                return balance;
        }

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

        // checkBalance( ) to print CURRENT BALANCE.
        public void checkBalance() {
                System.out.println("Current Balance: " + this.balance);
        }

        // deposit(int added_amount) should add add_amount to balance
        public void deposit(int added_amount) {
                this.balance = this.balance + added_amount;
        }

        // withdraw(int withdraw_amount) should deduct withdraw_amount balance
        public void withdraw(int withdraw_amount) {
                this.balance = this.balance - withdraw_amount;
        }

        // display( ) will print all the information (account number, name,
        // balance).
        public void display() {
                System.out.println("Account number: " + accountNumber
                                + ", Account Name: " + accountName + ", Balance: "
                                + this.balance);
        }

}

AccountTest.java

import java.util.Scanner;

public class AccountTest {
        public static void main(String[] args) {
                int accountNo;
                String accountName;
                float balance;
                Scanner sc = new Scanner(System.in);
                System.out.print("Enter Account Number: ");
                accountNo = Integer.parseInt(sc.nextLine());
                System.out.print("Enter Account Name: ");
                accountName = sc.nextLine();
                System.out.print("Enter Balance: ");
                balance = Float.parseFloat(sc.nextLine());
                Account account1 = new Account(accountNo, accountName, balance);
                account1.display();
                account1.checkBalance();
                account1.deposit(40000);
                account1.checkBalance();
                account1.withdraw(12000);
                account1.checkBalance();
        }
}

Output

Enter Account Number: 123465879
Enter Account Name: Mark's Inventories
Enter Balance: 100000
Account number: 123465879, Account Name: Mark's Inventories, Balance: 100000.0
Current Balance: 100000.0
Current Balance: 140000.0
Current Balance: 128000.0

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
For the following class Book: 1- Write a default constructor to give default values (title= Intro...
For the following class Book: 1- Write a default constructor to give default values (title= Intro to Programming and price = 20) to the class’s variables. 2 - Write a parameterized constructor to allow the user to initialize the class variables. 3- Write getter & setter for each variable of this class. 4- Then write a main code to create an instance of this class using parameterized constructor, ask user for inputs to initialize the variables of this instance and...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
Assume the method giveBonus() has been added to the BankAccount class. public class Raise { private...
Assume the method giveBonus() has been added to the BankAccount class. public class Raise { private int annualSalary; public Raise(){ annualSalary = 0; } //end constructor public Raise(int currentSalary){ annualSalary = currentSalary; } //end constructor public void giveRaise(){ annualSalary = annualSalary + 500; } //end giveRaise public void getSalary(){ return annualSalary; } //end giveRaise } What will be the output from the following statements that use this BankAccount class? (assume there is a getBalance() method that returns the balance) Raise...
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is...
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is up to you as long as you implement some form of inheritance. Below is my code however the credit and the actual menu isn't working. Can i get some help on getting the menu to work properly. // BankAccount.h #ifndef ACCOUNT_H #define ACCOUNT_H #include <string> #include <iostream> using namespace std; class BankAccount { protected : int noOfWithdrawls; private: // Declaring variables    float balance;...
C# Step 1: Create a Windows Forms Application. Step 2: Create a BankAccount class. Include: Private...
C# Step 1: Create a Windows Forms Application. Step 2: Create a BankAccount class. Include: Private data fields to store the account holder's name and the account balance A constructor with 0 arguments A constructor with 1 argument (account holder's name) A constructor with 2 arguments(account holder's name and account balance) Public properties for the account holder's name and the account balance. Do not use auto-implemented properties. A method to increase the balance (deposit) A method to decrease the balance...
public class Date {    private int month;    private int day;    private int year;...
public class Date {    private int month;    private int day;    private int year;    public Date( int monthValue, int dayValue, int yearValue )    {       month = monthValue;       day = dayValue;       year = yearValue;    }    public void setMonth( int monthValue )    {       month = monthValue;    }    public int getMonth()    {       return month;    }    public void setDay( int dayValue )    {       day =...
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with...
Java Program Implement a class called AnimalTrainer. Include the following data types in your class with the default values denoted by dataType name : defaultValue - String animal : empty string - int lapsRan : 0 - boolean resting : false - boolean eating : false - double energy : 100.00 For the animal property implement both getter/setter methods. For all other properties implement ONLY a getter method Now implement the following constructors: 1. Constructor 1 – accepts a String...
Write a Python class, Flower, that has 3 instance variables name, num_petals and price which have...
Write a Python class, Flower, that has 3 instance variables name, num_petals and price which have types str, int and float. Your class must have a constructor method to initialize the variables to an appropriate value, and methods for setting the value of each instance variable (set methods) and for retrieving the instance variable values (get methods). You can use the credit card code we looked at for assistance.
c++ Design a class named Account that contains (keep the data fields private): a) An int...
c++ Design a class named Account that contains (keep the data fields private): a) An int data field named id for the account. b) A double data field named balance for the account. c) A double data field named annualInterestRate that stores the current interest rate. d) A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. e) The accessor and mutator functions for id, balance, and annualInterestRate. f) A function named getMonthlyInterestRate() that...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...