Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming and logic I: Java Attached Files: This is an exercise in creating an

ID: 3836829 • Letter: P

Question

Programming and logic I: Java

Attached Files:

This is an exercise in creating an aggregation of objects similar to the aggregation discussed and reviewed using the chapter_6 zip file, 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).

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);

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 ");
System.out.println(bus_1.toString());
System.out.println();
System.out.println(bus_2.toString());
System.out.println(" Thank you for your patience");
  
}
}

Explanation / Answer

Below is your code: -

Account.java


public class Account {
   private String type;
   private String number;
   private Double balance;

   // Default Constructor
   Account() {
       type = "";
       number = "";
       balance = 0.0;
   }

   // Parametrized Constructor
   public Account(String type, String number, Double balance) {
       this.type = type;
       this.number = number;
       this.balance = balance;
   }

   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;
   }

   // Method to print the details of the object
   @Override
   public String toString() {
       return "Account [type=" + type + ", number=" + number + ", balance=" + balance + "]";
   }

}

Business.java


public class Business {
   private String name;
   private String type;
   private Account acct;

   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;
   }

   // Printing the details of the Business along with Account
   @Override
   public String toString() {
       return "Business [name=" + name + ", type=" + type + ", acct=" + acct + "]";
   }

}

Sample 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