Question

In: Computer Science

The Account class Create a class named Account, which has the following private properties:

in java


 The Account class

 Create a class named Account, which has the following private properties:

 number: long

 balance: double

 Create a no-argument constructor that sets the number and balance to zero.

 Create a two-parameter constructor that takes an account number and balance.

 First, implement getters and

 setters: getNumber (), getBalance (), setBalan newBalance). There is no setNumber ()

 once an account is created, its account number cannot change.

 Now implement these methods: void

 deposit (double amount) and void withdraw (double amount). For both these

 methods, if the amount is less than zero, the account balance remains untouched. For

 the withdraw () method, if the amount is greater than the balance, it remains untouched.

 Then, implement a tostring method that

 returns a string with the account number and

 balance, properly labeled.


The Savingsaccount class

 This class inherits from Account and adds a

 private apr property, which is the annual percentage rate for interest. Write a no-argument

 constructor that sets the account number, balanace, and APR to zero. Write a three- argument constructor that takes an account number, balance, and interest rate as a decimal (thus, a 3.5% interest rate is given as 0.035).

 Add a getter and setter method for apr. The setter should leave the APR untouched if given a negative value. Write

 a calculateInterest () method that returns the annual interest, calculated as the current balance times the annual interest rate.

 Modify toString() to include the interest rate and annual interest.


 The CreditCardAccount class

 This class inherits from Account and adds a

 private apr property, which is the annual interest rate charged on the balance. It also has a

 private creditLimit property (double) which gives the credit limit for the card. Write a no-argument constructor that sets all the properties

 to zero. Write a four-argument constructor that takes an account number, balance, interest rate as a decimal (thus, a 3.5% interest rate is given as 0.035), and credit limit. Write getters and setters for the apr and creditLimit.

 Override the withdraw() function so that you can have a negative balance. If a withdrawal would push you over the credit limit, leave the balance untouched. Examples:

 If your balance is $300 with a credit limit of

 $700, you can withdraw $900 (leaving a balance of $-600).

 If your balance is $-300 with a credit limit of $700, you can withdraw $350 (leaving a balance of $-650).

 If your balance is $-300 with a credit limit of $700, you can not withdraw $500, because that would then owe $800, which is more than your $700 limit.

 In short, the maximum amount you can withdraw is your current balance plus the credit limit.

 Add a calculatePayment () method that works

 as follows:

 In short, the maximum amount you can withdraw is your current balance plus the credit limit.

 Add a calculatePayment () method that works as follows:

 If the balance is positive, the minimum

 amount you have to pay on your card per

 month is zero.

 Otherwise, your monthly payment is the

 minimum of 20 and (apr/12) . (-balance)

 (apr/12).(-balance)

 Modify tostring() to include the interest rate,

 credit limit, and monthly payment.

 The Test Program

 Write a program named TestAccounts that

 creates an array of five Account objects:

 • An Account number 1066 with a balance of

 $7,500.

 A SavingsAccount number 30507 with a

 balance of $4,500 and an APR of 1.5%

 A CreditCardAccount number 51782737

 with a balance of $7,000.00, APR of 8%, and

 credit limit of $1000.00

 A CreditCardAccount number

 629553328 with a balance of $1,500.00, an

 APR of 7.5%, and a credit limit of $5,000

 . A CreditcardAccount number

 4977201043 with a balance of -$5,000.00,

 an APR of 7%, and a credit limit of $10,000

 Your program will use a loop to do the following

 for each account:

 Deposit $2,134.00

 .

 Withdraw $4,782.00

 .

 Print the account status using tostring ()

 Here is some sample output:

 Account: 1066

 Balance: $4852.00

 Account: 30507

 Balance: $1852.00

 Interest Rate: 1.50%

 Annual Interest: $27.78

 Account: 51782737

 Balance: $4352.00

 Interest Rate: 8.00%

 Credit Limit: $1000.00

 Monthly Payment: $0.00

 Account: 629553328

 Balance: $-1148.00

 Interest Rate: 7.50%

 Credit Limit: $5000.00

 Monthly Payment: $7.18



Solutions

Expert Solution

// Account.java

import java.text.DecimalFormat;

public class Account {
   private long number;
   private double balance;

   public Account() {
       this.number = 0;
       this.balance = 0;
   }

   /**
   * @param number
   * @param balance
   */
   public Account(long number, double balance) {
       this.number = number;
       this.balance = balance;
   }

   /**
   * @return the number
   */
   public long getNumber() {
       return number;
   }

   /**
   * @param number
   * the number to set
   */
   public void setNumber(long number) {
       this.number = number;
   }

   /**
   * @return the balance
   */
   public double getBalance() {
       return balance;
   }

   /**
   * @param balance
   * the balance to set
   */
   public void setBalance(double balance) {
       this.balance = balance;
   }

   public void withdraw(double amt) {
       if (balance - amt >= 0) {
           this.balance -= amt;
       }
   }

   public void deposit(double amt) {
       if (amt > 0)
           this.balance += amt;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       // DecimalFormat class is used to format the output
       DecimalFormat df = new DecimalFormat(".00");
       return "Account :" + number + "\nBalance :$" + df.format(balance);
   }

}
___________________________

// SavingsAccount.java

import java.text.DecimalFormat;

public class SavingsAccount extends Account {
   private double apr;

