From f0384dbc0f6ae8af71d361b86dcc4786efb9d98e Mon Sep 17 00:00:00 2001 From: Mohammad Kashem Date: Mon, 15 Feb 2021 00:34:47 +1300 Subject: [PATCH 1/7] fix shapes --- Order.Management/Circle.cs | 13 +++++-------- Order.Management/Shape.cs | 19 +++++++++++++------ Order.Management/Square.cs | 13 ++++--------- Order.Management/Triangle.cs | 12 +++++------- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Order.Management/Circle.cs b/Order.Management/Circle.cs index 9824ecc..7ab27e9 100644 --- a/Order.Management/Circle.cs +++ b/Order.Management/Circle.cs @@ -6,15 +6,12 @@ namespace Order.Management { class Circle : Shape { - public int circlePrice = 3; - public Circle(int red, int blue, int yellow) + public override string Name => "Circle"; + + public override int Price => 3; + + public Circle(int red, int blue, int yellow) :base(red, blue, yellow) { - Name = "Circle"; - base.Price = circlePrice; - AdditionalCharge = 1; - base.NumberOfRedShape = red; - base.NumberOfBlueShape = blue; - base.NumberOfYellowShape = yellow; } public override int Total() { diff --git a/Order.Management/Shape.cs b/Order.Management/Shape.cs index 7f5c61c..bacbfc8 100644 --- a/Order.Management/Shape.cs +++ b/Order.Management/Shape.cs @@ -6,12 +6,19 @@ 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; } + protected Shape(int numberOfRedShape, int numberOfBlueShape, int numberOfYellowShape) + { + NumberOfRedShape = numberOfRedShape; + NumberOfBlueShape = numberOfBlueShape; + NumberOfYellowShape = numberOfYellowShape; + } + + public abstract string Name { get; } + public abstract int Price { get; } + public virtual int AdditionalCharge { get => 1; } + public int NumberOfRedShape { get; private set; } + public int NumberOfBlueShape { get; private set; } + public int NumberOfYellowShape { get; private set; } public int TotalQuantityOfShape() { return NumberOfRedShape + NumberOfBlueShape + NumberOfYellowShape; diff --git a/Order.Management/Square.cs b/Order.Management/Square.cs index 017601e..10d7df7 100644 --- a/Order.Management/Square.cs +++ b/Order.Management/Square.cs @@ -6,17 +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) + public Square(int numberOfRedSquares, int numberOfBlueSquares, int numberOfYellowSquares) : + base(numberOfRedSquares, numberOfBlueSquares, numberOfYellowSquares) { - Name = "Square"; - base.Price = SquarePrice; - AdditionalCharge = 1; - base.NumberOfRedShape = numberOfRedSquares; - base.NumberOfBlueShape = numberOfBlueSquares; - base.NumberOfYellowShape = numberOfYellowSquares; } public override int Total() diff --git a/Order.Management/Triangle.cs b/Order.Management/Triangle.cs index dbf48ff..d286080 100644 --- a/Order.Management/Triangle.cs +++ b/Order.Management/Triangle.cs @@ -6,15 +6,13 @@ namespace Order.Management { class Triangle : Shape { - public int TrianglePrice = 2; + public override string Name => "Triangle"; + + public override int Price => 2; + public Triangle(int numberOfRedTriangles, int numberOfBlueTriangles, int numberOfYellowTriangles) + : base(numberOfRedTriangles, numberOfBlueTriangles, numberOfYellowTriangles) { - Name = "Triangle"; - base.Price = TrianglePrice; - AdditionalCharge = 1; - base.NumberOfRedShape = numberOfRedTriangles; - base.NumberOfBlueShape = numberOfBlueTriangles; - base.NumberOfYellowShape = numberOfYellowTriangles; } public override int Total() From d76b0fb7cfdf51b8c9c28c51ce2aee11e9274cdb Mon Sep 17 00:00:00 2001 From: Mohammad Kashem Date: Mon, 15 Feb 2021 01:10:24 +1300 Subject: [PATCH 2/7] update shape and reports --- Order.Management/Circle.cs | 17 ------------ Order.Management/CuttingListReport.cs | 6 ++-- Order.Management/InvoiceReport.cs | 6 ++-- Order.Management/Shape.cs | 40 ++++++++++++++++++++++----- Order.Management/Square.cs | 18 ------------ Order.Management/Triangle.cs | 21 +------------- 6 files changed, 40 insertions(+), 68 deletions(-) diff --git a/Order.Management/Circle.cs b/Order.Management/Circle.cs index 7ab27e9..5b0b13d 100644 --- a/Order.Management/Circle.cs +++ b/Order.Management/Circle.cs @@ -13,22 +13,5 @@ class Circle : Shape public Circle(int red, int blue, int yellow) :base(red, blue, yellow) { } - public override int Total() - { - return RedCirclesTotal() + BlueCirclesTotal() + YellowCirclesTotal(); - } - - public int RedCirclesTotal() - { - return (base.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..7fb8eaa 100644 --- a/Order.Management/CuttingListReport.cs +++ b/Order.Management/CuttingListReport.cs @@ -26,9 +26,9 @@ 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()); + PrintRow("Square",base.OrderedBlocks[0].TotalQuantity.ToString()); + PrintRow("Triangle", base.OrderedBlocks[1].TotalQuantity.ToString()); + PrintRow("Circle", base.OrderedBlocks[2].TotalQuantity.ToString()); PrintLine(); } public void PrintLine() diff --git a/Order.Management/InvoiceReport.cs b/Order.Management/InvoiceReport.cs index 78443c3..4c27b63 100644 --- a/Order.Management/InvoiceReport.cs +++ b/Order.Management/InvoiceReport.cs @@ -53,15 +53,15 @@ public void GenerateTable() } public void OrderSquareDetails() { - Console.WriteLine("\nSquares " + base.OrderedBlocks[0].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[0].Price + " ppi = $" + base.OrderedBlocks[0].Total()); + Console.WriteLine("\nSquares " + base.OrderedBlocks[0].TotalQuantity + " @ $" + base.OrderedBlocks[0].Price + " ppi = $" + base.OrderedBlocks[0].TotalPrice); } public void OrderTriangleDetails() { - Console.WriteLine("Triangles " + base.OrderedBlocks[1].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[1].Price + " ppi = $" + base.OrderedBlocks[1].Total()); + Console.WriteLine("Triangles " + base.OrderedBlocks[1].TotalQuantity + " @ $" + base.OrderedBlocks[1].Price + " ppi = $" + base.OrderedBlocks[1].TotalPrice); } public void OrderCircleDetails() { - Console.WriteLine("Circles " + base.OrderedBlocks[2].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[2].Price + " ppi = $" + base.OrderedBlocks[2].Total()); + Console.WriteLine("Circles " + base.OrderedBlocks[2].TotalQuantity + " @ $" + base.OrderedBlocks[2].Price + " ppi = $" + base.OrderedBlocks[2].TotalPrice); } public void PrintLine() { diff --git a/Order.Management/Shape.cs b/Order.Management/Shape.cs index bacbfc8..39c749b 100644 --- a/Order.Management/Shape.cs +++ b/Order.Management/Shape.cs @@ -6,29 +6,55 @@ namespace Order.Management { abstract class Shape { + #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 AdditionalCharge { get => 1; } - public int NumberOfRedShape { get; private set; } - public int NumberOfBlueShape { get; private set; } - public int NumberOfYellowShape { get; private set; } - public int TotalQuantityOfShape() + + #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; } - 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 10d7df7..9c48742 100644 --- a/Order.Management/Square.cs +++ b/Order.Management/Square.cs @@ -13,23 +13,5 @@ public Square(int numberOfRedSquares, int numberOfBlueSquares, int numberOfYello base(numberOfRedSquares, numberOfBlueSquares, 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() - { - return (base.NumberOfYellowShape * Price); - } } } diff --git a/Order.Management/Triangle.cs b/Order.Management/Triangle.cs index d286080..866c077 100644 --- a/Order.Management/Triangle.cs +++ b/Order.Management/Triangle.cs @@ -14,24 +14,5 @@ public Triangle(int numberOfRedTriangles, int numberOfBlueTriangles, int numberO : base(numberOfRedTriangles, numberOfBlueTriangles, numberOfYellowTriangles) { } - - public override int Total() - { - return RedTrianglesTotal() + BlueTrianglesTotal() + YellowTrianglesTotal(); - } - - public int RedTrianglesTotal() - { - return (base.NumberOfRedShape * Price); - } - public int BlueTrianglesTotal() - { - return (base.NumberOfBlueShape * Price); - } - public int YellowTrianglesTotal() - { - return (base.NumberOfYellowShape * Price); - } - -} + } } From fb43d1ee3036b5e5e8c49817e33b04ee07ac417a Mon Sep 17 00:00:00 2001 From: Mohammad Kashem Date: Mon, 15 Feb 2021 01:58:45 +1300 Subject: [PATCH 3/7] update shape --- Order.Management/Shape.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Order.Management/Shape.cs b/Order.Management/Shape.cs index 39c749b..209435a 100644 --- a/Order.Management/Shape.cs +++ b/Order.Management/Shape.cs @@ -26,10 +26,10 @@ protected Shape(int numberOfRedShape, int numberOfBlueShape, int numberOfYellowS } #region Abstract properties - - public abstract string Name { get; } - public abstract int Price { get; } - public virtual int AdditionalCharge { get => 1; } + + protected abstract string Name { get; } + protected abstract int Price { get; } + protected virtual int AdditionalCharge { get => 1; } #endregion From 3a25413c27d9e3dc71d20d6653afefd62573f96d Mon Sep 17 00:00:00 2001 From: Mohammad Kashem Date: Mon, 15 Feb 2021 02:11:02 +1300 Subject: [PATCH 4/7] Revert "update shape" This reverts commit fb43d1ee3036b5e5e8c49817e33b04ee07ac417a. --- Order.Management/Shape.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Order.Management/Shape.cs b/Order.Management/Shape.cs index 209435a..39c749b 100644 --- a/Order.Management/Shape.cs +++ b/Order.Management/Shape.cs @@ -26,10 +26,10 @@ protected Shape(int numberOfRedShape, int numberOfBlueShape, int numberOfYellowS } #region Abstract properties - - protected abstract string Name { get; } - protected abstract int Price { get; } - protected virtual int AdditionalCharge { get => 1; } + + public abstract string Name { get; } + public abstract int Price { get; } + public virtual int AdditionalCharge { get => 1; } #endregion From d8d346da536bb31736481cbba1e91dcf6b7d04e0 Mon Sep 17 00:00:00 2001 From: Mohammad Kashem Date: Mon, 15 Feb 2021 03:30:32 +1300 Subject: [PATCH 5/7] Update report and shape --- Order.Management/CuttingListReport.cs | 59 +++++-------------- Order.Management/InvoiceReport.cs | 85 +++++++-------------------- Order.Management/Order.cs | 83 +++++++++++++++++++++++++- Order.Management/PaintingReport.cs | 50 +--------------- Order.Management/Shape.cs | 4 +- 5 files changed, 122 insertions(+), 159 deletions(-) diff --git a/Order.Management/CuttingListReport.cs b/Order.Management/CuttingListReport.cs index 7fb8eaa..e6aa45f 100644 --- a/Order.Management/CuttingListReport.cs +++ b/Order.Management/CuttingListReport.cs @@ -6,7 +6,6 @@ namespace Order.Management { class CuttingListReport : Order { - public int tableWidth = 20; public CuttingListReport(string customerName, string customerAddress, string dueDate, List shapes) { base.CustomerName = customerName; @@ -15,54 +14,28 @@ public CuttingListReport(string customerName, string customerAddress, string due 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].TotalQuantity.ToString()); - PrintRow("Triangle", base.OrderedBlocks[1].TotalQuantity.ToString()); - PrintRow("Circle", base.OrderedBlocks[2].TotalQuantity.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 4c27b63..95f4d7b 100644 --- a/Order.Management/InvoiceReport.cs +++ b/Order.Management/InvoiceReport.cs @@ -6,7 +6,12 @@ namespace Order.Management { class InvoiceReport : Order { - public int tableWidth = 73; + public override string ReportType => "Invoice" ; + + private string PriceAtText => "@ $"; + private string PriceTotalText => "ppi = $"; + private int TotalReds => TotalAmountOfRedShapes(); + public InvoiceReport(string customerName, string customerAddress, string dueDate, List shapes) { base.CustomerName = customerName; @@ -17,82 +22,36 @@ public InvoiceReport(string customerName, string customerAddress, string dueDate 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].TotalQuantity + " @ $" + base.OrderedBlocks[0].Price + " ppi = $" + base.OrderedBlocks[0].TotalPrice); - } - public void OrderTriangleDetails() + private int TotalAmountOfRedShapes() { - Console.WriteLine("Triangles " + base.OrderedBlocks[1].TotalQuantity + " @ $" + base.OrderedBlocks[1].Price + " ppi = $" + base.OrderedBlocks[1].TotalPrice); - } - public void OrderCircleDetails() - { - Console.WriteLine("Circles " + base.OrderedBlocks[2].TotalQuantity + " @ $" + base.OrderedBlocks[2].Price + " ppi = $" + base.OrderedBlocks[2].TotalPrice); - } - 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..63890be 100644 --- a/Order.Management/Order.cs +++ b/Order.Management/Order.cs @@ -12,11 +12,90 @@ abstract class Order public int OrderNumber { get; set; } public List OrderedBlocks { get; set; } - public abstract void GenerateReport(); + #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 string ToString() + 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 = "|"; + + foreach (string column in columns) + { + row += AlignCentre(column, width) + "|"; + } + + Console.WriteLine(row); + } + + private string CustomerDetails() { return "\nName: " + CustomerName + " Address: " + Address + " Due Date: " + DueDate + " Order #: " + OrderNumber; } + + protected void PrintLine() + { + Console.WriteLine(new string('-', TableWidth)); + } + + protected void ReportHeader(string reportType) + { + 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..5519b23 100644 --- a/Order.Management/PaintingReport.cs +++ b/Order.Management/PaintingReport.cs @@ -6,7 +6,6 @@ namespace Order.Management { class PaintingReport : Order { - public int tableWidth = 73; public PaintingReport(string customerName, string customerAddress, string dueDate, List shapes) { base.CustomerName = customerName; @@ -14,54 +13,7 @@ public PaintingReport(string customerName, string customerAddress, string dueDat base.DueDate = dueDate; base.OrderedBlocks = 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/Shape.cs b/Order.Management/Shape.cs index 39c749b..dff1b95 100644 --- a/Order.Management/Shape.cs +++ b/Order.Management/Shape.cs @@ -29,7 +29,7 @@ protected Shape(int numberOfRedShape, int numberOfBlueShape, int numberOfYellowS public abstract string Name { get; } public abstract int Price { get; } - public virtual int AdditionalCharge { get => 1; } + public virtual int AdditionalChargeRed { get => 1; } #endregion @@ -46,7 +46,7 @@ protected int TotalQuantityOfShape() protected virtual int AdditionalChargeTotal() { - return NumberOfRedShape * AdditionalCharge; + return NumberOfRedShape * AdditionalChargeRed; } protected virtual int Total() From a9eb9150582d229fdfa32606bc38610f984c19d2 Mon Sep 17 00:00:00 2001 From: Mohammad Kashem Date: Mon, 15 Feb 2021 03:48:14 +1300 Subject: [PATCH 6/7] colours --- Order.Management/BlueColour.cs | 15 +++++++++++++++ Order.Management/Colour.cs | 23 +++++++++++++++++++++++ Order.Management/RedColour.cs | 15 +++++++++++++++ Order.Management/YellowColour.cs | 16 ++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 Order.Management/BlueColour.cs create mode 100644 Order.Management/Colour.cs create mode 100644 Order.Management/RedColour.cs create mode 100644 Order.Management/YellowColour.cs diff --git a/Order.Management/BlueColour.cs b/Order.Management/BlueColour.cs new file mode 100644 index 0000000..1873bca --- /dev/null +++ b/Order.Management/BlueColour.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Order.Management +{ + class BlueColour : Colour + { + public override string ColourName => "Blue"; + public BlueColour(int totalNumber) : base(totalNumber) + { + + } + } +} diff --git a/Order.Management/Colour.cs b/Order.Management/Colour.cs new file mode 100644 index 0000000..21a0308 --- /dev/null +++ b/Order.Management/Colour.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Order.Management +{ + abstract class Colour + { + public abstract string ColourName { get; } + + public virtual int SurchargeAmount => 0; + + public int TotalNumber { get; private set; } + + public int TotalSurchargeAmount { get; private set; } + + protected Colour(int totalNumber) + { + TotalNumber = totalNumber; + TotalSurchargeAmount = TotalNumber * TotalSurchargeAmount; + } + } +} diff --git a/Order.Management/RedColour.cs b/Order.Management/RedColour.cs new file mode 100644 index 0000000..df6fcc3 --- /dev/null +++ b/Order.Management/RedColour.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Order.Management +{ + class RedColour : Colour + { + public override string ColourName => "Red"; + + public RedColour(int totalNumber) : base(totalNumber) + { + } + } +} diff --git a/Order.Management/YellowColour.cs b/Order.Management/YellowColour.cs new file mode 100644 index 0000000..150eef4 --- /dev/null +++ b/Order.Management/YellowColour.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Order.Management +{ + class YellowColour : Colour + { + public override string ColourName => "Yellow"; + + public YellowColour(int totalNumber) : base(totalNumber) + { + + } + } +} From 0cf00ca51838ccca85e5f3281ad536f3ebebb6aa Mon Sep 17 00:00:00 2001 From: Mohammad Kashem Date: Mon, 15 Feb 2021 10:01:37 +1300 Subject: [PATCH 7/7] report and program update --- Order.Management/BlueColour.cs | 15 ------- Order.Management/Colour.cs | 23 ----------- Order.Management/CustomerInfo.cs | 13 ++++++ Order.Management/CuttingListReport.cs | 6 +-- Order.Management/InvoiceReport.cs | 6 +-- Order.Management/Order.cs | 16 +++++--- Order.Management/PaintingReport.cs | 8 +--- Order.Management/Program.cs | 57 +++++++++++++-------------- Order.Management/RedColour.cs | 15 ------- Order.Management/YellowColour.cs | 16 -------- 10 files changed, 55 insertions(+), 120 deletions(-) delete mode 100644 Order.Management/BlueColour.cs delete mode 100644 Order.Management/Colour.cs create mode 100644 Order.Management/CustomerInfo.cs delete mode 100644 Order.Management/RedColour.cs delete mode 100644 Order.Management/YellowColour.cs diff --git a/Order.Management/BlueColour.cs b/Order.Management/BlueColour.cs deleted file mode 100644 index 1873bca..0000000 --- a/Order.Management/BlueColour.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Order.Management -{ - class BlueColour : Colour - { - public override string ColourName => "Blue"; - public BlueColour(int totalNumber) : base(totalNumber) - { - - } - } -} diff --git a/Order.Management/Colour.cs b/Order.Management/Colour.cs deleted file mode 100644 index 21a0308..0000000 --- a/Order.Management/Colour.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Order.Management -{ - abstract class Colour - { - public abstract string ColourName { get; } - - public virtual int SurchargeAmount => 0; - - public int TotalNumber { get; private set; } - - public int TotalSurchargeAmount { get; private set; } - - protected Colour(int totalNumber) - { - TotalNumber = totalNumber; - TotalSurchargeAmount = TotalNumber * TotalSurchargeAmount; - } - } -} 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 e6aa45f..21741fc 100644 --- a/Order.Management/CuttingListReport.cs +++ b/Order.Management/CuttingListReport.cs @@ -6,12 +6,8 @@ namespace Order.Management { class CuttingListReport : Order { - 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 int TableWidth => 20; diff --git a/Order.Management/InvoiceReport.cs b/Order.Management/InvoiceReport.cs index 95f4d7b..1e163c4 100644 --- a/Order.Management/InvoiceReport.cs +++ b/Order.Management/InvoiceReport.cs @@ -12,12 +12,8 @@ class InvoiceReport : Order private string PriceTotalText => "ppi = $"; private int TotalReds => TotalAmountOfRedShapes(); - public InvoiceReport(string customerName, string customerAddress, string dueDate, List shapes) + 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() diff --git a/Order.Management/Order.cs b/Order.Management/Order.cs index 63890be..3e840ff 100644 --- a/Order.Management/Order.cs +++ b/Order.Management/Order.cs @@ -6,11 +6,15 @@ 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 Order(CustomerInfo customerInfo, List shapes) + { + CustomerInfo = customerInfo; + OrderedBlocks = shapes; + } #region Abstract Methods public virtual void GenerateTable() @@ -68,7 +72,7 @@ protected void PrintRow(List columns) private string CustomerDetails() { - return "\nName: " + CustomerName + " Address: " + Address + " Due Date: " + DueDate + " Order #: " + OrderNumber; + return "\nName: " + CustomerInfo.CustomerName + " Address: " + CustomerInfo.Address + " Due Date: " + CustomerInfo.DueDate + " Order #: " + OrderNumber; } protected void PrintLine() diff --git a/Order.Management/PaintingReport.cs b/Order.Management/PaintingReport.cs index 5519b23..29b5d25 100644 --- a/Order.Management/PaintingReport.cs +++ b/Order.Management/PaintingReport.cs @@ -6,12 +6,8 @@ namespace Order.Management { class PaintingReport : Order { - 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 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/RedColour.cs b/Order.Management/RedColour.cs deleted file mode 100644 index df6fcc3..0000000 --- a/Order.Management/RedColour.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Order.Management -{ - class RedColour : Colour - { - public override string ColourName => "Red"; - - public RedColour(int totalNumber) : base(totalNumber) - { - } - } -} diff --git a/Order.Management/YellowColour.cs b/Order.Management/YellowColour.cs deleted file mode 100644 index 150eef4..0000000 --- a/Order.Management/YellowColour.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Order.Management -{ - class YellowColour : Colour - { - public override string ColourName => "Yellow"; - - public YellowColour(int totalNumber) : base(totalNumber) - { - - } - } -}