Exercice 1:
Propose a class diagram relating to the following code (Reverse Engineering)
public class Advertiser {
public class Account {
private Set<Account> accounts;
private Advertiser owner;
public Advertiser() {
accounts = new HashSet<Account>();
}
public void setOwner(Advertiser newOwner) {
if (owner != newOwner) {
Advertiser old = owner;
owner = newOwner;
if (newOwner != null) {
a.setOwner(this);
newOwner.addAccount(this);
}
if (old != null) {
old.removeAccount(this);
}
}
}
public void addAccount(Account a) {
owner = newOwner;
accounts.add(a);
if (newOwner != null) {
a.setOwner(this);
newOwner.addAccount(this);
}
}
public void removeAccount(Account a) {
if (oldOwner != null) {
accounts.remove(a);
a.setOwner(null);
old.removeAccount(this);
}
}
}
}
Exercice 2:
Translate into Java the following UML class diagram
public class PizzaBoom {
private Pizza[] menu;
private int quantitySold;
public PizzaBoom(int size) {
menu = new Pizza[size];
quantitySold = 0;
}
public void sellPizza(String variety, int size, int quantitySold) {
// Implementation not provided
}
public void logSales(String fileName) {
// Implementation not provided
}
public void displaySalesFromFile(String fileName) {
// Implementation not provided
}
public void storelnObjectFile(String fileName) {
// Implementation not provided
}
public void displayMenuBySizeFromFile(String fileName, int minSize) {
// Implementation not provided
}
}
public class Pizza {
private String variety;
private int size;
public Pizza(String variety, int size) {
this.variety = variety;
this.size = size;
}
}