From 0f03bdcbf94503feb061b2cb4415fd52d72ca4f9 Mon Sep 17 00:00:00 2001 From: Hannah Hu Date: Tue, 12 Apr 2022 10:25:41 +0800 Subject: [PATCH 1/2] commits --- Order.Management/InvoiceReport.cs | 2 ++ Order.Management/Order.cs | 1 + Order.Management/Program.cs | 7 ++++++- Order.Management/Shape.cs | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Order.Management/InvoiceReport.cs b/Order.Management/InvoiceReport.cs index 78443c3..a8e3e31 100644 --- a/Order.Management/InvoiceReport.cs +++ b/Order.Management/InvoiceReport.cs @@ -63,6 +63,8 @@ public void OrderCircleDetails() { Console.WriteLine("Circles " + base.OrderedBlocks[2].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[2].Price + " ppi = $" + base.OrderedBlocks[2].Total()); } + + // PrintLine、PrintRow、AlignCentre can be moved into another class(e.g.help.cs) public void PrintLine() { Console.WriteLine(new string('-', tableWidth)); diff --git a/Order.Management/Order.cs b/Order.Management/Order.cs index 235c789..87f2442 100644 --- a/Order.Management/Order.cs +++ b/Order.Management/Order.cs @@ -14,6 +14,7 @@ abstract class Order public abstract void GenerateReport(); + // Override ToString(), because it is inherited from Object.ToString(). public string ToString() { return "\nName: " + CustomerName + " Address: " + Address + " Due Date: " + DueDate + " Order #: " + OrderNumber; diff --git a/Order.Management/Program.cs b/Order.Management/Program.cs index 1422f85..20678ef 100644 --- a/Order.Management/Program.cs +++ b/Order.Management/Program.cs @@ -18,8 +18,10 @@ static void Main(string[] args) PaintingReport(customerName, address, dueDate, orderedShapes); } - + // Order Circle Input + // OrderCirclesInput()、OrderSquaresInput()、OrderTrianglesInput() + // The above three methods can be merged as one method by passing parameters(e.g.OrderInput(shape)). public static Circle OrderCirclesInput() { Console.Write("\nPlease input the number of Red Circle: "); @@ -48,9 +50,11 @@ public static Square OrderSquaresInput() } // Order Triangles Input + // Use private to replace public,unless special reasons. public static Triangle OrderTrianglesInput() { Console.Write("\nPlease input the number of Red Triangles: "); + // User input validity check(e.g.Regex reg = new Regex("^[0-9]+$")) int redTriangle = Convert.ToInt32(userInput()); Console.Write("Please input the number of Blue Triangles: "); int blueTriangle = Convert.ToInt32(userInput()); @@ -103,6 +107,7 @@ private static (string customerName, string address, string dueDate) CustomerInf Console.Write("Please input your Address: "); string address = userInput(); Console.Write("Please input your Due Date: "); + //Convert user input to DateTime type. string dueDate = userInput(); return (customerName, address, dueDate); } diff --git a/Order.Management/Shape.cs b/Order.Management/Shape.cs index 7f5c61c..a397d25 100644 --- a/Order.Management/Shape.cs +++ b/Order.Management/Shape.cs @@ -17,6 +17,7 @@ public int TotalQuantityOfShape() return NumberOfRedShape + NumberOfBlueShape + NumberOfYellowShape; } + // This method isn't used, can be removed. public int AdditionalChargeTotal() { return NumberOfRedShape * AdditionalCharge; From 20655754cda96b1e799d01c95a76ceaeccca758f Mon Sep 17 00:00:00 2001 From: hufengjing Date: Thu, 14 Apr 2022 11:36:47 +0800 Subject: [PATCH 2/2] Refacter code --- Order.Management/Circle.cs | 43 +++++--- Order.Management/CuttingListReport.cs | 62 +++-------- Order.Management/InvoiceReport.cs | 80 +++++--------- Order.Management/Order.cs | 17 ++- Order.Management/PaintingReport.cs | 61 +++-------- Order.Management/Program.cs | 143 ++++++++++++++++---------- Order.Management/Report.cs | 43 ++++++++ Order.Management/Shape.cs | 26 ++--- Order.Management/Square.cs | 22 ++-- Order.Management/Triangle.cs | 25 ++--- 10 files changed, 253 insertions(+), 269 deletions(-) create mode 100644 Order.Management/Report.cs diff --git a/Order.Management/Circle.cs b/Order.Management/Circle.cs index 9824ecc..19a0b26 100644 --- a/Order.Management/Circle.cs +++ b/Order.Management/Circle.cs @@ -7,31 +7,42 @@ namespace Order.Management class Circle : Shape { public int circlePrice = 3; - public Circle(int red, int blue, int yellow) + //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 Circle() { Name = "Circle"; base.Price = circlePrice; AdditionalCharge = 1; - base.NumberOfRedShape = red; - base.NumberOfBlueShape = blue; - base.NumberOfYellowShape = yellow; } - public override int Total() + public override int Total(Order order) { - return RedCirclesTotal() + BlueCirclesTotal() + YellowCirclesTotal(); + return ColorCirclesTotal(order, "Red") + ColorCirclesTotal(order, "Blue") + ColorCirclesTotal(order, "Yellow"); } - public int RedCirclesTotal() + public int ColorCirclesTotal(Order order, string color) { - return (base.NumberOfRedShape * Price); - } - public int BlueCirclesTotal() - { - return (base.NumberOfBlueShape * Price); - } - public int YellowCirclesTotal() - { - return (base.NumberOfYellowShape * Price); + int TotalPrice = order.NumberOfColorShape[color] * Price; + return TotalPrice; } + //public int RedCirclesTotal() + //{ + // return (Order.NumberOfRedShape * Price); + //} + //public int BlueCirclesTotal() + //{ + // return (base.NumberOfBlueShape * Price); + //} + //public int YellowCirclesTotal() + //{ + // return (base.NumberOfYellowShape * Price); + //} } } diff --git a/Order.Management/CuttingListReport.cs b/Order.Management/CuttingListReport.cs index 125d45f..e5b9dee 100644 --- a/Order.Management/CuttingListReport.cs +++ b/Order.Management/CuttingListReport.cs @@ -4,65 +4,33 @@ namespace Order.Management { - class CuttingListReport : Order + class CuttingListReport : Report { public int tableWidth = 20; - public CuttingListReport(string customerName, string customerAddress, string dueDate, List shapes) + Order order = new Order(); + public CuttingListReport(string customerName, string address, string dueDate, List shapes) { - base.CustomerName = customerName; - base.Address = customerAddress; - base.DueDate = dueDate; - base.OrderedBlocks = shapes; + order.CustomerName = customerName; + order.Address = address; + order.DueDate = dueDate; + order.OrderedBlocks = shapes; } public override void GenerateReport() { Console.WriteLine("\nYour cutting list has been generated: "); - Console.WriteLine(base.ToString()); + Console.WriteLine(order.ToString()); generateTable(); } public 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()); - PrintLine(); + PrintLine(tableWidth); + PrintRow(tableWidth, " ", " Qty "); + PrintLine(tableWidth); + PrintRow(tableWidth, "Square", order.OrderedBlocks[0].TotalQuantityOfShape().ToString()); + PrintRow(tableWidth, "Triangle", order.OrderedBlocks[1].TotalQuantityOfShape().ToString()); + PrintRow(tableWidth, "Circle", order.OrderedBlocks[2].TotalQuantityOfShape().ToString()); + PrintLine(tableWidth); } - 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); - } - } - - } } diff --git a/Order.Management/InvoiceReport.cs b/Order.Management/InvoiceReport.cs index a8e3e31..ef6495b 100644 --- a/Order.Management/InvoiceReport.cs +++ b/Order.Management/InvoiceReport.cs @@ -4,15 +4,16 @@ namespace Order.Management { - class InvoiceReport : Order + class InvoiceReport : Report { public int tableWidth = 73; - public InvoiceReport(string customerName, string customerAddress, string dueDate, List shapes) + Order order = new Order(); + public InvoiceReport(string customerName, string address, string dueDate, List shapes) { - base.CustomerName = customerName; - base.Address = customerAddress; - base.DueDate = dueDate; - base.OrderedBlocks = shapes; + order.CustomerName = customerName; + order.Address = address; + order.DueDate = dueDate; + order.OrderedBlocks = shapes; } public override void GenerateReport() @@ -28,73 +29,46 @@ public override void GenerateReport() public void RedPaintSurcharge() { - Console.WriteLine("Red Color Surcharge " + TotalAmountOfRedShapes() + " @ $" + base.OrderedBlocks[0].AdditionalCharge + " ppi = $" + TotalPriceRedPaintSurcharge()); + Circle circle = new Circle(); + Console.WriteLine("Red Color Surcharge " + TotalAmountOfRedShapes() + " @ $" + circle.AdditionalCharge + " ppi = $" + TotalPriceRedPaintSurcharge()); } public int TotalAmountOfRedShapes() { - return base.OrderedBlocks[0].NumberOfRedShape + base.OrderedBlocks[1].NumberOfRedShape + - base.OrderedBlocks[2].NumberOfRedShape; + return order.OrderedBlocks[0].NumberOfColorShape["Red"] + order.OrderedBlocks[1].NumberOfColorShape["Red"] + + order.OrderedBlocks[2].NumberOfColorShape["Red"]; } public int TotalPriceRedPaintSurcharge() { - return TotalAmountOfRedShapes() * base.OrderedBlocks[0].AdditionalCharge; + Circle circle = new Circle(); + return TotalAmountOfRedShapes() * circle.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(); + PrintLine(tableWidth); + PrintRow(tableWidth, " ", " Red ", " Blue ", " Yellow "); + PrintLine(tableWidth); + PrintRow(tableWidth, "Square", order.OrderedBlocks[0].NumberOfColorShape["Red"].ToString(), order.OrderedBlocks[0].NumberOfColorShape["Blue"].ToString(), order.OrderedBlocks[0].NumberOfColorShape["Yellow"].ToString()); + PrintRow(tableWidth, "Triangle", order.OrderedBlocks[1].NumberOfColorShape["Red"].ToString(), order.OrderedBlocks[1].NumberOfColorShape["Blue"].ToString(), order.OrderedBlocks[1].NumberOfColorShape["Yellow"].ToString()); + PrintRow(tableWidth, "Circle", order.OrderedBlocks[2].NumberOfColorShape["Red"].ToString(), order.OrderedBlocks[2].NumberOfColorShape["Blue"].ToString(), order.OrderedBlocks[2].NumberOfColorShape["Yellow"].ToString()); + PrintLine(tableWidth); } + //OrderXXXDetails can be merged as one method by passing parameters, e.g.OrderShapeDetails(shape) public void OrderSquareDetails() { - Console.WriteLine("\nSquares " + base.OrderedBlocks[0].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[0].Price + " ppi = $" + base.OrderedBlocks[0].Total()); + Square square = new Square(); + Console.WriteLine("\nSquares " + order.OrderedBlocks[0].TotalQuantityOfShape() + " @ $" + square.Price + " ppi = $" + square.Total(order.OrderedBlocks[0])); } public void OrderTriangleDetails() { - Console.WriteLine("Triangles " + base.OrderedBlocks[1].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[1].Price + " ppi = $" + base.OrderedBlocks[1].Total()); + Triangle triangle = new Triangle(); + Console.WriteLine("Triangles " + order.OrderedBlocks[1].TotalQuantityOfShape() + " @ $" + triangle.Price + " ppi = $" + triangle.Total(order.OrderedBlocks[1])); } public void OrderCircleDetails() { - Console.WriteLine("Circles " + base.OrderedBlocks[2].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[2].Price + " ppi = $" + base.OrderedBlocks[2].Total()); - } - - // PrintLine、PrintRow、AlignCentre can be moved into another class(e.g.help.cs) - 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); - } + Circle circle = new Circle(); + Console.WriteLine("Circles " + order.OrderedBlocks[2].TotalQuantityOfShape() + " @ $" + circle.Price + " ppi = $" + circle.Total(order.OrderedBlocks[2])); } } } diff --git a/Order.Management/Order.cs b/Order.Management/Order.cs index 87f2442..0554cac 100644 --- a/Order.Management/Order.cs +++ b/Order.Management/Order.cs @@ -4,18 +4,25 @@ namespace Order.Management { - abstract class Order + public 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; } + public int NumberOfRedShape { get; set; } - public abstract void GenerateReport(); + public Dictionary NumberOfColorShape{ get; set; } - // Override ToString(), because it is inherited from Object.ToString(). - public string ToString() + public List OrderedBlocks { get; set; } + + public int TotalQuantityOfShape() + { + return NumberOfColorShape["Red"] + NumberOfColorShape["Blue"] + NumberOfColorShape["Yellow"]; + } + + //override ToString() + public override string ToString() { return "\nName: " + CustomerName + " Address: " + Address + " Due Date: " + DueDate + " Order #: " + OrderNumber; } diff --git a/Order.Management/PaintingReport.cs b/Order.Management/PaintingReport.cs index 9b61c83..ed42fae 100644 --- a/Order.Management/PaintingReport.cs +++ b/Order.Management/PaintingReport.cs @@ -4,64 +4,33 @@ namespace Order.Management { - class PaintingReport : Order + class PaintingReport : Report { public int tableWidth = 73; - public PaintingReport(string customerName, string customerAddress, string dueDate, List shapes) + Order order = new Order(); + public PaintingReport(string customerName, string address, string dueDate, List shapes) { - base.CustomerName = customerName; - base.Address = customerAddress; - base.DueDate = dueDate; - base.OrderedBlocks = shapes; + order.CustomerName = customerName; + order.Address = address; + order.DueDate = dueDate; + order.OrderedBlocks = shapes; } public override void GenerateReport() { Console.WriteLine("\nYour painting report has been generated: "); - Console.WriteLine(base.ToString()); + Console.WriteLine(order.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); - } + PrintLine(tableWidth); + PrintRow(tableWidth, " ", " Red ", " Blue ", " Yellow "); + PrintLine(tableWidth); + PrintRow(tableWidth, "Square", order.OrderedBlocks[0].NumberOfColorShape["Red"].ToString(), order.OrderedBlocks[0].NumberOfColorShape["Blue"].ToString(), order.OrderedBlocks[0].NumberOfColorShape["Yellow"].ToString()); + PrintRow(tableWidth, "Triangle", order.OrderedBlocks[1].NumberOfColorShape["Red"].ToString(), order.OrderedBlocks[1].NumberOfColorShape["Blue"].ToString(), order.OrderedBlocks[1].NumberOfColorShape["Yellow"].ToString()); + PrintRow(tableWidth, "Circle", order.OrderedBlocks[2].NumberOfColorShape["Red"].ToString(), order.OrderedBlocks[2].NumberOfColorShape["Blue"].ToString(), order.OrderedBlocks[2].NumberOfColorShape["Yellow"].ToString()); + PrintLine(tableWidth); } } } diff --git a/Order.Management/Program.cs b/Order.Management/Program.cs index 20678ef..38dbc1f 100644 --- a/Order.Management/Program.cs +++ b/Order.Management/Program.cs @@ -16,53 +16,70 @@ static void Main(string[] args) CuttingListReport(customerName, address, dueDate, orderedShapes); - PaintingReport(customerName, address, dueDate, orderedShapes); + PaintingReport(customerName, address, dueDate,orderedShapes); } // Order Circle Input // OrderCirclesInput()、OrderSquaresInput()、OrderTrianglesInput() - // The above three methods can be merged as one method by passing parameters(e.g.OrderInput(shape)). - public static Circle OrderCirclesInput() - { - Console.Write("\nPlease input the number of Red Circle: "); - int redCircle = Convert.ToInt32(userInput()); - Console.Write("Please input the number of Blue Circle: "); - int blueCircle = Convert.ToInt32(userInput()); - Console.Write("Please input the number of Yellow Circle: "); - int yellowCircle = Convert.ToInt32(userInput()); - - Circle circle = new Circle(redCircle, blueCircle, yellowCircle); - return circle; - } + // The above three methods can be merged as one method by passing parameters(e.g.OrderShapeInput(shape)). + //public static Circle OrderCirclesInput() + //{ + // Console.Write("\nPlease input the number of Red Circle: "); + // int redCircle = Convert.ToInt32(userInput()); + // Console.Write("Please input the number of Blue Circle: "); + // int blueCircle = Convert.ToInt32(userInput()); + // Console.Write("Please input the number of Yellow Circle: "); + // int yellowCircle = Convert.ToInt32(userInput()); + + // Circle circle = new Circle(redCircle, blueCircle, yellowCircle); + // return circle; + //} - // Order Squares Input - public static Square OrderSquaresInput() + //// Order Squares Input + //public static Square OrderSquaresInput() + //{ + // Console.Write("\nPlease input the number of Red Squares: "); + // int redSquare = Convert.ToInt32(userInput()); + // Console.Write("Please input the number of Blue Squares: "); + // int blueSquare = Convert.ToInt32(userInput()); + // Console.Write("Please input the number of Yellow Squares: "); + // int yellowSquare = Convert.ToInt32(userInput()); + + // Square square = new Square(redSquare, blueSquare, yellowSquare); + // return square; + //} + + //// Order Triangles Input + //// Use private or protected to replace public,unless special reasons. + //public static Triangle OrderTrianglesInput() + //{ + // Console.Write("\nPlease input the number of Red Triangles: "); + // // User input validity check(e.g.Regex reg = new Regex("^[0-9]+$")) + // int redTriangle = Convert.ToInt32(userInput()); + // Console.Write("Please input the number of Blue Triangles: "); + // int blueTriangle = Convert.ToInt32(userInput()); + // Console.Write("Please input the number of Yellow Triangles: "); + // int yellowTriangle = Convert.ToInt32(userInput()); + + // Triangle triangle = new Triangle(redTriangle, blueTriangle, yellowTriangle); + // return triangle; + //} + + private static Order OrderShapeInput(string shape) { - Console.Write("\nPlease input the number of Red Squares: "); - int redSquare = Convert.ToInt32(userInput()); - Console.Write("Please input the number of Blue Squares: "); - int blueSquare = Convert.ToInt32(userInput()); - Console.Write("Please input the number of Yellow Squares: "); - int yellowSquare = Convert.ToInt32(userInput()); - - Square square = new Square(redSquare, blueSquare, yellowSquare); - return square; - } - - // Order Triangles Input - // Use private to replace public,unless special reasons. - public static Triangle OrderTrianglesInput() - { - Console.Write("\nPlease input the number of Red Triangles: "); - // User input validity check(e.g.Regex reg = new Regex("^[0-9]+$")) - int redTriangle = Convert.ToInt32(userInput()); - Console.Write("Please input the number of Blue Triangles: "); - int blueTriangle = Convert.ToInt32(userInput()); - Console.Write("Please input the number of Yellow Triangles: "); - int yellowTriangle = Convert.ToInt32(userInput()); - - Triangle triangle = new Triangle(redTriangle, blueTriangle, yellowTriangle); - return triangle; + Console.Write("\nPlease input the number of Red " + shape + ": "); + int red = Convert.ToInt32(userInput()); + Console.Write("Please input the number of Blue " + shape + ": "); + int blue = Convert.ToInt32(userInput()); + Console.Write("Please input the number of Yellow " + shape + ": "); + int yellow = Convert.ToInt32(userInput()); + + Order order = new Order(); + order.NumberOfColorShape = new Dictionary(); + order.NumberOfColorShape["Red"] = red; + order.NumberOfColorShape["Blue"] = blue; + order.NumberOfColorShape["Yellow"] = yellow; + return order; } // User Console Input @@ -79,23 +96,23 @@ public static string userInput() } // Generate Painting Report - private static void PaintingReport(string customerName, string address, string dueDate, List orderedShapes) + private static void PaintingReport(string customerName, string address, string dueDate, List orderedShapes) { - PaintingReport paintingReport = new PaintingReport(customerName, address, dueDate, orderedShapes); + PaintingReport paintingReport = new PaintingReport(customerName, address, dueDate,orderedShapes); paintingReport.GenerateReport(); } // Generate Painting Report - private static void CuttingListReport(string customerName, string address, string dueDate, List orderedShapes) + private static void CuttingListReport(string customerName, string address, string dueDate, List orderedShapes) { - CuttingListReport cuttingListReport = new CuttingListReport(customerName, address, dueDate, orderedShapes); + CuttingListReport cuttingListReport = new CuttingListReport(customerName, address, dueDate,orderedShapes); cuttingListReport.GenerateReport(); } // Generate Invoice Report - private static void InvoiceReport(string customerName, string address, string dueDate, List orderedShapes) + private static void InvoiceReport(string customerName, string address, string dueDate, List orderedShapes) { - InvoiceReport invoiceReport = new InvoiceReport(customerName, address, dueDate, orderedShapes); + InvoiceReport invoiceReport = new InvoiceReport(customerName, address, dueDate,orderedShapes); invoiceReport.GenerateReport(); } @@ -113,17 +130,31 @@ private static (string customerName, string address, string dueDate) CustomerInf } // Get order input - private static List CustomerOrderInput() + private static List CustomerOrderInput() { - Square square = OrderSquaresInput(); - Triangle triangle = OrderTrianglesInput(); - Circle circle = OrderCirclesInput(); - - var orderedShapes = new List(); - orderedShapes.Add(square); - orderedShapes.Add(triangle); - orderedShapes.Add(circle); + Order SquareOrder = OrderShapeInput("Square"); + Order TriangleOrder = OrderShapeInput("Triangle"); + Order CircleOrder = OrderShapeInput("Circle"); + + var orderedShapes = new List(); + orderedShapes.Add(SquareOrder); + orderedShapes.Add(TriangleOrder); + orderedShapes.Add(CircleOrder); return orderedShapes; } + + // Get order input + //private static List CustomerOrderInput() + //{ + // Square square = OrderSquaresInput(); + // Triangle triangle = OrderTrianglesInput(); + // Circle circle = OrderCirclesInput(); + + // var orderedShapes = new List(); + // orderedShapes.Add(square); + // orderedShapes.Add(triangle); + // orderedShapes.Add(circle); + // return orderedShapes; + //} } } diff --git a/Order.Management/Report.cs b/Order.Management/Report.cs new file mode 100644 index 0000000..31c21d9 --- /dev/null +++ b/Order.Management/Report.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Order.Management +{ + abstract class Report + { + public abstract void GenerateReport(); + + public void PrintLine(int tableWidth) + { + Console.WriteLine(new string('-', tableWidth)); + } + + public void PrintRow(int tableWidth, 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); + } + } + } +} diff --git a/Order.Management/Shape.cs b/Order.Management/Shape.cs index a397d25..d696ec6 100644 --- a/Order.Management/Shape.cs +++ b/Order.Management/Shape.cs @@ -9,20 +9,22 @@ 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() - { - return NumberOfRedShape + NumberOfBlueShape + NumberOfYellowShape; - } + + //NumberOfXXXShape actually are not the attributes of Shape class, they should be moved to Order class. + //public int NumberOfRedShape { get; set; } + //public int NumberOfBlueShape { get; set; } + //public int NumberOfYellowShape { get; set; } + //public int TotalQuantityOfShape() + //{ + // return NumberOfRedShape + NumberOfBlueShape + NumberOfYellowShape; + //} // This method isn't used, can be removed. - public int AdditionalChargeTotal() - { - return NumberOfRedShape * AdditionalCharge; - } - public abstract int Total(); + //public int AdditionalChargeTotal() + //{ + // return NumberOfRedShape * AdditionalCharge; + //} + public abstract int Total(Order order); } } diff --git a/Order.Management/Square.cs b/Order.Management/Square.cs index 017601e..9df3a39 100644 --- a/Order.Management/Square.cs +++ b/Order.Management/Square.cs @@ -9,32 +9,22 @@ class Square : Shape public int SquarePrice = 1; - public Square(int numberOfRedSquares, int numberOfBlueSquares, int numberOfYellowSquares) + public Square() { Name = "Square"; base.Price = SquarePrice; AdditionalCharge = 1; - base.NumberOfRedShape = numberOfRedSquares; - base.NumberOfBlueShape = numberOfBlueSquares; - base.NumberOfYellowShape = numberOfYellowSquares; } - public override int Total() + public override int Total(Order order) { - return RedSquaresTotal() + BlueSquaresTotal() + YellowSquaresTotal(); + return ColorCirclesTotal(order, "Red") + ColorCirclesTotal(order, "Blue") + ColorCirclesTotal(order, "Yellow"); } - public int RedSquaresTotal() + public int ColorCirclesTotal(Order order, string color) { - return (base.NumberOfRedShape * Price); - } - public int BlueSquaresTotal() - { - return (base.NumberOfBlueShape * Price); - } - public int YellowSquaresTotal() - { - return (base.NumberOfYellowShape * Price); + int TotalPrice = order.NumberOfColorShape[color] * Price; + return TotalPrice; } } } diff --git a/Order.Management/Triangle.cs b/Order.Management/Triangle.cs index dbf48ff..a4a3927 100644 --- a/Order.Management/Triangle.cs +++ b/Order.Management/Triangle.cs @@ -7,33 +7,22 @@ namespace Order.Management class Triangle : Shape { public int TrianglePrice = 2; - public Triangle(int numberOfRedTriangles, int numberOfBlueTriangles, int numberOfYellowTriangles) + public Triangle() { Name = "Triangle"; base.Price = TrianglePrice; AdditionalCharge = 1; - base.NumberOfRedShape = numberOfRedTriangles; - base.NumberOfBlueShape = numberOfBlueTriangles; - base.NumberOfYellowShape = numberOfYellowTriangles; } - public override int Total() + public override int Total(Order order) { - return RedTrianglesTotal() + BlueTrianglesTotal() + YellowTrianglesTotal(); + return ColorCirclesTotal(order, "Red") + ColorCirclesTotal(order, "Blue") + ColorCirclesTotal(order, "Yellow"); } - public int RedTrianglesTotal() + public int ColorCirclesTotal(Order order, string color) { - return (base.NumberOfRedShape * Price); + int TotalPrice = order.NumberOfColorShape[color] * Price; + return TotalPrice; } - public int BlueTrianglesTotal() - { - return (base.NumberOfBlueShape * Price); - } - public int YellowTrianglesTotal() - { - return (base.NumberOfYellowShape * Price); - } - -} + } }