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

. Item, Purchase, Company. Study the following UML diagram Create the three blue

ID: 3733140 • Letter: #

Question

. Item, Purchase, Company. Study the following UML diagram

Create the three blueprints above. Then create a driver that instantiates two Purchase instances. Note that the driver also must have a method to print the purchases and another to total the cost of the purchases. The output should be similar to

A TV with a cost of 450.0 was purchased from Samsung with a phone number of 123-4567

A Phone with a cost of 650.0 was purchased from Apple with a phone number of 765-4321

The total cost of the two items is 1100.0

ePurchase midterm2018ANSWERSitp120 Java Class>> GItem midterm2018ANSWERStp120 Purchase0 Purchase(ltem,Company) to String0:String .getltem(O:ltem GCompany midterm2018ANSWERSitp120 -ite can desc: String cost: double name: String 01 phone: String dItem) dItem(String,double) getCompo:Company setComp Company)rvoid Company Company(String,String) toString0:String toString(): String getDesc0:String setDesc(String)void getCost():double setCost(double):void 0:String .setName(String)void getPhone):String Java Class>> e PurchaseDriver midterm2018ANSWERSitp 120 .setPhone(String)void PurchaseDriver) main String[l)void print Purchase Purchase)void total Purchase Purchase)double

Explanation / Answer

Company.java

public class Company {
//Declaring instance variables
private String name;
private String phone;

//Zero argumented constructor
public Company() {

}

//Parameterized constructor
public Company(String name, String phone) {
super();
this.name = name;
this.phone = phone;
}

// getters and setters
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

}

_________________

Item.java

public class Item {
//Declaring instance variables
private String des;
private double cost;

//Zero argumented constructor
public Item() {

}

//Parameterized constructor
public Item(String des, double cost) {
super();
this.des = des;
this.cost = cost;
}

// getters and setters
public String getDes() {
return des;
}

public void setDes(String des) {
this.des = des;
}

public double getCost() {
return cost;
}

public void setCost(double cost) {
this.cost = cost;
}

}

___________________

Purchase.java

public class Purchase {
//Declaring instance variables
private Item item;
private Company comp;

//Zero argumented constructor
public Purchase() {

}
//Parameterized constructor
Purchase(Item i, Company c) {
this.item = i;
this.comp = c;
}
//getters and setters
public Item getItem() {
return item;
}
public void setItem(Item item) {
this.item = item;
}
public Company getComp() {
return comp;
}
public void setComp(Company comp) {
this.comp = comp;
}

}

____________________

PurchaseDriver.java

public class PurchaseDriver {

public static void main(String[] args) {
//Creating an Instances of Purchase class object
Purchase p1 = new Purchase(new Item("TV", 450.0), new Company("Samsung", "123-4567"));
Purchase p2 = new Purchase(new Item("Phone", 650.0), new Company("Apple", "765-4321"));

//calling the methods
print(p1, p2);
double tot = total(p1, p2);
System.out.println("The total cost of the two items is " + tot);

}

private static double total(Purchase p1, Purchase p2) {

return p1.getItem().getCost() + p2.getItem().getCost();
}

private static void print(Purchase p1, Purchase p2) {
System.out.println("A " + p1.getItem().getDes() + " with a cost of " + p1.getItem().getCost() + " was purchased from " + p1.getComp().getName() + " with a phone number of " + p1.getComp().getPhone());
System.out.println("A " + p2.getItem().getDes() + " with a cost of " + p2.getItem().getCost() + " was purchased from " + p2.getComp().getName() + " with a phone number of " + p2.getComp().getPhone());

}

}

____________________

Output:

A TV with a cost of 450.0 was purchased from Samsung with a phone number of 123-4567
A Phone with a cost of 650.0 was purchased from Apple with a phone number of 765-4321
The total cost of the two items is 1100.0

_______________Thank You