Using a drawing tool, such as PowerPoint, Visio, etc., create a Class diagram th
ID: 3806511 • Letter: U
Question
Using a drawing tool, such as PowerPoint, Visio, etc., create a Class diagram that illustrates the inheritance relationships implemented in Program 1.
Then, as a secondary step, imagine you are modeling a Bank class that actualizes an AGGREGATION relationship with the Account object... such that 0..n Accounts can be associated with the Bank class.
Submit one Class Diagram that shows all for this assignment.
Program 1 is LISTED below.
public class CheckingAccount {
private int id;
private double balance;
private double annualInterestRate;
private java.util.Date dateCreated;
double data[] = new double[20];
public CheckingAccount() {
dateCreated = new java.util.Date();
}
public CheckingAccount(int id, double balance, double annualInterestRate) {
this.id = id;
this.balance = balance;
this.annualInterestRate = annualInterestRate;
dateCreated = new java.util.Date();
}
public int getId() {
return this.id;
}
public double getBalance() {
return balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setId(int id) {
this.id =id;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
public double getMonthlyInterest() {
return balance * (annualInterestRate / 1200);
}
public java.util.Date getDateCreated() {
return dateCreated;
}
public void withdraw(double amount) {
balance -= amount;
}
public void deposit(double amount) {
balance += amount;
}
public static void main (String[] args) {
/* Account account = new Account(1122, 20000, 4.5);
account.withdraw(10000);
account.deposit(3000);
System.out.println("Balance is " + account.getBalance());
System.out.println("Monthly interest is " + account.getMonthlyInterest());
System.out.println("This account was created at " + account.getDateCreated());
*/
CheckingAccount newMemberChkAcct=new CheckingAccount();
newMemberChkAcct.setLastCheckNumber(100);
newMemberChkAcct.setOverdraftProection(true);
SavingsAccount newSavingsChkAcct=new SavingsAccount();
newSavingsChkAcct.setHighBalance(2300.55);
System.out.println("Last Check Number : newMemberChkAcct :"+newMemberChkAcct.getLastCheckNumber());
System.out.println("OverDraft Protection : newMemberChkAcct :"+newMemberChkAcct.getOverdraftProection());
System.out.println("High Balance : newSavingsChkAcct :"+newSavingsChkAcct.getHighBalance());
System.out.println("Premium Number :newSavingsChkAcct :"+newSavingsChkAcct.getPremiumNumber());
}
}
class CheckingAccount extends Account{
public int lastCheckNumber;
public boolean overdraftProection;
public CheckingAccount(){
super();
lastCheckNumber=0;
overdraftProection=false;
}
public CheckingAccount(int id, double balance, double annualInterestRate, int lastCheckNumber, boolean overdraftProection){
super(id,balance,annualInterestRate);
this.lastCheckNumber=lastCheckNumber;
this.overdraftProection=overdraftProection;
}
public int getLastCheckNumber(){
return lastCheckNumber;
}
public boolean getOverdraftProection(){
return overdraftProection;
}
public void setLastCheckNumber(int lastCheckNumber){
this.lastCheckNumber=lastCheckNumber;
}
public void setOverdraftProection(boolean overdraftProection){
this.overdraftProection=overdraftProection;
}
}
class SavingsAccount extends CheckingAccount{
public double highBalance;
public boolean premiumMember;
public SavingsAccount(){
super();
highBalance=0;
premiumMember=false;
}
public SavingsAccount(int id, double balance, double annualInterestRate, double highBalance, boolean premiumMember){
super(id,balance,annualInterestRate);
this.highBalance=highBalance;
this.premiumMember=premiumMember;
}
public double getHighBalance(){
return highBalance;
}
public boolean getPremiumNumber(){
return premiumMember;
}
public void setHighBalance(double highBalance){
this.highBalance=highBalance;
}
public void setPremiumNumber(boolean premiumMember){
this.premiumMember=premiumMember;
}
}
Explanation / Answer
public class CheckingAccount {
private int id;
private double balance;
private double annualInterestRate;
private java.util.Date dateCreated;
double data[] = new double[20];
public CheckingAccount() {
dateCreated = new java.util.Date();
}
public CheckingAccount(int id, double balance, double annualInterestRate) {
this.id = id;
this.balance = balance;
this.annualInterestRate = annualInterestRate;
dateCreated = new java.util.Date();
}
public int getId() {
return this.id;
}
public double getBalance() {
return balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setId(int id) {
this.id =id;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
public double getMonthlyInterest() {
return balance * (annualInterestRate / 1200);
}
public java.util.Date getDateCreated() {
return dateCreated;
}
public void withdraw(double amount) {
balance -= amount;
}
public void deposit(double amount) {
balance += amount;
}
public static void main (String[] args) {
/* Account account = new Account(1122, 20000, 4.5);
account.withdraw(10000);
account.deposit(3000);
System.out.println("Balance is " + account.getBalance());
System.out.println("Monthly interest is " + account.getMonthlyInterest());
System.out.println("This account was created at " + account.getDateCreated());
*/
CheckingAccount newMemberChkAcct=new CheckingAccount();
newMemberChkAcct.setLastCheckNumber(100);
newMemberChkAcct.setOverdraftProection(true);
SavingsAccount newSavingsChkAcct=new SavingsAccount();
newSavingsChkAcct.setHighBalance(2300.55);
System.out.println("Last Check Number : newMemberChkAcct :"+newMemberChkAcct.getLastCheckNumber());
System.out.println("OverDraft Protection : newMemberChkAcct :"+newMemberChkAcct.getOverdraftProection());
System.out.println("High Balance : newSavingsChkAcct :"+newSavingsChkAcct.getHighBalance());
System.out.println("Premium Number :newSavingsChkAcct :"+newSavingsChkAcct.getPremiumNumber());
}
}
class CheckingAccount extends Account{
public int lastCheckNumber;
public boolean overdraftProection;
public CheckingAccount(){
super();
lastCheckNumber=0;
overdraftProection=false;
}
public CheckingAccount(int id, double balance, double annualInterestRate, int lastCheckNumber, boolean overdraftProection){
super(id,balance,annualInterestRate);
this.lastCheckNumber=lastCheckNumber;
this.overdraftProection=overdraftProection;
}
public int getLastCheckNumber(){
return lastCheckNumber;
}
public boolean getOverdraftProection(){
return overdraftProection;
}
public void setLastCheckNumber(int lastCheckNumber){
this.lastCheckNumber=lastCheckNumber;
}
public void setOverdraftProection(boolean overdraftProection){
this.overdraftProection=overdraftProection;
}
}
class SavingsAccount extends CheckingAccount{
public double highBalance;
public boolean premiumMember;
public SavingsAccount(){
super();
highBalance=0;
premiumMember=false;
}
public SavingsAccount(int id, double balance, double annualInterestRate, double highBalance, boolean premiumMember){
super(id,balance,annualInterestRate);
this.highBalance=highBalance;
this.premiumMember=premiumMember;
}
public double getHighBalance(){
return highBalance;
}
public boolean getPremiumNumber(){
return premiumMember;
}
public void setHighBalance(double highBalance){
this.highBalance=highBalance;
}
public void setPremiumNumber(boolean premiumMember){
this.premiumMember=premiumMember;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.