Order

cs

School

Brigham Young University, Idaho *

*We aren’t endorsed by this school

Course

210

Subject

Information Systems

Date

Nov 24, 2024

Type

cs

Pages

2

Uploaded by ChancellorFreedomTapir22

Report
using System; public class Order { private List<Product> _products; private Customer _customer; public Order(List<Product> products, Customer customer) { _products = products; _customer = customer; } public double CalculateShipping() { double shippingCost = _customer.isFromUSA() ? 5 : 35; return shippingCost; } public double CalculateTotalPrice() { double totalprice = 0; foreach (Product p in _products) { double price = p.CalculatePrice(); totalprice += price; } double shippingCost = CalculateShipping(); totalprice += shippingCost; return totalprice; } public string GeneratePackingLabel() { string packingLabel = "Packing Label:\n"; foreach (Product p in _products) { packingLabel += p.GetName() + " - " + p.GetProductID() + "\n"; } return packingLabel; } public string GenerateShippingLabel() { string shippingLabel = "Shipping Label:\n"; shippingLabel += _customer.GetName() + "\n" + _customer.GenerateAddress(); return shippingLabel; } public string GenerateTotalCost() { string totalCost = "\nProducts:\n"; double totalPrice = CalculateTotalPrice(); foreach (Product p in _products) { totalCost += p.GetName() + " (" + p.GetProductID() + ") - " + "$" + p.GetPrice() + " x " + p.GetQuantity() + " = " + p.CalculatePrice() + "\n";
} totalCost += "Shipping Cost: $" + CalculateShipping() + "\n"; totalCost += "Total: $" + CalculateTotalPrice(); return totalCost; } public void DisplayResults() { string packingLabel = GeneratePackingLabel(); string shippingLabel = GenerateShippingLabel(); string totalCost = GenerateTotalCost(); Console.WriteLine(packingLabel); Console.WriteLine(shippingLabel); Console.WriteLine(totalCost); } }
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help