This is a java exercise in creating an aggregation of object
This is a java exercise in creating an aggregation of objects, I want you to do something similar per the following UML diagrams. I will provide you with a program to test your files with. Neither the class variables nor the methods are static (ie. leave out the static modifier).
Account Business String type String number Double balance String name String type Account acct Constructor(s) String getType() void setType (String pTyp) String getNumber() voidsetNumber(String pNbr) Double getBalance) void setBalance Doubl String toString Constructor(s) String getName() void setName(String pNme) String getType() void setType(String pTyp) Account getAcct() void setAcct(Account pAcct) String toString() le pBal)ASolution
Source-code for first class(base class) name Account is below..
..........................................................................................................................
package businessaccounttester;
public class Account {
String type;
String number;
Double balance;
public Account() {
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public Double getBalance() {
return balance;
}
public void setBalance(Double balance) {
this.balance = balance;
}
@Override
public String toString() {
return \"Account{\" + \"type=\" + type + \", number=\" + number + \", balance=\" + balance + \'}\';
}
}
...........................................................................................................................
Source-code for second class( aggregate class) name Business is below.
...................................................................................................................................
package businessaccounttester;
public class Business {
String name;
String type;
Account acct;
public Business() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Account getAcct() {
return acct;
}
public void setAcct(Account acct) {
this.acct = acct;
}
@Override
public String toString() {
return \"Business{\" + \"name=\" + name + \", type=\" + type + \", acct=\" + acct + \'}\';
}
}
..................................................................................................................................
main Class code below.
..................................................................................................................................
package businessaccounttester;
public class BusinessAccountTester {
public static void main(String[] args) {
Account acct_1 = new Account();
acct_1.setType(\"Checking\");
acct_1.setNumber(\"4332 7789 4223 0987\");
acct_1.setBalance(4250.00);
Account acct_2 = new Account();
acct_2.setType(\"Savings\");
acct_2.setNumber(\"6543 2231 5432 7088\");
acct_2.setBalance(3475.99);
//System.out.println(acct_1.tostring());
Business bus_1 = new Business();
bus_1.setName(\"Joe\'s Pizza\");
bus_1.setType(\"Food\");
bus_1.setAcct(acct_2);
Business bus_2 = new Business();
bus_2.setName(\"Carl\'s Excavating\");
bus_2.setType(\"Landscaping\");
bus_2.setAcct(acct_1);
System.out.println(\"Now output the instance variable values for the 2 Businesses\ \");
String s1 = bus_1.toString();
System.out.println(s1);
String s2 = bus_2.toString();
System.out.println(s2);
System.out.println(\"\ Thank you for your patience\");
}
}
output........................................
Now output the instance variable values for the 2 Businesses
Business{name=Joe\'s Pizza, type=Food, acct=Account{type=Savings, number=6543 2231 5432 7088, balance=3475.99}}
Business{name=Carl\'s Excavating, type=Landscaping, acct=Account{type=Checking, number=4332 7789 4223 0987, balance=4250.0}}
Thank you for your patience


