Fallowing code explain the loose coupling concept. I want to implement the main method to added items (with price and quantity) and calculate the total price with sales tax. How I implement the main method.
class ShopingCartEntry {
public float price;
public int quantity;
public float getTotalPrice() {
return price * quantity;
}
}
class ShopingCartContents {
public ShopingCartEntry[] items;
public float getTotalPrice() {
float totalPrice = 0;
for (ShopingCartEntry item : items) {
totalPrice += item.getTotalPrice();
}
return totalPrice;
}
}
class Order {
private ShopingCartContents cart;
private float salesTax;
public Order(ShopingCartContents cart, float salesTax) {
this.cart = cart;
this.salesTax = salesTax;
}
public float orderTotalPrice() {
return cart.getTotalPrice() * (1.0f + salesTax);
}
}
public class LooseCoupling {
public static void main(String[] args) {
}
}