Question

In: Computer Science

Design a class named Account (put it in a package named accountspackages) with the following UML...

Design a class named Account (put it in a package named accountspackages) with the following UML diagram:

Account

-customerID: int

-customerName: String

-balance: double

+setCustomerID(int): void

+setCustomerName(String): void

+setBalance(double):void

+getCustomerID(): int

+getCustomerName(): String

+getBalance(): double

+deposit(double): void

+withdraw(double): void

+printInformation():void

The method withdraw(double) withdraws a specified amount from the account if the amount is less than or equal the balance, otherwise the method prints the message:

Sorry! The account does not have sufficient funds.

The method printInformation() prints:

    the customerName, the customerID, and the account balance.

Test the Account class by running the following code

(You are not allowed to modify this code):

package accountsdemocom;

public class AccountDemo{

   public static void main(String[] args) {

        Account accountOne = new Account();

        Account accountTwo = new Account();              

        accountOne.setCustomerID(78654);

        accountOne.setCustomerName("John Smith");

        accountOne.deposit(10000.0);

        accountOne.withdraw(25000.0);

        accountTwo.setCustomerID(76234);

        accountTwo.setCustomerName("Jennifer Harris");

        accountOne.deposit(2000.0);

        accountOne.withdraw(150.0);

        accountOne.printInformation();

        accountTwo.printInformation();

        accountOne.withdraw(250.0);

        accountOne.getBalance();     

    }

}

Solutions

Expert Solution

Account.java

package accountspackages;

public class Account {

    private int customerID;
    private String customerName;
    private double balance;

    public Account() {
    }

    public void setCustomerID(int id) {
        customerID = id;
    }

    public void setCustomerName(String name) {
        customerName = name;
    }

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

    public int getCustomerID() {
        return customerID;
    }

    public String getCustomerName() {
        return customerName;
    }

    public double getBalance() {
        return balance;
    }

    public void deposit(double amount) {
        balance += amount;
    }

    public void withdraw(double amount) {
        if (amount <= balance) {
            balance -= amount;
        } else {
            System.err.println("Sorry! The account does not have sufficient funds.(ID: " + customerID + ")");
        }
    }

    public void printInformation() {
        System.out.println("ID: " + customerID + " Name: " + customerName + " Balance: " + balance);
    }
}

AccountDemo.java

import accountspackages.Account;

public class AccountDemo {
    public static void main(String[] args) {
        Account accountOne = new Account();
        Account accountTwo = new Account();
        accountOne.setCustomerID(78654);
        accountOne.setCustomerName("John Smith");
        accountOne.deposit(10000.0);
        accountOne.withdraw(25000.0);
        accountTwo.setCustomerID(76234);
        accountTwo.setCustomerName("Jennifer Harris");
        accountOne.deposit(2000.0);
        accountOne.withdraw(150.0);
        accountOne.printInformation();
        accountTwo.printInformation();
        accountOne.withdraw(250.0);
        accountOne.getBalance();
    }
}


Related Solutions

PUT IN JAVA PROGRAMMING The StockB class: Design a class named StockB that contains the following...
PUT IN JAVA PROGRAMMING The StockB class: Design a class named StockB that contains the following properties: • Name of company • Number of shares owned • Value of each share • Total value of all shares and the following operations: • Acquire stock in a company • Buy more shares of the same stock • Sell stock • Update the per-share value of a stock • Display information about the holdings • The StockB class should have the proper...
7.3 (The Account class) Design a class named Account that contains: ■ A private int data...
7.3 (The Account class) Design a class named Account that contains: ■ A private int data field named id for the account. ■ A private float data field named balance for the account. ■ A private float data field named annualInterestRate that stores the current interest rate. ■ A constructor 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...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the...
Write a C++ program (The Account Class) 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....
Put In Java Programming The TicketMachine class: Design a class named TicketMachine that contains: • A...
Put In Java Programming The TicketMachine class: Design a class named TicketMachine that contains: • A double data field named price (for the price of a ticket from this machine). • A double data field named balance (for the amount of money entered by a customer). • A double data field named total (for total amount of money collected by the machine). • A constructor that creates a TicketMachine with all the three fields initialized to some values. • A...
PUT IN JAVA PROGRAMMING The Stock class: Design a class named Stock that contains: • A...
PUT IN JAVA PROGRAMMING The Stock class: Design a class named Stock that contains: • A string data field named symbol1 for the stock’s symbol. • A string data field named name for the stock’s name. • A double data field named previousClosingPrice that stores the stock price for the previous day. • A double data field named currentPrice that stores the stock price for the current time. • A constructor that creates a stock with the specified symbol and...
In a package named "oop" create a Scala class named "Score" with the following: • A...
In a package named "oop" create a Scala class named "Score" with the following: • A constructor that takes an Int and stores it in a member variable named score • A method named scoreGoal that takes no parameters and has return type Unit that increments the score by 1 • A method named isWinner that takes a Score object as a parameter and returns a Boolean. The method returns true if this instances score is strictly greater than the...
PUT IN JAVA PROGRAMMING The Rectangle class: Design a class named Rectangle to represent a rectangle....
PUT IN JAVA PROGRAMMING The Rectangle class: Design a class named Rectangle to represent a rectangle. The class contains: • Two double data fields named width and height that specify the width and height of a rectangle. The default values are 1 for both width and height. • A no-arg (default) constructor that creates a default rectangle. • A constructor that creates a rectangle with the specified width and height. • A method named findArea() that finds the area of...
Design a class named Account that contains: A private int data field named id for the...
Design a class named Account that contains: A private int data field named id for the account. A private double data field named balance for the account. A private double data field named annualInterestRate that stores the current interest rate. A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. The accessor and mutator methods for id, balance, and annualInterestRate. A method named getMonthlyInterestRate() that returns the monthly interest rate. A method named withdraw(amount)...
Design a class named Account that contains: A private String data field named accountNumber for the...
Design a class named Account that contains: A private String data field named accountNumber for the account (default AC000). A private double data field named balance for the account (default 0). A private double data field named annualIntRate 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 account. A constructor...
Java - Design a class named Account that contains: A private String data field named accountNumber...
Java - Design a class named Account that contains: A private String data field named accountNumber for the account (default AC000). A private double data field named balance for the account (default 0). A private double data field named annualIntRate 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 account....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT