From 8efbcd025c48af504d4a3735baa3fcca5c795867 Mon Sep 17 00:00:00 2001 From: Gerardo Sullivan Date: Tue, 25 May 2021 21:59:16 +1200 Subject: [PATCH 01/10] Add readme to solution --- Order.Management.sln | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Order.Management.sln b/Order.Management.sln index 400236d..333e7ca 100644 --- a/Order.Management.sln +++ b/Order.Management.sln @@ -3,7 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.29519.87 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Order.Management", "Order.Management\Order.Management.csproj", "{1DAC7794-3F0E-4083-95A9-2E6FF9512C0C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Order.Management", "Order.Management\Order.Management.csproj", "{1DAC7794-3F0E-4083-95A9-2E6FF9512C0C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4B49C9C7-B797-4C36-B4F5-1EEA2554D763}" + ProjectSection(SolutionItems) = preProject + README.md = README.md + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution From 4ef85dbc9ebe1e2f0ee83ca8eb6a7aeb2c4b2d9a Mon Sep 17 00:00:00 2001 From: Gerardo Sullivan Date: Tue, 25 May 2021 22:11:33 +1200 Subject: [PATCH 02/10] Tidy up some code Add better accessibility, unused references, line spacing, Method naming conventions, etc. --- Order.Management/Circle.cs | 10 ++++------ Order.Management/CuttingListReport.cs | 7 +++---- Order.Management/InvoiceReport.cs | 4 ++-- Order.Management/Order.cs | 8 +++----- Order.Management/PaintingReport.cs | 11 ++++++----- Order.Management/Program.cs | 15 +++++++-------- Order.Management/Shape.cs | 9 ++------- Order.Management/Square.cs | 9 ++------- Order.Management/Triangle.cs | 11 +++-------- 9 files changed, 32 insertions(+), 52 deletions(-) diff --git a/Order.Management/Circle.cs b/Order.Management/Circle.cs index 9824ecc..3871e4d 100644 --- a/Order.Management/Circle.cs +++ b/Order.Management/Circle.cs @@ -1,12 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Order.Management +namespace Order.Management { - class Circle : Shape + public class Circle : Shape { public int circlePrice = 3; + public Circle(int red, int blue, int yellow) { Name = "Circle"; @@ -16,6 +13,7 @@ public Circle(int red, int blue, int yellow) base.NumberOfBlueShape = blue; base.NumberOfYellowShape = yellow; } + public override int Total() { return RedCirclesTotal() + BlueCirclesTotal() + YellowCirclesTotal(); diff --git a/Order.Management/CuttingListReport.cs b/Order.Management/CuttingListReport.cs index 125d45f..24c5b0d 100644 --- a/Order.Management/CuttingListReport.cs +++ b/Order.Management/CuttingListReport.cs @@ -4,9 +4,10 @@ namespace Order.Management { - class CuttingListReport : Order + public class CuttingListReport : Order { public int tableWidth = 20; + public CuttingListReport(string customerName, string customerAddress, string dueDate, List shapes) { base.CustomerName = customerName; @@ -26,7 +27,7 @@ public void generateTable() PrintLine(); PrintRow(" ", " Qty "); PrintLine(); - PrintRow("Square",base.OrderedBlocks[0].TotalQuantityOfShape().ToString()); + PrintRow("Square", base.OrderedBlocks[0].TotalQuantityOfShape().ToString()); PrintRow("Triangle", base.OrderedBlocks[1].TotalQuantityOfShape().ToString()); PrintRow("Circle", base.OrderedBlocks[2].TotalQuantityOfShape().ToString()); PrintLine(); @@ -62,7 +63,5 @@ public string AlignCentre(string text, int width) return text.PadRight(width - (width - text.Length) / 2).PadLeft(width); } } - - } } diff --git a/Order.Management/InvoiceReport.cs b/Order.Management/InvoiceReport.cs index 78443c3..2fdacc7 100644 --- a/Order.Management/InvoiceReport.cs +++ b/Order.Management/InvoiceReport.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; -using System.Text; namespace Order.Management { - class InvoiceReport : Order + public class InvoiceReport : Order { public int tableWidth = 73; + public InvoiceReport(string customerName, string customerAddress, string dueDate, List shapes) { base.CustomerName = customerName; diff --git a/Order.Management/Order.cs b/Order.Management/Order.cs index 235c789..613093e 100644 --- a/Order.Management/Order.cs +++ b/Order.Management/Order.cs @@ -1,10 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; namespace Order.Management { - abstract class Order + public abstract class Order { public string CustomerName { get; set; } public string Address { get; set; } @@ -14,7 +12,7 @@ abstract class Order public abstract void GenerateReport(); - public string 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..80b6532 100644 --- a/Order.Management/PaintingReport.cs +++ b/Order.Management/PaintingReport.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; -using System.Text; namespace Order.Management { - class PaintingReport : Order + public class PaintingReport : Order { public int tableWidth = 73; + public PaintingReport(string customerName, string customerAddress, string dueDate, List shapes) { base.CustomerName = customerName; @@ -14,14 +14,15 @@ 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(); + GenerateTable(); } - public void generateTable() + public void GenerateTable() { PrintLine(); PrintRow(" ", " Red ", " Blue ", " Yellow "); @@ -31,7 +32,7 @@ public void generateTable() 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)); diff --git a/Order.Management/Program.cs b/Order.Management/Program.cs index 1422f85..4c27a75 100644 --- a/Order.Management/Program.cs +++ b/Order.Management/Program.cs @@ -3,10 +3,10 @@ namespace Order.Management { - class Program + public class Program { // Main entry - static void Main(string[] args) + public static void Main(string[] args) { var (customerName, address, dueDate) = CustomerInfoInput(); @@ -18,7 +18,7 @@ static void Main(string[] args) PaintingReport(customerName, address, dueDate, orderedShapes); } - + // Order Circle Input public static Circle OrderCirclesInput() { @@ -32,7 +32,7 @@ public static Circle OrderCirclesInput() Circle circle = new Circle(redCircle, blueCircle, yellowCircle); return circle; } - + // Order Squares Input public static Square OrderSquaresInput() { @@ -69,26 +69,25 @@ public static string userInput() { Console.WriteLine("please enter valid details"); input = Console.ReadLine(); - } return input; } - // Generate Painting Report + // Generate Painting Report private static void PaintingReport(string customerName, string address, string dueDate, List orderedShapes) { PaintingReport paintingReport = new PaintingReport(customerName, address, dueDate, orderedShapes); paintingReport.GenerateReport(); } - // Generate Painting Report + // Generate Painting Report private static void CuttingListReport(string customerName, string address, string dueDate, List orderedShapes) { CuttingListReport cuttingListReport = new CuttingListReport(customerName, address, dueDate, orderedShapes); cuttingListReport.GenerateReport(); } - // Generate Invoice Report + // Generate Invoice Report private static void InvoiceReport(string customerName, string address, string dueDate, List orderedShapes) { InvoiceReport invoiceReport = new InvoiceReport(customerName, address, dueDate, orderedShapes); diff --git a/Order.Management/Shape.cs b/Order.Management/Shape.cs index 7f5c61c..3d90013 100644 --- a/Order.Management/Shape.cs +++ b/Order.Management/Shape.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Order.Management +namespace Order.Management { - abstract class Shape + public abstract class Shape { public string Name { get; set; } public int Price { get; set; } @@ -22,6 +18,5 @@ public int AdditionalChargeTotal() return NumberOfRedShape * AdditionalCharge; } public abstract int Total(); - } } diff --git a/Order.Management/Square.cs b/Order.Management/Square.cs index 017601e..80b4d1e 100644 --- a/Order.Management/Square.cs +++ b/Order.Management/Square.cs @@ -1,12 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Order.Management +namespace Order.Management { - class Square : Shape + public class Square : Shape { - public int SquarePrice = 1; public Square(int numberOfRedSquares, int numberOfBlueSquares, int numberOfYellowSquares) diff --git a/Order.Management/Triangle.cs b/Order.Management/Triangle.cs index dbf48ff..73bbf6d 100644 --- a/Order.Management/Triangle.cs +++ b/Order.Management/Triangle.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Order.Management +namespace Order.Management { - class Triangle : Shape + public class Triangle : Shape { public int TrianglePrice = 2; public Triangle(int numberOfRedTriangles, int numberOfBlueTriangles, int numberOfYellowTriangles) @@ -34,6 +30,5 @@ public int YellowTrianglesTotal() { return (base.NumberOfYellowShape * Price); } - -} + } } From fb5087a2ac528588ce1cf98df5d74a7d79452475 Mon Sep 17 00:00:00 2001 From: Gerardo Sullivan Date: Tue, 25 May 2021 22:15:41 +1200 Subject: [PATCH 03/10] Add folder for ToyBlock models --- Order.Management/CuttingListReport.cs | 4 ++-- Order.Management/InvoiceReport.cs | 3 ++- Order.Management/Order.cs | 3 ++- Order.Management/PaintingReport.cs | 3 ++- Order.Management/Program.cs | 3 ++- Order.Management/{ => ToyBlocks}/Circle.cs | 4 +++- Order.Management/{ => ToyBlocks}/Shape.cs | 4 +++- Order.Management/{ => ToyBlocks}/Square.cs | 4 +++- Order.Management/{ => ToyBlocks}/Triangle.cs | 2 +- 9 files changed, 20 insertions(+), 10 deletions(-) rename Order.Management/{ => ToyBlocks}/Circle.cs (95%) rename Order.Management/{ => ToyBlocks}/Shape.cs (93%) rename Order.Management/{ => ToyBlocks}/Square.cs (95%) rename Order.Management/{ => ToyBlocks}/Triangle.cs (96%) diff --git a/Order.Management/CuttingListReport.cs b/Order.Management/CuttingListReport.cs index 24c5b0d..b9fa5cf 100644 --- a/Order.Management/CuttingListReport.cs +++ b/Order.Management/CuttingListReport.cs @@ -1,6 +1,6 @@ -using System; +using Order.Management.ToyBlocks; +using System; using System.Collections.Generic; -using System.Text; namespace Order.Management { diff --git a/Order.Management/InvoiceReport.cs b/Order.Management/InvoiceReport.cs index 2fdacc7..9d24ef6 100644 --- a/Order.Management/InvoiceReport.cs +++ b/Order.Management/InvoiceReport.cs @@ -1,4 +1,5 @@ -using System; +using Order.Management.ToyBlocks; +using System; using System.Collections.Generic; namespace Order.Management diff --git a/Order.Management/Order.cs b/Order.Management/Order.cs index 613093e..ec2b4ea 100644 --- a/Order.Management/Order.cs +++ b/Order.Management/Order.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using Order.Management.ToyBlocks; +using System.Collections.Generic; namespace Order.Management { diff --git a/Order.Management/PaintingReport.cs b/Order.Management/PaintingReport.cs index 80b6532..cb25d73 100644 --- a/Order.Management/PaintingReport.cs +++ b/Order.Management/PaintingReport.cs @@ -1,4 +1,5 @@ -using System; +using Order.Management.ToyBlocks; +using System; using System.Collections.Generic; namespace Order.Management diff --git a/Order.Management/Program.cs b/Order.Management/Program.cs index 4c27a75..6b107cb 100644 --- a/Order.Management/Program.cs +++ b/Order.Management/Program.cs @@ -1,4 +1,5 @@ -using System; +using Order.Management.ToyBlocks; +using System; using System.Collections.Generic; namespace Order.Management diff --git a/Order.Management/Circle.cs b/Order.Management/ToyBlocks/Circle.cs similarity index 95% rename from Order.Management/Circle.cs rename to Order.Management/ToyBlocks/Circle.cs index 3871e4d..b41eb2e 100644 --- a/Order.Management/Circle.cs +++ b/Order.Management/ToyBlocks/Circle.cs @@ -1,4 +1,4 @@ -namespace Order.Management +namespace Order.Management.ToyBlocks { public class Circle : Shape { @@ -23,10 +23,12 @@ 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/Shape.cs b/Order.Management/ToyBlocks/Shape.cs similarity index 93% rename from Order.Management/Shape.cs rename to Order.Management/ToyBlocks/Shape.cs index 3d90013..f067757 100644 --- a/Order.Management/Shape.cs +++ b/Order.Management/ToyBlocks/Shape.cs @@ -1,4 +1,4 @@ -namespace Order.Management +namespace Order.Management.ToyBlocks { public abstract class Shape { @@ -8,6 +8,7 @@ public 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; @@ -17,6 +18,7 @@ public int AdditionalChargeTotal() { return NumberOfRedShape * AdditionalCharge; } + public abstract int Total(); } } diff --git a/Order.Management/Square.cs b/Order.Management/ToyBlocks/Square.cs similarity index 95% rename from Order.Management/Square.cs rename to Order.Management/ToyBlocks/Square.cs index 80b4d1e..c38588c 100644 --- a/Order.Management/Square.cs +++ b/Order.Management/ToyBlocks/Square.cs @@ -1,4 +1,4 @@ -namespace Order.Management +namespace Order.Management.ToyBlocks { public class Square : Shape { @@ -23,10 +23,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/ToyBlocks/Triangle.cs similarity index 96% rename from Order.Management/Triangle.cs rename to Order.Management/ToyBlocks/Triangle.cs index 73bbf6d..5fc8813 100644 --- a/Order.Management/Triangle.cs +++ b/Order.Management/ToyBlocks/Triangle.cs @@ -1,4 +1,4 @@ -namespace Order.Management +namespace Order.Management.ToyBlocks { public class Triangle : Shape { From 15461a7213bfeaa8d1d9addf0b92582a0aab8af1 Mon Sep 17 00:00:00 2001 From: Gerardo Sullivan Date: Tue, 25 May 2021 22:17:52 +1200 Subject: [PATCH 04/10] Move report models to their own folder --- Order.Management/Program.cs | 3 ++- Order.Management/{ => Reports}/CuttingListReport.cs | 2 +- Order.Management/{ => Reports}/InvoiceReport.cs | 2 +- Order.Management/{ => Reports}/PaintingReport.cs | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) rename Order.Management/{ => Reports}/CuttingListReport.cs (98%) rename Order.Management/{ => Reports}/InvoiceReport.cs (99%) rename Order.Management/{ => Reports}/PaintingReport.cs (98%) diff --git a/Order.Management/Program.cs b/Order.Management/Program.cs index 6b107cb..245f349 100644 --- a/Order.Management/Program.cs +++ b/Order.Management/Program.cs @@ -1,4 +1,5 @@ -using Order.Management.ToyBlocks; +using Order.Management.Reports; +using Order.Management.ToyBlocks; using System; using System.Collections.Generic; diff --git a/Order.Management/CuttingListReport.cs b/Order.Management/Reports/CuttingListReport.cs similarity index 98% rename from Order.Management/CuttingListReport.cs rename to Order.Management/Reports/CuttingListReport.cs index b9fa5cf..7abb881 100644 --- a/Order.Management/CuttingListReport.cs +++ b/Order.Management/Reports/CuttingListReport.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; -namespace Order.Management +namespace Order.Management.Reports { public class CuttingListReport : Order { diff --git a/Order.Management/InvoiceReport.cs b/Order.Management/Reports/InvoiceReport.cs similarity index 99% rename from Order.Management/InvoiceReport.cs rename to Order.Management/Reports/InvoiceReport.cs index 9d24ef6..3daef43 100644 --- a/Order.Management/InvoiceReport.cs +++ b/Order.Management/Reports/InvoiceReport.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; -namespace Order.Management +namespace Order.Management.Reports { public class InvoiceReport : Order { diff --git a/Order.Management/PaintingReport.cs b/Order.Management/Reports/PaintingReport.cs similarity index 98% rename from Order.Management/PaintingReport.cs rename to Order.Management/Reports/PaintingReport.cs index cb25d73..98eb10a 100644 --- a/Order.Management/PaintingReport.cs +++ b/Order.Management/Reports/PaintingReport.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; -namespace Order.Management +namespace Order.Management.Reports { public class PaintingReport : Order { From 6a9804fbaa5004d472e8acd9b13409ecb806b785 Mon Sep 17 00:00:00 2001 From: Gerardo Sullivan Date: Tue, 25 May 2021 22:37:50 +1200 Subject: [PATCH 05/10] Abstract customer console input into its own class --- Order.Management/CustomerInputHandler.cs | 97 ++++++++++++++++++++++++ Order.Management/Program.cs | 89 +--------------------- 2 files changed, 101 insertions(+), 85 deletions(-) create mode 100644 Order.Management/CustomerInputHandler.cs diff --git a/Order.Management/CustomerInputHandler.cs b/Order.Management/CustomerInputHandler.cs new file mode 100644 index 0000000..1dc4a5e --- /dev/null +++ b/Order.Management/CustomerInputHandler.cs @@ -0,0 +1,97 @@ +using Order.Management.ToyBlocks; +using System; +using System.Collections.Generic; + +namespace Order.Management +{ + public class CustomerInputHandler + { + // Get customer Info + public (string customerName, string address, string dueDate) GetCustomerInfoInput() + { + Console.Write("Please input your Name: "); + string customerName = GetUserInput(); + + Console.Write("Please input your Address: "); + string address = GetUserInput(); + + Console.Write("Please input your Due Date: "); + string dueDate = GetUserInput(); + + return (customerName, address, dueDate); + } + + public List GetCustomerOrderInput() + { + Square square = OrderSquaresInput(); + Triangle triangle = OrderTrianglesInput(); + Circle circle = OrderCirclesInput(); + + var orderedShapes = new List(); + orderedShapes.Add(square); + orderedShapes.Add(triangle); + orderedShapes.Add(circle); + + return orderedShapes; + } + + private static Circle OrderCirclesInput() + { + Console.Write("\nPlease input the number of Red Circle: "); + int redCircle = Convert.ToInt32(GetUserInput()); + + Console.Write("Please input the number of Blue Circle: "); + int blueCircle = Convert.ToInt32(GetUserInput()); + + Console.Write("Please input the number of Yellow Circle: "); + int yellowCircle = Convert.ToInt32(GetUserInput()); + + Circle circle = new Circle(redCircle, blueCircle, yellowCircle); + + return circle; + } + + private static Square OrderSquaresInput() + { + Console.Write("\nPlease input the number of Red Squares: "); + int redSquare = Convert.ToInt32(GetUserInput()); + + Console.Write("Please input the number of Blue Squares: "); + int blueSquare = Convert.ToInt32(GetUserInput()); + + Console.Write("Please input the number of Yellow Squares: "); + int yellowSquare = Convert.ToInt32(GetUserInput()); + + Square square = new Square(redSquare, blueSquare, yellowSquare); + return square; + } + + private static Triangle OrderTrianglesInput() + { + Console.Write("\nPlease input the number of Red Triangles: "); + int redTriangle = Convert.ToInt32(GetUserInput()); + + Console.Write("Please input the number of Blue Triangles: "); + int blueTriangle = Convert.ToInt32(GetUserInput()); + + Console.Write("Please input the number of Yellow Triangles: "); + int yellowTriangle = Convert.ToInt32(GetUserInput()); + + Triangle triangle = new Triangle(redTriangle, blueTriangle, yellowTriangle); + + return triangle; + } + + private static string GetUserInput() + { + string input = Console.ReadLine(); + while (string.IsNullOrEmpty(input)) + { + Console.WriteLine("please enter valid details"); + input = Console.ReadLine(); + } + + return input; + } + } +} diff --git a/Order.Management/Program.cs b/Order.Management/Program.cs index 245f349..1eec9c1 100644 --- a/Order.Management/Program.cs +++ b/Order.Management/Program.cs @@ -1,18 +1,17 @@ using Order.Management.Reports; using Order.Management.ToyBlocks; -using System; using System.Collections.Generic; namespace Order.Management { - public class Program + public static class Program { // Main entry public static void Main(string[] args) { - var (customerName, address, dueDate) = CustomerInfoInput(); - - var orderedShapes = CustomerOrderInput(); + var customerInput = new CustomerInputHandler(); + var (customerName, address, dueDate) = customerInput.GetCustomerInfoInput(); + var orderedShapes = customerInput.GetCustomerOrderInput(); InvoiceReport(customerName, address, dueDate, orderedShapes); @@ -21,60 +20,6 @@ public 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()); - 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() - { - 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 - public static Triangle OrderTrianglesInput() - { - Console.Write("\nPlease input the number of Red Triangles: "); - 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; - } - - // User Console Input - public static string userInput() - { - string input = Console.ReadLine(); - while (string.IsNullOrEmpty(input)) - { - Console.WriteLine("please enter valid details"); - input = Console.ReadLine(); - } - return input; - } - // Generate Painting Report private static void PaintingReport(string customerName, string address, string dueDate, List orderedShapes) { @@ -95,31 +40,5 @@ private static void InvoiceReport(string customerName, string address, string du InvoiceReport invoiceReport = new InvoiceReport(customerName, address, dueDate, orderedShapes); invoiceReport.GenerateReport(); } - - // Get customer Info - private static (string customerName, string address, string dueDate) CustomerInfoInput() - { - Console.Write("Please input your Name: "); - string customerName = userInput(); - Console.Write("Please input your Address: "); - string address = userInput(); - Console.Write("Please input your Due Date: "); - string dueDate = userInput(); - return (customerName, address, dueDate); - } - - // 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; - } } } From e074d78c8fb909dccba0d06dff36a8a8e3012a12 Mon Sep 17 00:00:00 2001 From: Gerardo Sullivan Date: Tue, 25 May 2021 23:00:06 +1200 Subject: [PATCH 06/10] Remove report inheritance of order Order should be its own concept as part of this application. Reports should be able to just take an order and output the details in a particular way --- Order.Management/Order.cs | 8 ++-- Order.Management/Program.cs | 28 ++++++++------ Order.Management/Reports/CuttingListReport.cs | 24 +++++------- Order.Management/Reports/InvoiceReport.cs | 34 +++++++---------- Order.Management/Reports/PaintingReport.cs | 38 +++++++++++-------- Order.Management/Reports/Report.cs | 14 +++++++ Order.Management/ToyBlocks/Shape.cs | 1 + 7 files changed, 80 insertions(+), 67 deletions(-) create mode 100644 Order.Management/Reports/Report.cs diff --git a/Order.Management/Order.cs b/Order.Management/Order.cs index ec2b4ea..0452080 100644 --- a/Order.Management/Order.cs +++ b/Order.Management/Order.cs @@ -3,15 +3,13 @@ namespace Order.Management { - public 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 abstract void GenerateReport(); + public int OrderNumber => OrderedBlocks?.Count ?? 0; + public List OrderedBlocks { get; set; } = new List(); public override string ToString() { diff --git a/Order.Management/Program.cs b/Order.Management/Program.cs index 1eec9c1..3662ce6 100644 --- a/Order.Management/Program.cs +++ b/Order.Management/Program.cs @@ -1,6 +1,4 @@ using Order.Management.Reports; -using Order.Management.ToyBlocks; -using System.Collections.Generic; namespace Order.Management { @@ -13,31 +11,39 @@ public static void Main(string[] args) var (customerName, address, dueDate) = customerInput.GetCustomerInfoInput(); var orderedShapes = customerInput.GetCustomerOrderInput(); - InvoiceReport(customerName, address, dueDate, orderedShapes); + var order = new Order + { + CustomerName = customerName, + Address = address, + DueDate = dueDate, + OrderedBlocks = orderedShapes + }; - CuttingListReport(customerName, address, dueDate, orderedShapes); + InvoiceReport(order); - PaintingReport(customerName, address, dueDate, orderedShapes); + CuttingListReport(order); + + PaintingReport(order); } // Generate Painting Report - private static void PaintingReport(string customerName, string address, string dueDate, List orderedShapes) + private static void PaintingReport(Order order) { - PaintingReport paintingReport = new PaintingReport(customerName, address, dueDate, orderedShapes); + PaintingReport paintingReport = new PaintingReport(order); paintingReport.GenerateReport(); } // Generate Painting Report - private static void CuttingListReport(string customerName, string address, string dueDate, List orderedShapes) + private static void CuttingListReport(Order order) { - CuttingListReport cuttingListReport = new CuttingListReport(customerName, address, dueDate, orderedShapes); + CuttingListReport cuttingListReport = new CuttingListReport(order); cuttingListReport.GenerateReport(); } // Generate Invoice Report - private static void InvoiceReport(string customerName, string address, string dueDate, List orderedShapes) + private static void InvoiceReport(Order order) { - InvoiceReport invoiceReport = new InvoiceReport(customerName, address, dueDate, orderedShapes); + InvoiceReport invoiceReport = new InvoiceReport(order); invoiceReport.GenerateReport(); } } diff --git a/Order.Management/Reports/CuttingListReport.cs b/Order.Management/Reports/CuttingListReport.cs index 7abb881..8cce2b0 100644 --- a/Order.Management/Reports/CuttingListReport.cs +++ b/Order.Management/Reports/CuttingListReport.cs @@ -1,35 +1,29 @@ -using Order.Management.ToyBlocks; -using System; -using System.Collections.Generic; +using System; namespace Order.Management.Reports { - public class CuttingListReport : Order + public class CuttingListReport : Report { public int tableWidth = 20; - public CuttingListReport(string customerName, string customerAddress, string dueDate, List shapes) + public CuttingListReport(Order order) : base(order) { - 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(); + Console.WriteLine(Order.ToString()); + GenerateTable(); } - public void 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()); + PrintRow("Square", Order.OrderedBlocks[0].TotalQuantityOfShape().ToString()); + PrintRow("Triangle", Order.OrderedBlocks[1].TotalQuantityOfShape().ToString()); + PrintRow("Circle", Order.OrderedBlocks[2].TotalQuantityOfShape().ToString()); PrintLine(); } public void PrintLine() diff --git a/Order.Management/Reports/InvoiceReport.cs b/Order.Management/Reports/InvoiceReport.cs index 3daef43..e5a41e7 100644 --- a/Order.Management/Reports/InvoiceReport.cs +++ b/Order.Management/Reports/InvoiceReport.cs @@ -1,25 +1,19 @@ -using Order.Management.ToyBlocks; -using System; -using System.Collections.Generic; +using System; namespace Order.Management.Reports { - public class InvoiceReport : Order + public class InvoiceReport : Report { public int tableWidth = 73; - public InvoiceReport(string customerName, string customerAddress, string dueDate, List shapes) + public InvoiceReport(Order order) : base(order) { - 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()); + Console.WriteLine(Order.ToString()); GenerateTable(); OrderSquareDetails(); OrderTriangleDetails(); @@ -29,40 +23,40 @@ public override void GenerateReport() public void RedPaintSurcharge() { - Console.WriteLine("Red Color Surcharge " + TotalAmountOfRedShapes() + " @ $" + base.OrderedBlocks[0].AdditionalCharge + " ppi = $" + TotalPriceRedPaintSurcharge()); + Console.WriteLine("Red Color Surcharge " + TotalAmountOfRedShapes() + " @ $" + Order.OrderedBlocks[0].AdditionalCharge + " ppi = $" + TotalPriceRedPaintSurcharge()); } public int TotalAmountOfRedShapes() { - return base.OrderedBlocks[0].NumberOfRedShape + base.OrderedBlocks[1].NumberOfRedShape + - base.OrderedBlocks[2].NumberOfRedShape; + return Order.OrderedBlocks[0].NumberOfRedShape + Order.OrderedBlocks[1].NumberOfRedShape + + Order.OrderedBlocks[2].NumberOfRedShape; } public int TotalPriceRedPaintSurcharge() { - return TotalAmountOfRedShapes() * base.OrderedBlocks[0].AdditionalCharge; + return TotalAmountOfRedShapes() * Order.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()); + PrintRow("Square", Order.OrderedBlocks[0].NumberOfRedShape.ToString(), Order.OrderedBlocks[0].NumberOfBlueShape.ToString(), Order.OrderedBlocks[0].NumberOfYellowShape.ToString()); + PrintRow("Triangle", Order.OrderedBlocks[1].NumberOfRedShape.ToString(), Order.OrderedBlocks[1].NumberOfBlueShape.ToString(), Order.OrderedBlocks[1].NumberOfYellowShape.ToString()); + PrintRow("Circle", Order.OrderedBlocks[2].NumberOfRedShape.ToString(), Order.OrderedBlocks[2].NumberOfBlueShape.ToString(), Order.OrderedBlocks[2].NumberOfYellowShape.ToString()); PrintLine(); } public void OrderSquareDetails() { - Console.WriteLine("\nSquares " + base.OrderedBlocks[0].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[0].Price + " ppi = $" + base.OrderedBlocks[0].Total()); + Console.WriteLine("\nSquares " + Order.OrderedBlocks[0].TotalQuantityOfShape() + " @ $" + Order.OrderedBlocks[0].Price + " ppi = $" + Order.OrderedBlocks[0].Total()); } public void OrderTriangleDetails() { - Console.WriteLine("Triangles " + base.OrderedBlocks[1].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[1].Price + " ppi = $" + base.OrderedBlocks[1].Total()); + Console.WriteLine("Triangles " + Order.OrderedBlocks[1].TotalQuantityOfShape() + " @ $" + Order.OrderedBlocks[1].Price + " ppi = $" + Order.OrderedBlocks[1].Total()); } public void OrderCircleDetails() { - Console.WriteLine("Circles " + base.OrderedBlocks[2].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[2].Price + " ppi = $" + base.OrderedBlocks[2].Total()); + Console.WriteLine("Circles " + Order.OrderedBlocks[2].TotalQuantityOfShape() + " @ $" + Order.OrderedBlocks[2].Price + " ppi = $" + Order.OrderedBlocks[2].Total()); } public void PrintLine() { diff --git a/Order.Management/Reports/PaintingReport.cs b/Order.Management/Reports/PaintingReport.cs index 98eb10a..441aa82 100644 --- a/Order.Management/Reports/PaintingReport.cs +++ b/Order.Management/Reports/PaintingReport.cs @@ -1,25 +1,19 @@ -using Order.Management.ToyBlocks; -using System; -using System.Collections.Generic; +using System; namespace Order.Management.Reports { - public class PaintingReport : Order + public class PaintingReport : Report { - public int tableWidth = 73; + public const int TABLE_WIDTH = 73; - public PaintingReport(string customerName, string customerAddress, string dueDate, List shapes) + public PaintingReport(Order order) : base(order) { - base.CustomerName = customerName; - base.Address = customerAddress; - base.DueDate = dueDate; - base.OrderedBlocks = shapes; } public override void GenerateReport() { Console.WriteLine("\nYour painting report has been generated: "); - Console.WriteLine(base.ToString()); + Console.WriteLine(Order.ToString()); GenerateTable(); } @@ -28,20 +22,32 @@ 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()); + PrintRow( + "Square", + Order.OrderedBlocks[0].NumberOfRedShape.ToString(), + Order.OrderedBlocks[0].NumberOfBlueShape.ToString(), + Order.OrderedBlocks[0].NumberOfYellowShape.ToString()); + PrintRow( + "Triangle", + Order.OrderedBlocks[1].NumberOfRedShape.ToString(), + Order.OrderedBlocks[1].NumberOfBlueShape.ToString(), + Order.OrderedBlocks[1].NumberOfYellowShape.ToString()); + PrintRow( + "Circle", + Order.OrderedBlocks[2].NumberOfRedShape.ToString(), + Order.OrderedBlocks[2].NumberOfBlueShape.ToString(), + Order.OrderedBlocks[2].NumberOfYellowShape.ToString()); PrintLine(); } public void PrintLine() { - Console.WriteLine(new string('-', tableWidth)); + Console.WriteLine(new string('-', TABLE_WIDTH)); } public void PrintRow(params string[] columns) { - int width = (tableWidth - columns.Length) / columns.Length; + int width = (TABLE_WIDTH - columns.Length) / columns.Length; string row = "|"; foreach (string column in columns) diff --git a/Order.Management/Reports/Report.cs b/Order.Management/Reports/Report.cs new file mode 100644 index 0000000..fe073ff --- /dev/null +++ b/Order.Management/Reports/Report.cs @@ -0,0 +1,14 @@ +namespace Order.Management.Reports +{ + public abstract class Report + { + public Order Order { get; } + + public Report(Order order) + { + Order = order; + } + + public abstract void GenerateReport(); + } +} diff --git a/Order.Management/ToyBlocks/Shape.cs b/Order.Management/ToyBlocks/Shape.cs index f067757..55f4633 100644 --- a/Order.Management/ToyBlocks/Shape.cs +++ b/Order.Management/ToyBlocks/Shape.cs @@ -1,5 +1,6 @@ namespace Order.Management.ToyBlocks { + // TODO: rename this to Block public abstract class Shape { public string Name { get; set; } From 3aa29328cdf0a6d93064b61daa54b3a26b51e3a3 Mon Sep 17 00:00:00 2001 From: Gerardo Sullivan Date: Tue, 25 May 2021 23:12:10 +1200 Subject: [PATCH 07/10] Add user validation of integers so application doesnt blow up --- Order.Management/CustomerInputHandler.cs | 43 +++++++++++++++--------- Order.Management/Order.cs | 2 +- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Order.Management/CustomerInputHandler.cs b/Order.Management/CustomerInputHandler.cs index 1dc4a5e..a547665 100644 --- a/Order.Management/CustomerInputHandler.cs +++ b/Order.Management/CustomerInputHandler.cs @@ -10,13 +10,13 @@ public class CustomerInputHandler public (string customerName, string address, string dueDate) GetCustomerInfoInput() { Console.Write("Please input your Name: "); - string customerName = GetUserInput(); + string customerName = GetUserInputAsString(); Console.Write("Please input your Address: "); - string address = GetUserInput(); + string address = GetUserInputAsString(); - Console.Write("Please input your Due Date: "); - string dueDate = GetUserInput(); + Console.Write("Please input your Due Date: "); // TODO: should probably be DateTime with valid user input for DateTime + string dueDate = GetUserInputAsString(); return (customerName, address, dueDate); } @@ -38,13 +38,13 @@ public List GetCustomerOrderInput() private static Circle OrderCirclesInput() { Console.Write("\nPlease input the number of Red Circle: "); - int redCircle = Convert.ToInt32(GetUserInput()); + int redCircle = GetUserInputAsInt(); Console.Write("Please input the number of Blue Circle: "); - int blueCircle = Convert.ToInt32(GetUserInput()); + int blueCircle = GetUserInputAsInt(); Console.Write("Please input the number of Yellow Circle: "); - int yellowCircle = Convert.ToInt32(GetUserInput()); + int yellowCircle = GetUserInputAsInt(); Circle circle = new Circle(redCircle, blueCircle, yellowCircle); @@ -54,13 +54,13 @@ private static Circle OrderCirclesInput() private static Square OrderSquaresInput() { Console.Write("\nPlease input the number of Red Squares: "); - int redSquare = Convert.ToInt32(GetUserInput()); + int redSquare = GetUserInputAsInt(); Console.Write("Please input the number of Blue Squares: "); - int blueSquare = Convert.ToInt32(GetUserInput()); + int blueSquare = GetUserInputAsInt(); Console.Write("Please input the number of Yellow Squares: "); - int yellowSquare = Convert.ToInt32(GetUserInput()); + int yellowSquare = GetUserInputAsInt(); Square square = new Square(redSquare, blueSquare, yellowSquare); return square; @@ -69,22 +69,22 @@ private static Square OrderSquaresInput() private static Triangle OrderTrianglesInput() { Console.Write("\nPlease input the number of Red Triangles: "); - int redTriangle = Convert.ToInt32(GetUserInput()); + int redTriangle = GetUserInputAsInt(); Console.Write("Please input the number of Blue Triangles: "); - int blueTriangle = Convert.ToInt32(GetUserInput()); + int blueTriangle = GetUserInputAsInt(); Console.Write("Please input the number of Yellow Triangles: "); - int yellowTriangle = Convert.ToInt32(GetUserInput()); + int yellowTriangle = GetUserInputAsInt(); Triangle triangle = new Triangle(redTriangle, blueTriangle, yellowTriangle); return triangle; } - private static string GetUserInput() + private static string GetUserInputAsString() { - string input = Console.ReadLine(); + string input = Console.ReadLine().Trim(); while (string.IsNullOrEmpty(input)) { Console.WriteLine("please enter valid details"); @@ -93,5 +93,18 @@ private static string GetUserInput() return input; } + + private static int GetUserInputAsInt() + { + string input = GetUserInputAsString(); + + while (!int.TryParse(input, out var _)) + { + Console.WriteLine("please enter valid details"); + input = GetUserInputAsString(); + } + + return int.Parse(input); + } } } diff --git a/Order.Management/Order.cs b/Order.Management/Order.cs index 0452080..2490e40 100644 --- a/Order.Management/Order.cs +++ b/Order.Management/Order.cs @@ -7,7 +7,7 @@ public class Order { public string CustomerName { get; set; } public string Address { get; set; } - public string DueDate { get; set; } + public string DueDate { get; set; } // TODO: should probably be DateTime public int OrderNumber => OrderedBlocks?.Count ?? 0; public List OrderedBlocks { get; set; } = new List(); From 6e771ad9ba45ab9d522ccdf5a6354bce4a9494ea Mon Sep 17 00:00:00 2001 From: Gerardo Sullivan Date: Tue, 25 May 2021 23:27:21 +1200 Subject: [PATCH 08/10] Revert OrderNumber change TODO: need to think of some auto generator for Order Number --- Order.Management/Order.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Order.Management/Order.cs b/Order.Management/Order.cs index 2490e40..539dd0b 100644 --- a/Order.Management/Order.cs +++ b/Order.Management/Order.cs @@ -8,7 +8,7 @@ public class Order public string CustomerName { get; set; } public string Address { get; set; } public string DueDate { get; set; } // TODO: should probably be DateTime - public int OrderNumber => OrderedBlocks?.Count ?? 0; + public int OrderNumber { get; set; } public List OrderedBlocks { get; set; } = new List(); public override string ToString() From 4c77acb1f0e70fc3f67563759d437ac8c3d7e198 Mon Sep 17 00:00:00 2001 From: Gerardo Sullivan Date: Tue, 25 May 2021 23:27:54 +1200 Subject: [PATCH 09/10] Abstract some user input functionality Handle ints better, reuse code --- Order.Management/CustomerInputHandler.cs | 63 +++++++++++------------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/Order.Management/CustomerInputHandler.cs b/Order.Management/CustomerInputHandler.cs index a547665..59f8167 100644 --- a/Order.Management/CustomerInputHandler.cs +++ b/Order.Management/CustomerInputHandler.cs @@ -9,14 +9,12 @@ public class CustomerInputHandler // Get customer Info public (string customerName, string address, string dueDate) GetCustomerInfoInput() { - Console.Write("Please input your Name: "); - string customerName = GetUserInputAsString(); + string customerName = GetUserInputAsString("Please input your Name: "); - Console.Write("Please input your Address: "); - string address = GetUserInputAsString(); + string address = GetUserInputAsString("Please input your Address: "); - Console.Write("Please input your Due Date: "); // TODO: should probably be DateTime with valid user input for DateTime - string dueDate = GetUserInputAsString(); + // TODO: should probably be DateTime with valid user input for DateTime + string dueDate = GetUserInputAsString("Please input your Due Date: "); return (customerName, address, dueDate); } @@ -37,14 +35,10 @@ public List GetCustomerOrderInput() private static Circle OrderCirclesInput() { - Console.Write("\nPlease input the number of Red Circle: "); - int redCircle = GetUserInputAsInt(); - - Console.Write("Please input the number of Blue Circle: "); - int blueCircle = GetUserInputAsInt(); - - Console.Write("Please input the number of Yellow Circle: "); - int yellowCircle = GetUserInputAsInt(); + Console.WriteLine(); + int redCircle = GetUserInputAsInt("Please input the number of Red Circle: "); + int blueCircle = GetUserInputAsInt("Please input the number of Blue Circle: "); + int yellowCircle = GetUserInputAsInt("Please input the number of Yellow Circle: "); Circle circle = new Circle(redCircle, blueCircle, yellowCircle); @@ -53,14 +47,10 @@ private static Circle OrderCirclesInput() private static Square OrderSquaresInput() { - Console.Write("\nPlease input the number of Red Squares: "); - int redSquare = GetUserInputAsInt(); - - Console.Write("Please input the number of Blue Squares: "); - int blueSquare = GetUserInputAsInt(); - - Console.Write("Please input the number of Yellow Squares: "); - int yellowSquare = GetUserInputAsInt(); + Console.WriteLine(); + int redSquare = GetUserInputAsInt("Please input the number of Red Squares: "); + int blueSquare = GetUserInputAsInt("Please input the number of Blue Squares: "); + int yellowSquare = GetUserInputAsInt("Please input the number of Yellow Squares: "); Square square = new Square(redSquare, blueSquare, yellowSquare); return square; @@ -68,40 +58,45 @@ private static Square OrderSquaresInput() private static Triangle OrderTrianglesInput() { - Console.Write("\nPlease input the number of Red Triangles: "); - int redTriangle = GetUserInputAsInt(); - - Console.Write("Please input the number of Blue Triangles: "); - int blueTriangle = GetUserInputAsInt(); - - Console.Write("Please input the number of Yellow Triangles: "); - int yellowTriangle = GetUserInputAsInt(); + Console.WriteLine(); + int redTriangle = GetUserInputAsInt("Please input the number of Red Triangles: "); + int blueTriangle = GetUserInputAsInt("Please input the number of Blue Triangles: "); + int yellowTriangle = GetUserInputAsInt("Please input the number of Yellow Triangles: "); Triangle triangle = new Triangle(redTriangle, blueTriangle, yellowTriangle); return triangle; } - private static string GetUserInputAsString() + private static string GetUserInputAsString(string message) { + if (string.IsNullOrWhiteSpace(message)) + { + throw new ArgumentNullException(nameof(message)); + } + + Console.Write(message); + + // Get user input string input = Console.ReadLine().Trim(); while (string.IsNullOrEmpty(input)) { Console.WriteLine("please enter valid details"); + Console.Write(message); input = Console.ReadLine(); } return input; } - private static int GetUserInputAsInt() + private static int GetUserInputAsInt(string message) //TODO: example had ints being nullable from input { - string input = GetUserInputAsString(); + string input = GetUserInputAsString(message); while (!int.TryParse(input, out var _)) { Console.WriteLine("please enter valid details"); - input = GetUserInputAsString(); + input = GetUserInputAsString(message); } return int.Parse(input); From 5682c54b4f6d074369defb065959aa7231e8b835 Mon Sep 17 00:00:00 2001 From: Gerardo Sullivan Date: Wed, 26 May 2021 08:38:37 +1200 Subject: [PATCH 10/10] Abstract away some report methods --- Order.Management/Reports/CuttingListReport.cs | 36 ++-------------- Order.Management/Reports/InvoiceReport.cs | 35 +--------------- Order.Management/Reports/PaintingReport.cs | 36 +--------------- Order.Management/Reports/Report.cs | 41 ++++++++++++++++++- 4 files changed, 46 insertions(+), 102 deletions(-) diff --git a/Order.Management/Reports/CuttingListReport.cs b/Order.Management/Reports/CuttingListReport.cs index 8cce2b0..58b44fa 100644 --- a/Order.Management/Reports/CuttingListReport.cs +++ b/Order.Management/Reports/CuttingListReport.cs @@ -4,9 +4,9 @@ namespace Order.Management.Reports { public class CuttingListReport : Report { - public int tableWidth = 20; + private const int TABLE_WIDTH = 20; - public CuttingListReport(Order order) : base(order) + public CuttingListReport(Order order) : base(order, TABLE_WIDTH) { } @@ -16,6 +16,7 @@ public override void GenerateReport() Console.WriteLine(Order.ToString()); GenerateTable(); } + public void GenerateTable() { PrintLine(); @@ -26,36 +27,5 @@ public void GenerateTable() PrintRow("Circle", Order.OrderedBlocks[2].TotalQuantityOfShape().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); - } - } } } diff --git a/Order.Management/Reports/InvoiceReport.cs b/Order.Management/Reports/InvoiceReport.cs index e5a41e7..66a1e51 100644 --- a/Order.Management/Reports/InvoiceReport.cs +++ b/Order.Management/Reports/InvoiceReport.cs @@ -4,9 +4,9 @@ namespace Order.Management.Reports { public class InvoiceReport : Report { - public int tableWidth = 73; + private const int TABLE_WIDTH = 73; - public InvoiceReport(Order order) : base(order) + public InvoiceReport(Order order) : base(order, TABLE_WIDTH) { } @@ -58,36 +58,5 @@ public void OrderCircleDetails() { Console.WriteLine("Circles " + Order.OrderedBlocks[2].TotalQuantityOfShape() + " @ $" + Order.OrderedBlocks[2].Price + " ppi = $" + Order.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) - { - 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/Reports/PaintingReport.cs b/Order.Management/Reports/PaintingReport.cs index 441aa82..bd6d987 100644 --- a/Order.Management/Reports/PaintingReport.cs +++ b/Order.Management/Reports/PaintingReport.cs @@ -4,9 +4,9 @@ namespace Order.Management.Reports { public class PaintingReport : Report { - public const int TABLE_WIDTH = 73; + private const int TABLE_WIDTH = 73; - public PaintingReport(Order order) : base(order) + public PaintingReport(Order order) : base(order, TABLE_WIDTH) { } @@ -39,37 +39,5 @@ public void GenerateTable() Order.OrderedBlocks[2].NumberOfYellowShape.ToString()); PrintLine(); } - - public void PrintLine() - { - Console.WriteLine(new string('-', TABLE_WIDTH)); - } - - public void PrintRow(params string[] columns) - { - int width = (TABLE_WIDTH - 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/Reports/Report.cs b/Order.Management/Reports/Report.cs index fe073ff..6d054e4 100644 --- a/Order.Management/Reports/Report.cs +++ b/Order.Management/Reports/Report.cs @@ -1,14 +1,51 @@ -namespace Order.Management.Reports +using System; + +namespace Order.Management.Reports { public abstract class Report { + public int TableWidth { get; } + public Order Order { get; } - public Report(Order order) + public Report(Order order, int tableWidth) { Order = order; + TableWidth = tableWidth; } public abstract void GenerateReport(); + + 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); + } + } } }