8.2or8.1 java netbean. I do not know why the other query did not work in netbean
ID: 3855169 • Letter: 8
Question
8.2or8.1 java netbean. I do not know why the other query did not work in netbean
Project: The Account Class
Problem Description:
(The Account class) Design a class named Account that contains:
A private intdata field named id for the account (default 0).
A private String data field namefor the account (default “No Name yet”)
A private doubledata field named balance for the account (default 0).
A private doubledata field named annualInterestRate that stores the current interest rate (default 0).
A private Datedata field named dateCreated that stores the date when the account was created. (You may make this a String field and access the date with the .toString()method in String.
A private int data field named transactionsfor the account (default is 0).
A private intstatic data field named numberOfAccounts that stores the current number of accounts created.
A no-arg constructor that creates a default account.
A constructor that creates an account with the specified id, name, initial balance,and annualInterestRate.
The accessor and mutator methods for id, name, balance, and annualInterestRate.
The accessor method for dateCreated.
A method named withdrawthat withdraws a specified amount from the account.
A method named depositthat deposits a specified amount to the account.
A method named displayAccountwhich will show all the information in the account.
A method name transferFunds which will transfer money from one account to another.
Draw the UML diagram for the class.
Implement the class and do the following:
Write a test (client) program.
Create an Accountobject with an account ID of 1122, and a name of “Fred” with a balance of $20,000, and an annual interest rate of 4.5%. Show the account.
Use the withdrawmethod to withdraw $2,500, use the deposit method to deposit $3,000. Show the account.
Create another Accountobject with an account ID of 1124, and a name of “Gloria” with a balance of $2,000, and an annual interest rate of 14.5%. Show the account.
Use the withdrawmethod to withdraw $500, use the deposit method to deposit $300. Show the account.
Use the transferFunds method to transfer 1000 from Fred’s account to Gloria’s account. Show both accounts.
Use the displayAccount method to show the results for both accounts.
Explanation / Answer
Find the program..
Account.java
public class Account {
private int id;
private String name;
private double balance;
private double annualInterestRate;
private String dateCreated;
private int transactions;
private static int numberOfAccounts;
/**
*
*/
public Account1() {
super();
id = 0;
name = "";
balance = 0d;
annualInterestRate = 0d;
transactions = 0;
}
/**
* @param id
* @param name
* @param balance
* @param annualInterestRate
*/
public Account1(int id, String name, double balance, double annualInterestRate) {
super();
this.id = id;
this.name = name;
this.balance = balance;
this.annualInterestRate = annualInterestRate;
}
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the balance
*/
public double getBalance() {
return balance;
}
/**
* @param balance the balance to set
*/
public void setBalance(double balance) {
this.balance = balance;
}
/**
* @return the annualInterestRate
*/
public double getAnnualInterestRate() {
return annualInterestRate;
}
/**
* @param annualInterestRate the annualInterestRate to set
*/
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
/**
* @return the dateCreated
*/
/**
* @return the dateCreated
*/
public String getDateCreated() {
return dateCreated;
}
/**
* @param dateCreated the dateCreated to set
*/
public void setDateCreated(String dateCreated) {
this.dateCreated = dateCreated;
}
public double withdraw(double amount) {
balance -= amount;
return balance;
}
public double deposit(double amount) {
balance += amount;
return balance;
}
public String displayAccount() {
return "[" + id + ", " + name + ", " + balance + ", " + annualInterestRate + ", " + dateCreated + ", "
+ transactions + ", " + getId() + ", " + getName() + ", " + getBalance() + ", "
+ getAnnualInterestRate() + ", " + getDateCreated() + ", " + getClass() + ", " + hashCode() + ", "
+ super.toString() + "]";
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "[" + id + ", " + name + ", " + balance + ", " + annualInterestRate + ", " + dateCreated + ", "
+ transactions + ", " + getId() + ", " + getName() + ", " + getBalance() + ", "
+ getAnnualInterestRate() + ", " + getDateCreated() + ", " + getClass() + ", " + hashCode() + ", "
+ super.toString() + "]";
}
public double transferFunds(int id, double amount){
balance += amount;
return balance;
}
}
AccountTest.java
public class AccountTest {
public static void main(String[] args) {
Account acc= new Account(1122, "Fred", 20000, 4.5);
acc.displayAccount();
acc.withdraw(2500);
acc.deposit(3000);
acc.displayAccount();
Account acc1 = new Account(1124, "Gloria", 2000, 14.5);
acc1.displayAccount();
acc1.withdraw(500);
acc1.deposit(300);
acc1.displayAccount();
acc.transferFunds(1124, 1000);
acc.displayAccount();
acc1.displayAccount();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.