diff --git a/Order.Management/Circle.cs b/Order.Management/Circle.cs index 9824ecc..5b0b13d 100644 --- a/Order.Management/Circle.cs +++ b/Order.Management/Circle.cs @@ -6,32 +6,12 @@ namespace Order.Management { class Circle : Shape { - public int circlePrice = 3; - public Circle(int red, int blue, int yellow) - { - Name = "Circle"; - base.Price = circlePrice; - AdditionalCharge = 1; - base.NumberOfRedShape = red; - base.NumberOfBlueShape = blue; - base.NumberOfYellowShape = yellow; - } - public override int Total() - { - return RedCirclesTotal() + BlueCirclesTotal() + YellowCirclesTotal(); - } + public override string Name => "Circle"; - public int RedCirclesTotal() - { - return (base.NumberOfRedShape * Price); - } - public int BlueCirclesTotal() - { - return (base.NumberOfBlueShape * Price); - } - public int YellowCirclesTotal() + public override int Price => 3; + + public Circle(int red, int blue, int yellow) :base(red, blue, yellow) { - return (base.NumberOfYellowShape * Price); } } } diff --git a/Order.Management/CustomerInfo.cs b/Order.Management/CustomerInfo.cs new file mode 100644 index 0000000..88db082 --- /dev/null +++ b/Order.Management/CustomerInfo.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Order.Management +{ + class CustomerInfo + { + public string CustomerName { get; set; } + public string Address { get; set; } + public string DueDate { get; set; } + } +} diff --git a/Order.Management/CuttingListReport.cs b/Order.Management/CuttingListReport.cs index 125d45f..21741fc 100644 --- a/Order.Management/CuttingListReport.cs +++ b/Order.Management/CuttingListReport.cs @@ -6,63 +6,32 @@ namespace Order.Management { class CuttingListReport : Order { - public int tableWidth = 20; - public CuttingListReport(string customerName, string customerAddress, string dueDate, List shapes) + public CuttingListReport(CustomerInfo customerInfo, List shapes) : base(customerInfo, shapes) { - base.CustomerName = customerName; - base.Address = customerAddress; - base.DueDate = dueDate; - base.OrderedBlocks = shapes; } - public override void GenerateReport() - { - Console.WriteLine("\nYour cutting list has been generated: "); - Console.WriteLine(base.ToString()); - generateTable(); - } - public void generateTable() + public override int TableWidth => 20; + + public override string ReportType => "Cutting List"; + + public override void GenerateTable() { PrintLine(); - PrintRow(" ", " Qty "); - PrintLine(); - PrintRow("Square",base.OrderedBlocks[0].TotalQuantityOfShape().ToString()); - PrintRow("Triangle", base.OrderedBlocks[1].TotalQuantityOfShape().ToString()); - PrintRow("Circle", base.OrderedBlocks[2].TotalQuantityOfShape().ToString()); + PrintRow(new List { + " ", + " Qty " + }); PrintLine(); - } - public void PrintLine() - { - Console.WriteLine(new string('-', tableWidth)); - } - - public void PrintRow(params string[] columns) - { - int width = (tableWidth - columns.Length) / columns.Length; - string row = "|"; - - foreach (string column in columns) + foreach (var order in OrderedBlocks) { - row += AlignCentre(column, width) + "|"; + PrintRow(new List + { + order.Name, + order.TotalQuantity.ToString(), + }); } - Console.WriteLine(row); - } - - public string AlignCentre(string text, int width) - { - text = text.Length > width ? text.Substring(0, width - 3) + "..." : text; - - if (string.IsNullOrEmpty(text)) - { - return new string(' ', width); - } - else - { - return text.PadRight(width - (width - text.Length) / 2).PadLeft(width); - } + PrintLine(); } - - } } diff --git a/Order.Management/InvoiceReport.cs b/Order.Management/InvoiceReport.cs index 78443c3..1e163c4 100644 --- a/Order.Management/InvoiceReport.cs +++ b/Order.Management/InvoiceReport.cs @@ -6,93 +6,48 @@ namespace Order.Management { class InvoiceReport : Order { - public int tableWidth = 73; - public InvoiceReport(string customerName, string customerAddress, string dueDate, List shapes) + public override string ReportType => "Invoice" ; + + private string PriceAtText => "@ $"; + private string PriceTotalText => "ppi = $"; + private int TotalReds => TotalAmountOfRedShapes(); + + public InvoiceReport(CustomerInfo customerInfo, List shapes) : base(customerInfo, shapes) { - base.CustomerName = customerName; - base.Address = customerAddress; - base.DueDate = dueDate; - base.OrderedBlocks = shapes; } public override void GenerateReport() { - Console.WriteLine("\nYour invoice report has been generated: "); - Console.WriteLine(base.ToString()); + ReportHeader(ReportType); GenerateTable(); - OrderSquareDetails(); - OrderTriangleDetails(); - OrderCircleDetails(); - RedPaintSurcharge(); - } + Console.WriteLine(Environment.NewLine); + foreach (var order in OrderedBlocks) + { + Console.WriteLine("{0} {1} {2}{3} {4}{5}",order.Name, order.TotalQuantity, PriceAtText, order.Price, PriceTotalText, order.TotalPrice); + } - public void RedPaintSurcharge() - { - Console.WriteLine("Red Color Surcharge " + TotalAmountOfRedShapes() + " @ $" + base.OrderedBlocks[0].AdditionalCharge + " ppi = $" + TotalPriceRedPaintSurcharge()); + RedPaintSurcharge(); } - public int TotalAmountOfRedShapes() + private void RedPaintSurcharge() { - return base.OrderedBlocks[0].NumberOfRedShape + base.OrderedBlocks[1].NumberOfRedShape + - base.OrderedBlocks[2].NumberOfRedShape; + Console.WriteLine("{0} {1} {2}{3} {4}{5}","Red Paint Surcharge", TotalAmountOfRedShapes(), PriceAtText, TotalReds, PriceTotalText , TotalPriceRedPaintSurcharge()); } - public int TotalPriceRedPaintSurcharge() - { - return TotalAmountOfRedShapes() * base.OrderedBlocks[0].AdditionalCharge; - } - public void GenerateTable() - { - PrintLine(); - PrintRow(" ", " Red ", " Blue ", " Yellow "); - PrintLine(); - PrintRow("Square", base.OrderedBlocks[0].NumberOfRedShape.ToString(), base.OrderedBlocks[0].NumberOfBlueShape.ToString(), base.OrderedBlocks[0].NumberOfYellowShape.ToString()); - PrintRow("Triangle", base.OrderedBlocks[1].NumberOfRedShape.ToString(), base.OrderedBlocks[1].NumberOfBlueShape.ToString(), base.OrderedBlocks[1].NumberOfYellowShape.ToString()); - PrintRow("Circle", base.OrderedBlocks[2].NumberOfRedShape.ToString(), base.OrderedBlocks[2].NumberOfBlueShape.ToString(), base.OrderedBlocks[2].NumberOfYellowShape.ToString()); - PrintLine(); - } - public void OrderSquareDetails() - { - Console.WriteLine("\nSquares " + base.OrderedBlocks[0].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[0].Price + " ppi = $" + base.OrderedBlocks[0].Total()); - } - public void OrderTriangleDetails() + private int TotalAmountOfRedShapes() { - Console.WriteLine("Triangles " + base.OrderedBlocks[1].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[1].Price + " ppi = $" + base.OrderedBlocks[1].Total()); - } - public void OrderCircleDetails() - { - Console.WriteLine("Circles " + base.OrderedBlocks[2].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[2].Price + " ppi = $" + base.OrderedBlocks[2].Total()); - } - public void PrintLine() - { - Console.WriteLine(new string('-', tableWidth)); - } - - public void PrintRow(params string[] columns) - { - int width = (tableWidth - columns.Length) / columns.Length; - string row = "|"; - - foreach (string column in columns) + var totalReds = 0; + foreach(var order in OrderedBlocks) { - row += AlignCentre(column, width) + "|"; + totalReds += order.NumberOfRedShape; } - Console.WriteLine(row); + return totalReds; } - public string AlignCentre(string text, int width) + private int TotalPriceRedPaintSurcharge() { - text = text.Length > width ? text.Substring(0, width - 3) + "..." : text; - - if (string.IsNullOrEmpty(text)) - { - return new string(' ', width); - } - else - { - return text.PadRight(width - (width - text.Length) / 2).PadLeft(width); - } + return TotalReds * base.OrderedBlocks[0].AdditionalChargeRed; } } } diff --git a/Order.Management/Order.cs b/Order.Management/Order.cs index 235c789..3e840ff 100644 --- a/Order.Management/Order.cs +++ b/Order.Management/Order.cs @@ -6,17 +6,100 @@ namespace Order.Management { abstract class Order { - public string CustomerName { get; set; } - public string Address { get; set; } - public string DueDate { get; set; } - public int OrderNumber { get; set; } - public List OrderedBlocks { get; set; } + CustomerInfo CustomerInfo { get; set; } + public int OrderNumber { get; private set; } + public List OrderedBlocks { get; private set; } - public abstract void GenerateReport(); + public Order(CustomerInfo customerInfo, List shapes) + { + CustomerInfo = customerInfo; + OrderedBlocks = shapes; + } + + #region Abstract Methods + public virtual void GenerateTable() + { + PrintLine(); + PrintRow(new List + { + " ", + " Red ", + " Blue ", + " Yellow " + }); + PrintLine(); + foreach(var order in OrderedBlocks) + { + PrintRow(new List + { + order.Name, + order.NumberOfRedShape.ToString(), + order.NumberOfBlueShape.ToString(), + order.NumberOfYellowShape.ToString() + }); + } + PrintLine(); + } + + #endregion + + #region Abstract Properties + + public virtual int TableWidth => 73; + public abstract string ReportType { get; } + #endregion + + #region Protected/Private Methods + + public virtual void GenerateReport() + { + ReportHeader(ReportType); + GenerateTable(); + } + + protected void PrintRow(List columns) + { + int width = (TableWidth - columns.Count) / columns.Count; + string row = "|"; - public string ToString() + foreach (string column in columns) + { + row += AlignCentre(column, width) + "|"; + } + + Console.WriteLine(row); + } + + private string CustomerDetails() + { + return "\nName: " + CustomerInfo.CustomerName + " Address: " + CustomerInfo.Address + " Due Date: " + CustomerInfo.DueDate + " Order #: " + OrderNumber; + } + + protected void PrintLine() + { + Console.WriteLine(new string('-', TableWidth)); + } + + protected void ReportHeader(string reportType) { - return "\nName: " + CustomerName + " Address: " + Address + " Due Date: " + DueDate + " Order #: " + OrderNumber; + Console.WriteLine("\nYour {0} report has been generated: ", ReportType); + Console.WriteLine(CustomerDetails()); } + + private string AlignCentre(string text, int width) + { + text = text.Length > width ? text.Substring(0, width - 3) + "..." : text; + + if (string.IsNullOrEmpty(text)) + { + return new string(' ', width); + } + else + { + return text.PadRight(width - (width - text.Length) / 2).PadLeft(width); + } + } + + #endregion } } diff --git a/Order.Management/PaintingReport.cs b/Order.Management/PaintingReport.cs index 9b61c83..29b5d25 100644 --- a/Order.Management/PaintingReport.cs +++ b/Order.Management/PaintingReport.cs @@ -6,62 +6,10 @@ namespace Order.Management { class PaintingReport : Order { - public int tableWidth = 73; - public PaintingReport(string customerName, string customerAddress, string dueDate, List shapes) - { - base.CustomerName = customerName; - base.Address = customerAddress; - base.DueDate = dueDate; - base.OrderedBlocks = shapes; + public PaintingReport(CustomerInfo customerInfo, List shapes) : base(customerInfo, shapes) + { } - public override void GenerateReport() - { - Console.WriteLine("\nYour painting report has been generated: "); - Console.WriteLine(base.ToString()); - generateTable(); - } - - public void generateTable() - { - PrintLine(); - PrintRow(" ", " Red ", " Blue ", " Yellow "); - PrintLine(); - PrintRow("Square", base.OrderedBlocks[0].NumberOfRedShape.ToString(), base.OrderedBlocks[0].NumberOfBlueShape.ToString(), base.OrderedBlocks[0].NumberOfYellowShape.ToString()); - PrintRow("Triangle", base.OrderedBlocks[1].NumberOfRedShape.ToString(), base.OrderedBlocks[1].NumberOfBlueShape.ToString(), base.OrderedBlocks[1].NumberOfYellowShape.ToString()); - PrintRow("Circle", base.OrderedBlocks[2].NumberOfRedShape.ToString(), base.OrderedBlocks[2].NumberOfBlueShape.ToString(), base.OrderedBlocks[2].NumberOfYellowShape.ToString()); - PrintLine(); - } - - public void PrintLine() - { - Console.WriteLine(new string('-', tableWidth)); - } - - public void PrintRow(params string[] columns) - { - int width = (tableWidth - columns.Length) / columns.Length; - string row = "|"; - foreach (string column in columns) - { - row += AlignCentre(column, width) + "|"; - } - - Console.WriteLine(row); - } - - public string AlignCentre(string text, int width) - { - text = text.Length > width ? text.Substring(0, width - 3) + "..." : text; - - if (string.IsNullOrEmpty(text)) - { - return new string(' ', width); - } - else - { - return text.PadRight(width - (width - text.Length) / 2).PadLeft(width); - } - } + public override string ReportType => "Painting"; } } diff --git a/Order.Management/Program.cs b/Order.Management/Program.cs index 1422f85..171609f 100644 --- a/Order.Management/Program.cs +++ b/Order.Management/Program.cs @@ -8,26 +8,26 @@ class Program // Main entry static void Main(string[] args) { - var (customerName, address, dueDate) = CustomerInfoInput(); + var customerInfo = CustomerInfoInput(); var orderedShapes = CustomerOrderInput(); - InvoiceReport(customerName, address, dueDate, orderedShapes); + InvoiceReport(customerInfo, orderedShapes); - CuttingListReport(customerName, address, dueDate, orderedShapes); + CuttingListReport(customerInfo, orderedShapes); - PaintingReport(customerName, address, dueDate, orderedShapes); + PaintingReport(customerInfo, orderedShapes); } // Order Circle Input public static Circle OrderCirclesInput() { Console.Write("\nPlease input the number of Red Circle: "); - int redCircle = Convert.ToInt32(userInput()); + int redCircle = Convert.ToInt32(UserInput()); Console.Write("Please input the number of Blue Circle: "); - int blueCircle = Convert.ToInt32(userInput()); + int blueCircle = Convert.ToInt32(UserInput()); Console.Write("Please input the number of Yellow Circle: "); - int yellowCircle = Convert.ToInt32(userInput()); + int yellowCircle = Convert.ToInt32(UserInput()); Circle circle = new Circle(redCircle, blueCircle, yellowCircle); return circle; @@ -37,11 +37,11 @@ public static Circle OrderCirclesInput() public static Square OrderSquaresInput() { Console.Write("\nPlease input the number of Red Squares: "); - int redSquare = Convert.ToInt32(userInput()); + int redSquare = Convert.ToInt32(UserInput()); Console.Write("Please input the number of Blue Squares: "); - int blueSquare = Convert.ToInt32(userInput()); + int blueSquare = Convert.ToInt32(UserInput()); Console.Write("Please input the number of Yellow Squares: "); - int yellowSquare = Convert.ToInt32(userInput()); + int yellowSquare = Convert.ToInt32(UserInput()); Square square = new Square(redSquare, blueSquare, yellowSquare); return square; @@ -51,60 +51,59 @@ public static Square OrderSquaresInput() public static Triangle OrderTrianglesInput() { Console.Write("\nPlease input the number of Red Triangles: "); - int redTriangle = Convert.ToInt32(userInput()); + int redTriangle = Convert.ToInt32(UserInput()); Console.Write("Please input the number of Blue Triangles: "); - int blueTriangle = Convert.ToInt32(userInput()); + int blueTriangle = Convert.ToInt32(UserInput()); Console.Write("Please input the number of Yellow Triangles: "); - int yellowTriangle = Convert.ToInt32(userInput()); + int yellowTriangle = Convert.ToInt32(UserInput()); Triangle triangle = new Triangle(redTriangle, blueTriangle, yellowTriangle); return triangle; } // User Console Input - public static string userInput() + public static string UserInput() { string input = Console.ReadLine(); - while (string.IsNullOrEmpty(input)) + if (string.IsNullOrEmpty(input)) { - Console.WriteLine("please enter valid details"); - input = Console.ReadLine(); - + return UserInput(); } return input; } // Generate Painting Report - private static void PaintingReport(string customerName, string address, string dueDate, List orderedShapes) + private static void PaintingReport(CustomerInfo customerInfo, List orderedShapes) { - PaintingReport paintingReport = new PaintingReport(customerName, address, dueDate, orderedShapes); + PaintingReport paintingReport = new PaintingReport(customerInfo, orderedShapes); paintingReport.GenerateReport(); } // Generate Painting Report - private static void CuttingListReport(string customerName, string address, string dueDate, List orderedShapes) + private static void CuttingListReport(CustomerInfo customerInfo, List orderedShapes) { - CuttingListReport cuttingListReport = new CuttingListReport(customerName, address, dueDate, orderedShapes); + CuttingListReport cuttingListReport = new CuttingListReport(customerInfo, orderedShapes); cuttingListReport.GenerateReport(); } // Generate Invoice Report - private static void InvoiceReport(string customerName, string address, string dueDate, List orderedShapes) + private static void InvoiceReport(CustomerInfo customerInfo, List orderedShapes) { - InvoiceReport invoiceReport = new InvoiceReport(customerName, address, dueDate, orderedShapes); + InvoiceReport invoiceReport = new InvoiceReport(customerInfo, orderedShapes); invoiceReport.GenerateReport(); } // Get customer Info - private static (string customerName, string address, string dueDate) CustomerInfoInput() + private static CustomerInfo CustomerInfoInput() { + var customerOrderDetails = new CustomerInfo(); Console.Write("Please input your Name: "); - string customerName = userInput(); + customerOrderDetails.CustomerName = UserInput(); Console.Write("Please input your Address: "); - string address = userInput(); + customerOrderDetails.Address = UserInput(); Console.Write("Please input your Due Date: "); - string dueDate = userInput(); - return (customerName, address, dueDate); + customerOrderDetails.DueDate = UserInput(); + return customerOrderDetails; } // Get order input diff --git a/Order.Management/Shape.cs b/Order.Management/Shape.cs index 7f5c61c..dff1b95 100644 --- a/Order.Management/Shape.cs +++ b/Order.Management/Shape.cs @@ -6,22 +6,55 @@ namespace Order.Management { abstract class Shape { - public string Name { get; set; } - public int Price { get; set; } - public int AdditionalCharge { get; set; } - public int NumberOfRedShape { get; set; } - public int NumberOfBlueShape { get; set; } - public int NumberOfYellowShape { get; set; } - public int TotalQuantityOfShape() + #region Public Properties + + public int TotalPrice { get; private set; } + public int TotalQuantity { get; private set; } + public int NumberOfRedShape { get; private set; } + public int NumberOfBlueShape { get; private set; } + public int NumberOfYellowShape { get; private set; } + + #endregion + + protected Shape(int numberOfRedShape, int numberOfBlueShape, int numberOfYellowShape) + { + NumberOfRedShape = numberOfRedShape; + NumberOfBlueShape = numberOfBlueShape; + NumberOfYellowShape = numberOfYellowShape; + TotalPrice = Total(); + TotalQuantity = TotalQuantityOfShape(); + } + + #region Abstract properties + + public abstract string Name { get; } + public abstract int Price { get; } + public virtual int AdditionalChargeRed { get => 1; } + + #endregion + + #region Protected Methods + + protected int TotalQuantityOfShape() { return NumberOfRedShape + NumberOfBlueShape + NumberOfYellowShape; } - public int AdditionalChargeTotal() + #endregion + + #region Abstract protected methods + + protected virtual int AdditionalChargeTotal() { - return NumberOfRedShape * AdditionalCharge; + return NumberOfRedShape * AdditionalChargeRed; } - public abstract int Total(); + protected virtual int Total() + { + return (NumberOfRedShape * Price) + + (NumberOfBlueShape * Price) + + (NumberOfYellowShape * Price); + } + #endregion } -} +} \ No newline at end of file diff --git a/Order.Management/Square.cs b/Order.Management/Square.cs index 017601e..9c48742 100644 --- a/Order.Management/Square.cs +++ b/Order.Management/Square.cs @@ -6,35 +6,12 @@ namespace Order.Management { class Square : Shape { + public override string Name => "Square"; + public override int Price => 1; - public int SquarePrice = 1; - - public Square(int numberOfRedSquares, int numberOfBlueSquares, int numberOfYellowSquares) - { - Name = "Square"; - base.Price = SquarePrice; - AdditionalCharge = 1; - base.NumberOfRedShape = numberOfRedSquares; - base.NumberOfBlueShape = numberOfBlueSquares; - base.NumberOfYellowShape = numberOfYellowSquares; - } - - public override int Total() - { - return RedSquaresTotal() + BlueSquaresTotal() + YellowSquaresTotal(); - } - - public int RedSquaresTotal() - { - return (base.NumberOfRedShape * Price); - } - public int BlueSquaresTotal() - { - return (base.NumberOfBlueShape * Price); - } - public int YellowSquaresTotal() + public Square(int numberOfRedSquares, int numberOfBlueSquares, int numberOfYellowSquares) : + base(numberOfRedSquares, numberOfBlueSquares, numberOfYellowSquares) { - return (base.NumberOfYellowShape * Price); } } } diff --git a/Order.Management/Triangle.cs b/Order.Management/Triangle.cs index dbf48ff..866c077 100644 --- a/Order.Management/Triangle.cs +++ b/Order.Management/Triangle.cs @@ -6,34 +6,13 @@ namespace Order.Management { class Triangle : Shape { - public int TrianglePrice = 2; - public Triangle(int numberOfRedTriangles, int numberOfBlueTriangles, int numberOfYellowTriangles) - { - Name = "Triangle"; - base.Price = TrianglePrice; - AdditionalCharge = 1; - base.NumberOfRedShape = numberOfRedTriangles; - base.NumberOfBlueShape = numberOfBlueTriangles; - base.NumberOfYellowShape = numberOfYellowTriangles; - } + public override string Name => "Triangle"; - public override int Total() - { - return RedTrianglesTotal() + BlueTrianglesTotal() + YellowTrianglesTotal(); - } + public override int Price => 2; - public int RedTrianglesTotal() - { - return (base.NumberOfRedShape * Price); - } - public int BlueTrianglesTotal() - { - return (base.NumberOfBlueShape * Price); - } - public int YellowTrianglesTotal() + public Triangle(int numberOfRedTriangles, int numberOfBlueTriangles, int numberOfYellowTriangles) + : base(numberOfRedTriangles, numberOfBlueTriangles, numberOfYellowTriangles) { - return (base.NumberOfYellowShape * Price); } - -} + } }