Question
Fix my code and make it complete: Question Write a class Account to represent a bank account with the following members: Account = {type, accountHolderName,
Question
Write a class \"Account\" to represent a bank account with the following members:
Account = {type, accountHolderName, creationDate, balance, category}
Note that \"type\" = checking or saving
and \"category\" = gold or silver
Implement the following methods:
1) all constructors, toString method, getters and setters.
2) functions AddMoney, RemoveMoney, CheckBalance, ShowTransactionHistory, showAllAccounts
The main function should be something like this:
//create an account and set the initial parameters
Account my = new Account();
my.SetType(\"checking\"); //account has only two types, checking/saving
my.SetAccountHolderName(\"Tariq\");
my.SetCreationDate(8, 10, 2017); //this is the date when account is created
my.SetBalance(3000); //this is the opening balance
//Only two categories are allowed: Gold/Silver.
//note that if account balance is more than 100K, category should be Gold, otherwise Silver.
//now, lets call some functions on 'my' object
my.AddMoney(4000);
my.CheckBalance(); //display a balance of 7000
my.RemoveMoney(1000);
my.CheckBalance(); //display a balance of 6000
my.ShowTransactionHistory(); //displays a history of all the above
//the above function ShowTransactionHistory() should display the following:
//SAR 4000 added on 8/10/2017
//SAR 1000 removed on 8/10/2017
//now lets create another account
Account your = new Account(my);
your.SetType(\"saving\");
your.SetAccountHolderName(\"Ahmed\");
your.SetCreationDate(8, 10, 2017);
my.SetBalance(200000);
//now print all the accounts created so far
Account.ShowAllAccounts();//displays the following about all the accounts
//Total accounts created = 2
//Total Silver members = 1
//Total Gold members = 1
Incomplete code that needs to be fixed
/* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template */ package homework2;
/** * * @author */ class Date{ int day; int month; int year; public void Set(int d, int m, int y){ day=d;month=m;year=y;
} }
class Account {
public String accountHolderName, type,category,histransactions; public int balance; Date creationDate; public static int count=0; public static int gold=0; public static int silver=0; public Account() { count+=1; this.accountHolderName = \"\"; this.type = \"\"; this.category = \"Sliver\"; silver++; //this.creationDate = \"\"; this.balance = 0; histransactions = \"\"; } public Account(String accountHolderName, String type, String creationDate, int balance) { this.type = type; this.accountHolderName = accountHolderName; // this.creationDate = creationDate; this.balance = balance; if(balance>100000) { Account.gold+=1; this.category =\"Gold\"; } else { Account.silver+=1; // this or account this.category=\"Silver\"; } } public String getType() { return type; } public String getAccountHolderName() { return accountHolderName; }
public void setAccountHolderName(String accountHolderName) { this.accountHolderName = accountHolderName; } public Date getCreationDate() // make object up { return creationDate; }
public void setCreationDate(int day,int month,int year) { this.creationDate.Set(day, month, year); } public String getCategory() { return category; }
public void setCategory(String category) { this.category = category; }
public int getBalance() { return balance; }
public void setBalance(int balance) { this.balance = balance; } public void AddMoney(int bal) { balance += bal; if(balance>=100000) setBalance(balance); this.category = \"gold\"; transactionHistory.add(\"SAR \"+balance+\" added on \"+creationDate); } public void RemoveMoney(int bal) { balance -= bal; if(balance setBalance(balance); this.category = \"silver\"; transactionHistory.add(\"SAR \"+balance+\" added on \"+creationDate); } public void CheckBalance() { System.out.println(\"The balance of \"+getAccountHolderName()+\" is \"+getBalance()); } public static void showAllAccounts() { System.out.println(\"Totat Accounts created = \"+count); System.out.println(\"Total Silver accounts = \"+silver); System.out.println(\"Total Gold accounts = \"+ gold); } } public class Homework2 {
/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Account my= new Account(); my.AddMoney(4000); my.CheckBalance(); my.RemoveMoney(1000); my.CheckBalance(); my.ShowTrascationHistory();// dislplays 400 and 1000 Account your=new Account(my); your.setType(\"saving\"); your.setAccountHolderName(\"Ahmed\"); your.setCreationDate(8, 10, 2017); my.setBalance(2000000); Account.ShowAllAccounts(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started