Question

Create a class named BankAccount with data fields for a count number and a balance. Include...

Create a class named BankAccount with data fields for a count number and a balance. Include a constructor that takes arguments for each field. The constructor sets the balance to 0 if it is below the required $200.00 minimum for an account. Include a method that displays the account details, including an explanation if the balance was reduced to 0.

Write the class TestAccount in which you instantiate two BankAccount objects, prompt a user for values of the account number and the balance, and then display the values for each field in each account object. Make sure to format the balance output as currency, with the “$" sign and values of dollars and cents (use Java currency formatter). Save both classes as BankAccount.java and TestAccount.java.

Compile, run and test the application. Submit two original .java files as an attachment to your initial response. (Please do not copy/paste the whole file codes into your response.) Zip them into a single .zip file and attach the .zip file to your post. In the initial response itself, provide comments and explanations of your solution, including the UML diagram of your application.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
//BankAccount.java

import java.text.NumberFormat;
import java.util.Locale;

public class BankAccount
{
        int accountNumber;
        double balance;
        public BankAccount(int accountNumber, double balance)
        {
            this.accountNumber = accountNumber;
            if(balance < 200)
                this.balance = 0;
            else
                this.balance = balance;
        }
        public void display()
        {
            System.out.println("Account number: " + this.accountNumber);
            NumberFormat us = NumberFormat.getCurrencyInstance(Locale.US);
            if(this.balance == 0)
                System.out.println("Your balance was reduced to 0 as balance was below required minimum $200.00");
            System.out.println("Balance: " + us.format(this.balance));
        }
}
//TestAccount.java

import java.util.Scanner;

public class TestAccount
{
    public static void main(String[] args)
    {
        int accountNumber1, accountNumber2;
        double balance1, balance2;
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter account number for first account: ");
        accountNumber1 = scanner.nextInt();
        System.out.print("Enter balance for first account: ");
        balance1 = scanner.nextDouble();
        System.out.print("Enter account number for second account: ");
        accountNumber2 = scanner.nextInt();
        System.out.print("Enter balance for second account: ");
        balance2 = scanner.nextDouble();
        scanner.close();
        BankAccount a = new BankAccount(accountNumber1, balance1);
        BankAccount b = new BankAccount(accountNumber2, balance2);
        a.display();
        b.display();
    }
}

OUTPUT:

Enter balance for first account: Enter account number for second account: Enter balance for second account: Account number: 123456 Balance: $210.00 Account number: 987456 Your balance was reduced to 0 as balance was below required minimum $200.00 Balance: $0.00

Add a comment
Know the answer?
Add Answer to:
Create a class named BankAccount with data fields for a count number and a balance. Include...
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
  • C++ Please create the class named BankAccount with the following properties below: // The BankAccount class...

    C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (name & ID), keeps track of a user's available balance. // It also keeps track of how many transactions (deposits and/or withdrawals) are made. public class BankAccount { Private String name private String id; private double balance; private int numTransactions; // Please define method definitions for Accessors and Mutator functions below Private member variables string getName(); // No set...

  • Design a class named BankAccount containing the following data field and methods. • One double data...

    Design a class named BankAccount containing the following data field and methods. • One double data field named balance with default values 0.0 to denote the balance of the account. • A no-arg constructor that creates a default bank account. • A constructor that creates a bank account with the specified balance.  throw an IllegalArgumentException when constructing an account with a negative balance • The accessor method for the data field. • A method named deposit(double amount) that deposits...

  • Design a class named BankAccount that contains: 1. A private int data field named accountId for...

    Design a class named BankAccount that contains: 1. A private int data field named accountId for the account. 2. A private double data field named accountBalance for the account (default 0). 3. A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. 4. A private Date data field named dateCreated that stores the date when the account was created. 5. A private int data field named numberOfDeposits...

  • Java Programming assignment. 1. Create a class called Square that takes a width parameter in the...

    Java Programming assignment. 1. Create a class called Square that takes a width parameter in the constructor. The Square class should have a draw() method that will draw the square on the screen. Create a class called TestSquare that will take width from the user, create an object of Square, and invoke the draw() method on the square object. Below is a UML diagram for the Square and Rectangle class: 3. Create a zip file that contains your Java programs....

  • Graded Exercise Create a class named Student. A Student has fields for an ID number, number...

    Graded Exercise Create a class named Student. A Student has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point...

  • Design and implement the following 3 classes with the exact fields and methods (these names and c...

    Design and implement the following 3 classes with the exact fields and methods (these names and caps exactly): 1. An abstract class named BankAccount (java file called BankAccount.java) Description Filed/Method Balance NumberDeposits NumberWithdrawals AnnualInterestRate MonthlyServiceCharge BankAccount SetHonthlyServiceCharges A method that accepts the monthly service charges as an argument and set the field value GetBalance GetNum berDeposits GetNum berWithdrawals GetAnnualinterestRate GetMonthlyServiceCharge A method that returns the monthly service charge Deposit field for the bank account balance A field for the number...

  • C++ Design a class bankAccount that defines a bank account as an ADT and implements the...

    C++ Design a class bankAccount that defines a bank account as an ADT and implements the basic properties of a bank account. The program will be an interactive, menu-driven program. a. Each object of the class bankAccount will hold the following information about an account: account holder’s name account number balance interest rate The data members MUST be private. Create an array of the bankAccount class that can hold up to 20 class objects. b. Include the member functions to...

  • (The Account class) Design a class named Account that contains: A private int data field named...

    (The Account class) Design a class named Account that contains: A private int data field named id for the account (default 0). A private double data field named balance for the account (default 0). A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default...

  • a. Create a class named Lease with fields that hold an apartment tenant's name, apartment Number,...

    a. Create a class named Lease with fields that hold an apartment tenant's name, apartment Number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name. "XXX", the apartment number to O, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a nonstatic method named addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy...

  • TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static...

    TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...

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
ADVERTISEMENT