   public SavingsAccount() {
       super();
       this.apr = 0;
   }

   /**
   * @param apr
   */
   public SavingsAccount(long number, double balance,double apr) {
       super(number,balance);
   setApr(apr);
   }

   /**
   * @return the apr
   */
   public double getApr() {
       return apr;
   }

   /**
   * @param apr the apr to set
   */
   public void setApr(double apr) {
       if(apr>0)
   this.apr = apr;
   }
  
   public double calculateInterest()
   {
       return getBalance()*(apr/100);
   }

   /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       // DecimalFormat class is used to format the output
       DecimalFormat df = new DecimalFormat(".00");
       return super.toString()+"\nInterest Rate :" + df.format(apr)+"%\nAnnual Interest :$"+df.format(calculateInterest());
   }
  
}

_______________________________

// CreditCardccount.java

import java.text.DecimalFormat;

import com.sun.swing.internal.plaf.basic.resources.basic;

public class CreditCardccount extends Account {
   private double apr;
   private double creditLimit;

   public CreditCardccount() {
       super();
       this.apr = 0;
       this.creditLimit = 0;
   }

   /**
   * @param apr
   * @param creditLimit
   */
   public CreditCardccount(long number, double balance,double apr, double creditLimit) {
       super(number,balance);
       setApr(apr);
       this.creditLimit = creditLimit;
   }

   /**
   * @return the apr
   */
   public double getApr() {
       return apr;
   }

   /**
   * @param apr the apr to set
   */
   public void setApr(double apr) {
       if(apr>0)
       this.apr = apr;
   }

   /**
   * @return the creditLimit
   */
   public double getCreditLimit() {
       return creditLimit;
   }

   /**
   * @param creditLimit the creditLimit to set
   */
   public void setCreditLimit(double creditLimit) {
       this.creditLimit = creditLimit;
   }

   @Override
   public void withdraw(double amt)
   {
       double bal=getBalance();
       if((creditLimit+getBalance())-amt>=0)
       {
           bal-=amt;
           super.setBalance(bal);
       }
   }
  
   public double calculatePayment()
   {
       double paymentAmt=0;
       if(getBalance()>=0)
       {
           paymentAmt=0;
       }
       else
       {
           paymentAmt=20+(apr/1200)*(-getBalance());
       }
       return paymentAmt;
   }

   /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       // DecimalFormat class is used to format the output
               DecimalFormat df = new DecimalFormat("0.00");
       return super.toString()+"\nInterest Rate:"+df.format(apr)+"%\nCredit Limit :$"+df.format(creditLimit)+"\nMonthly Payment :$"+df.format(calculatePayment());
   }
  
  
}
_____________________________

// Test.java

public class Test {

   public static void main(String[] args) {
       Account account[] = { new Account(1066, 7500),
               new SavingsAccount(30507, 4500, 1.5),
               new CreditCardccount(51782737, 7000, 8, 1000),
               new CreditCardccount(629553328, 1500, 1.5, 5000) };
      
       for(int i=0;i        {
           account[i].deposit(2134.00);
           account[i].withdraw(4782.00);
           System.out.println(account[i]+"\n");
       }

   }

}
_________________________

Output:

Account :1066
Balance :$4852.00

Account :30507
Balance :$1852.00
Interest Rate :1.50%
Annual Interest :$27.78

Account :51782737
Balance :$4352.00
Interest Rate:8.00%
Credit Limit :$1000.00
Monthly Payment :$0.00

Account :629553328
Balance :$-1148.00
Interest Rate:1.50%
Credit Limit :$5000.00
Monthly Payment :$21.43


Related Solutions

The Account class Create a class named Account , which has the following private properties:
 The Account class Create a class named Account , which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNunber(), getBalance(), setBalance (double newBalance) . There is no setNunber() - once an account is created, its account number cannot change. Now implement these methods: void deposit (double anount) and void withdraw(double anount). For both these methods, if the amount is less than zero,...
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement deposit(double amount) and withdraw(double amount) methods. If the amount is less than zero,...
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement deposit(double amount) and withdraw(double amount) methods. If the amount is less than zero,...
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement these methods: void deposit(double amount) and void withdraw(double amount). For both these methods,...
(In Matlab) Create a base class named Point that has the properties for x and y...
(In Matlab) Create a base class named Point that has the properties for x and y coordinates. From this class derive a class named Circle having an additional property named radius. For this derived class, the x and y properties represent the center coordinates of a circle. The methods of the base class should consist of a constructor, an area function that returns 0, and a distance function that returns the distance between two points. The derived class should have...
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...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (using name & id), and - keeps track of a user's available balance. - how many transactions (deposits and/or withdrawals) are made. public class BankAccount { private int id; private String name private double balance; private int numTransactions; // ** Please define method definitions for Accessors and Mutators functions below for the class private member variables string getName();...
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...
Create a class named “Car” which has the following fields. The fields correspond to the columns...
Create a class named “Car” which has the following fields. The fields correspond to the columns in the text file except the last one. i. Vehicle_Name : String ii. Engine_Number : String iii. Vehicle_Price : double iv. Profit : double v. Total_Price : double (Total_Price = Vehicle_Price + Vehicle_Price* Profit/100) 2. Write a Java program to read the content of the text file. Each row has the attributes of one Car Object (except Total_Price). 3. After reading the instances of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT