Code example of High Coupling-01842

Online Quiz This subjective question is related to the book/course vu mgt101 Financial Accounting. It can also be found in vu mgt101 Mid Term Solved Past Paper No. 3.

Question 1: Code example of High Coupling
Answer:

Tightly Coupled Example:

public class CartEntry{
public float Price; public int Quantity;
}
public class CartContents {
public CartEntry[] items;
}
public class Order {
private CartContents cart;
private float salesTax;
public Order(CartContents cart, float salesTax) {
this.cart = cart;
this.salesTax = salesTax;
}
public float OrderTotal() {
float cartTotal = 0;
for (int i = 0; i < cart.items.Length; i++) {
cartTotal += cart.items[i].Price * cart.items[i].Quantity;
}
cartTotal += cartTotal*salesTax; return cartTotal;
}
}

Reference: Lecture No. 14


Choose an organization

Theme Customizer

Gaussian Texture



Gradient Background