Question: 4. Command pattern //class Stock public class Stock { private String name; private double price; public Product(String name, double price) { this.name = name; this.price
4. Command pattern //class Stock
public class Stock { private String name; private double price;
public Product(String name, double price) { this.name = name; this.price = price; } public void buy(int quantity){ System.out.println(BOUGHT: + quantity + x + this); } public void sell(int quantity){ System.out.println(SOLD: + quantity + x + this); } public String toString() { return Product [name= + name + , price= + price + ]; } }
a. Create two command classes that allows the customer to buy and sold stocks. b. Write a main method to test it.
5. Adapter pattern //interface NameInterface interface NameInterface { public void setName(String n);
public String getName(); }
//Adaptee class class SimpleName implements NameInterface { String name;
public void setName(String n) { name = n; }
public String getName() { return name; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
