diff --git a/Order.Management/Circle.cs b/Order.Management/Circle.cs index 9824ecc..afef36f 100644 --- a/Order.Management/Circle.cs +++ b/Order.Management/Circle.cs @@ -7,15 +7,17 @@ namespace Order.Management class Circle : Shape { public int circlePrice = 3; - public Circle(int red, int blue, int yellow) + + public Circle(int numberOfRedCircles, int numberOfBlueCircles, int numberOfYellowCircles) { Name = "Circle"; - base.Price = circlePrice; + Price = circlePrice; AdditionalCharge = 1; - base.NumberOfRedShape = red; - base.NumberOfBlueShape = blue; - base.NumberOfYellowShape = yellow; + NumberOfRedShape = numberOfRedCircles; + NumberOfBlueShape = numberOfBlueCircles; + NumberOfYellowShape = numberOfYellowCircles; } + public override int Total() { return RedCirclesTotal() + BlueCirclesTotal() + YellowCirclesTotal(); @@ -23,15 +25,17 @@ public override int Total() public int RedCirclesTotal() { - return (base.NumberOfRedShape * Price); + return (NumberOfRedShape * Price); } + public int BlueCirclesTotal() { - return (base.NumberOfBlueShape * Price); + return (NumberOfBlueShape * Price); } + public int YellowCirclesTotal() { - return (base.NumberOfYellowShape * Price); + return (NumberOfYellowShape * Price); } } } diff --git a/Order.Management/CuttingListReport.cs b/Order.Management/CuttingListReport.cs index 125d45f..8a629c1 100644 --- a/Order.Management/CuttingListReport.cs +++ b/Order.Management/CuttingListReport.cs @@ -1,68 +1,37 @@ using System; using System.Collections.Generic; -using System.Text; namespace Order.Management { class CuttingListReport : Order { - public int tableWidth = 20; public CuttingListReport(string customerName, string customerAddress, string dueDate, List shapes) { - base.CustomerName = customerName; - base.Address = customerAddress; - base.DueDate = dueDate; - base.OrderedBlocks = shapes; + CustomerName = customerName; + Address = customerAddress; + DueDate = dueDate; + OrderedBlocks = shapes; + ReportTableWidth = 20; } public override void GenerateReport() { Console.WriteLine("\nYour cutting list has been generated: "); - Console.WriteLine(base.ToString()); - generateTable(); + Console.WriteLine(ReportSummaryHeader()); + GenerateReportDetail(" ", " Qty "); } - public void generateTable() + + public new void GenerateReportDetail(params string[] reportDetailColumns) { 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(reportDetailColumns); 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 orderedblock in OrderedBlocks) { - 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); + PrintRow(orderedblock.Name, orderedblock.TotalQuantityOfShape().ToString()); } + PrintLine(); } - } } diff --git a/Order.Management/InvoiceReport.cs b/Order.Management/InvoiceReport.cs index 78443c3..6a140b2 100644 --- a/Order.Management/InvoiceReport.cs +++ b/Order.Management/InvoiceReport.cs @@ -6,93 +6,65 @@ namespace Order.Management { class InvoiceReport : Order { - public int tableWidth = 73; public InvoiceReport(string customerName, string customerAddress, string dueDate, List shapes) { - base.CustomerName = customerName; - base.Address = customerAddress; - base.DueDate = dueDate; - base.OrderedBlocks = shapes; + CustomerName = customerName; + Address = customerAddress; + DueDate = dueDate; + OrderedBlocks = shapes; + ReportTableWidth = 73; } public override void GenerateReport() { Console.WriteLine("\nYour invoice report has been generated: "); - Console.WriteLine(base.ToString()); - GenerateTable(); - OrderSquareDetails(); - OrderTriangleDetails(); - OrderCircleDetails(); + Console.WriteLine(ReportSummaryHeader()); + GenerateReportDetail(" ", " Red ", " Blue ", " Yellow "); + + foreach (var orderedBlock in OrderedBlocks) + { + Console.WriteLine(string.Format("\n{0} {1} @ ${2} ppi = ${3}", + orderedBlock.Name, + orderedBlock.TotalQuantityOfShape().ToString(), + orderedBlock.Price.ToString(), + orderedBlock.Total().ToString())); + + Console.WriteLine(string.Format("Red Color Surcharge {0} @ ${1} ppi = ${2}", + orderedBlock.NumberOfRedShape, + orderedBlock.AdditionalCharge, + (orderedBlock.NumberOfRedShape * orderedBlock.AdditionalCharge) )); + + } + RedPaintSurcharge(); } public void RedPaintSurcharge() { - Console.WriteLine("Red Color Surcharge " + TotalAmountOfRedShapes() + " @ $" + base.OrderedBlocks[0].AdditionalCharge + " ppi = $" + TotalPriceRedPaintSurcharge()); + Console.WriteLine(string.Format("\nRed Color Surcharge Total {0} ppi = ${1}", + TotalAmountOfRedShapes().ToString(), + TotalPriceRedPaintSurcharge().ToString() )); } public int TotalAmountOfRedShapes() { - return base.OrderedBlocks[0].NumberOfRedShape + base.OrderedBlocks[1].NumberOfRedShape + - base.OrderedBlocks[2].NumberOfRedShape; - } - - 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() - { - 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) + int redShapesTotal = 0; + foreach (var orderedBlock in OrderedBlocks) { - row += AlignCentre(column, width) + "|"; + redShapesTotal += orderedBlock.NumberOfRedShape; } - - Console.WriteLine(row); + return redShapesTotal; } - public string AlignCentre(string text, int width) + public int TotalPriceRedPaintSurcharge() { - text = text.Length > width ? text.Substring(0, width - 3) + "..." : text; - - if (string.IsNullOrEmpty(text)) + int paintSurchargeTotal = 0; + foreach (var orderedBlock in OrderedBlocks) { - return new string(' ', width); - } - else - { - return text.PadRight(width - (width - text.Length) / 2).PadLeft(width); + paintSurchargeTotal += (orderedBlock.NumberOfRedShape * orderedBlock.AdditionalCharge); } + return paintSurchargeTotal; } + } } diff --git a/Order.Management/Order.cs b/Order.Management/Order.cs index 235c789..513f165 100644 --- a/Order.Management/Order.cs +++ b/Order.Management/Order.cs @@ -12,11 +12,58 @@ abstract class Order public int OrderNumber { get; set; } public List OrderedBlocks { get; set; } + public int ReportTableWidth { get; set; } + public abstract void GenerateReport(); - public string ToString() + public void GenerateReportDetail(params string[] reportDetailColumns) { - return "\nName: " + CustomerName + " Address: " + Address + " Due Date: " + DueDate + " Order #: " + OrderNumber; + PrintLine(); + PrintRow(reportDetailColumns); + PrintLine(); + foreach (var orderedblock in OrderedBlocks) + { + PrintRow(orderedblock.Name, orderedblock.NumberOfRedShape.ToString(), orderedblock.NumberOfBlueShape.ToString(), orderedblock.NumberOfYellowShape.ToString()); + } + PrintLine(); } + + public string ReportSummaryHeader() + { + return string.Format("\nName: {0} Address: {1} Due Date: {2} Order #: {3} ", CustomerName, Address, DueDate, OrderNumber); + } + + public void PrintLine() + { + Console.WriteLine(new string('-', ReportTableWidth)); + } + + public void PrintRow(params string[] columns) + { + int width = (ReportTableWidth - 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); + } + } + } } diff --git a/Order.Management/PaintingReport.cs b/Order.Management/PaintingReport.cs index 9b61c83..947f13b 100644 --- a/Order.Management/PaintingReport.cs +++ b/Order.Management/PaintingReport.cs @@ -6,62 +6,20 @@ 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; + CustomerName = customerName; + Address = customerAddress; + DueDate = dueDate; + OrderedBlocks = shapes; + ReportTableWidth = 73; } + 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); - } + Console.WriteLine(ReportSummaryHeader()); + GenerateReportDetail(" ", " Red ", " Blue ", " Yellow "); } } } diff --git a/Order.Management/Program.cs b/Order.Management/Program.cs index 1422f85..7ecce7a 100644 --- a/Order.Management/Program.cs +++ b/Order.Management/Program.cs @@ -18,18 +18,21 @@ static void Main(string[] args) PaintingReport(customerName, address, dueDate, orderedShapes); } - + // Order Circle Input public static Circle OrderCirclesInput() { Console.Write("\nPlease input the number of Red Circle: "); - int redCircle = Convert.ToInt32(userInput()); + int redCircle = UserNumberInput(); + Console.Write("Please input the number of Blue Circle: "); - int blueCircle = Convert.ToInt32(userInput()); + int blueCircle = UserNumberInput(); + Console.Write("Please input the number of Yellow Circle: "); - int yellowCircle = Convert.ToInt32(userInput()); + int yellowCircle = UserNumberInput(); Circle circle = new Circle(redCircle, blueCircle, yellowCircle); + return circle; } @@ -37,13 +40,16 @@ public static Circle OrderCirclesInput() public static Square OrderSquaresInput() { Console.Write("\nPlease input the number of Red Squares: "); - int redSquare = Convert.ToInt32(userInput()); + int redSquare = UserNumberInput(); + Console.Write("Please input the number of Blue Squares: "); - int blueSquare = Convert.ToInt32(userInput()); + int blueSquare = UserNumberInput(); + Console.Write("Please input the number of Yellow Squares: "); - int yellowSquare = Convert.ToInt32(userInput()); + int yellowSquare = UserNumberInput(); Square square = new Square(redSquare, blueSquare, yellowSquare); + return square; } @@ -51,18 +57,18 @@ public static Square OrderSquaresInput() public static Triangle OrderTrianglesInput() { Console.Write("\nPlease input the number of Red Triangles: "); - int redTriangle = Convert.ToInt32(userInput()); + int redTriangle = UserNumberInput(); Console.Write("Please input the number of Blue Triangles: "); - int blueTriangle = Convert.ToInt32(userInput()); + int blueTriangle = UserNumberInput(); Console.Write("Please input the number of Yellow Triangles: "); - int yellowTriangle = Convert.ToInt32(userInput()); + int yellowTriangle = UserNumberInput(); Triangle triangle = new Triangle(redTriangle, blueTriangle, yellowTriangle); return triangle; } - // User Console Input - public static string userInput() + // User Console String Input + public static string UserInput() { string input = Console.ReadLine(); while (string.IsNullOrEmpty(input)) @@ -74,6 +80,32 @@ public static string userInput() return input; } + // User Console Number Input + public static int UserNumberInput() + { + string input = Console.ReadLine(); + while (string.IsNullOrEmpty(input) || !int.TryParse(input, out _)) + { + Console.WriteLine("Please enter a number"); + input = Console.ReadLine(); + + } + return Convert.ToInt32(input); + } + + // User Console Date Input + public static string UserDateInput() + { + string input = Console.ReadLine(); + while (string.IsNullOrEmpty(input) || !DateTime.TryParse(input, out _)) + { + Console.WriteLine("Please enter a valid date"); + input = Console.ReadLine(); + + } + return input; + } + // Generate Painting Report private static void PaintingReport(string customerName, string address, string dueDate, List orderedShapes) { @@ -99,11 +131,14 @@ private static void InvoiceReport(string customerName, string address, string du private static (string customerName, string address, string dueDate) CustomerInfoInput() { Console.Write("Please input your Name: "); - string customerName = userInput(); + string customerName = UserInput(); + Console.Write("Please input your Address: "); - string address = userInput(); + string address = UserInput(); + Console.Write("Please input your Due Date: "); - string dueDate = userInput(); + string dueDate = UserDateInput(); + return (customerName, address, dueDate); } @@ -114,10 +149,13 @@ private static List CustomerOrderInput() Triangle triangle = OrderTrianglesInput(); Circle circle = OrderCirclesInput(); - var orderedShapes = new List(); - orderedShapes.Add(square); - orderedShapes.Add(triangle); - orderedShapes.Add(circle); + var orderedShapes = new List + { + square, + triangle, + circle + }; + return orderedShapes; } } diff --git a/Order.Management/Shape.cs b/Order.Management/Shape.cs index 7f5c61c..bcdd841 100644 --- a/Order.Management/Shape.cs +++ b/Order.Management/Shape.cs @@ -12,6 +12,7 @@ abstract class Shape public int NumberOfRedShape { get; set; } public int NumberOfBlueShape { get; set; } public int NumberOfYellowShape { get; set; } + public int TotalQuantityOfShape() { return NumberOfRedShape + NumberOfBlueShape + NumberOfYellowShape; @@ -21,6 +22,7 @@ public int AdditionalChargeTotal() { return NumberOfRedShape * AdditionalCharge; } + public abstract int Total(); } diff --git a/Order.Management/Square.cs b/Order.Management/Square.cs index 017601e..eeb86c1 100644 --- a/Order.Management/Square.cs +++ b/Order.Management/Square.cs @@ -12,11 +12,11 @@ class Square : Shape public Square(int numberOfRedSquares, int numberOfBlueSquares, int numberOfYellowSquares) { Name = "Square"; - base.Price = SquarePrice; + Price = SquarePrice; AdditionalCharge = 1; - base.NumberOfRedShape = numberOfRedSquares; - base.NumberOfBlueShape = numberOfBlueSquares; - base.NumberOfYellowShape = numberOfYellowSquares; + NumberOfRedShape = numberOfRedSquares; + NumberOfBlueShape = numberOfBlueSquares; + NumberOfYellowShape = numberOfYellowSquares; } public override int Total() @@ -28,10 +28,12 @@ public int RedSquaresTotal() { return (base.NumberOfRedShape * Price); } + public int BlueSquaresTotal() { return (base.NumberOfBlueShape * Price); } + public int YellowSquaresTotal() { return (base.NumberOfYellowShape * Price); diff --git a/Order.Management/Triangle.cs b/Order.Management/Triangle.cs index dbf48ff..e387835 100644 --- a/Order.Management/Triangle.cs +++ b/Order.Management/Triangle.cs @@ -7,14 +7,15 @@ namespace Order.Management class Triangle : Shape { public int TrianglePrice = 2; + public Triangle(int numberOfRedTriangles, int numberOfBlueTriangles, int numberOfYellowTriangles) { Name = "Triangle"; - base.Price = TrianglePrice; + Price = TrianglePrice; AdditionalCharge = 1; - base.NumberOfRedShape = numberOfRedTriangles; - base.NumberOfBlueShape = numberOfBlueTriangles; - base.NumberOfYellowShape = numberOfYellowTriangles; + NumberOfRedShape = numberOfRedTriangles; + NumberOfBlueShape = numberOfBlueTriangles; + NumberOfYellowShape = numberOfYellowTriangles; } public override int Total() @@ -26,14 +27,16 @@ public int RedTrianglesTotal() { return (base.NumberOfRedShape * Price); } + public int BlueTrianglesTotal() { return (base.NumberOfBlueShape * Price); } + public int YellowTrianglesTotal() { return (base.NumberOfYellowShape * Price); } - -} + + } }