From 39cd30d86ac3e969e73debe45033f454bb4fe558 Mon Sep 17 00:00:00 2001 From: cxprofile Date: Thu, 11 Feb 2021 12:31:35 +1300 Subject: [PATCH 1/2] initial commit for commenting on code review - could not create pull request so I forked on my repo --- Order.Management/Circle.cs | 2 +- Order.Management/CuttingListReport.cs | 6 ++-- Order.Management/InvoiceReport.cs | 2 +- Order.Management/Order.Management.csproj | 2 +- Order.Management/Order.cs | 5 +-- Order.Management/PaintingReport.cs | 8 +++-- Order.Management/Program.cs | 39 +++++++++++++----------- Order.Management/Shape.cs | 7 +++++ Order.Management/Square.cs | 2 ++ Order.Management/Triangle.cs | 3 ++ 10 files changed, 46 insertions(+), 30 deletions(-) diff --git a/Order.Management/Circle.cs b/Order.Management/Circle.cs index 9824ecc..08f8aa2 100644 --- a/Order.Management/Circle.cs +++ b/Order.Management/Circle.cs @@ -10,7 +10,7 @@ class Circle : Shape public Circle(int red, int blue, int yellow) { Name = "Circle"; - base.Price = circlePrice; + Price = circlePrice; AdditionalCharge = 1; base.NumberOfRedShape = red; base.NumberOfBlueShape = blue; diff --git a/Order.Management/CuttingListReport.cs b/Order.Management/CuttingListReport.cs index 125d45f..a25ba63 100644 --- a/Order.Management/CuttingListReport.cs +++ b/Order.Management/CuttingListReport.cs @@ -9,7 +9,7 @@ class CuttingListReport : Order public int tableWidth = 20; public CuttingListReport(string customerName, string customerAddress, string dueDate, List shapes) { - base.CustomerName = customerName; + CustomerName = customerName; base.Address = customerAddress; base.DueDate = dueDate; base.OrderedBlocks = shapes; @@ -19,9 +19,9 @@ public override void GenerateReport() { Console.WriteLine("\nYour cutting list has been generated: "); Console.WriteLine(base.ToString()); - generateTable(); + GenerateTable(); } - public void generateTable() + public void GenerateTable() { PrintLine(); PrintRow(" ", " Qty "); diff --git a/Order.Management/InvoiceReport.cs b/Order.Management/InvoiceReport.cs index 78443c3..f29ca24 100644 --- a/Order.Management/InvoiceReport.cs +++ b/Order.Management/InvoiceReport.cs @@ -33,7 +33,7 @@ public void RedPaintSurcharge() public int TotalAmountOfRedShapes() { - return base.OrderedBlocks[0].NumberOfRedShape + base.OrderedBlocks[1].NumberOfRedShape + + return OrderedBlocks[0].NumberOfRedShape + base.OrderedBlocks[1].NumberOfRedShape + base.OrderedBlocks[2].NumberOfRedShape; } diff --git a/Order.Management/Order.Management.csproj b/Order.Management/Order.Management.csproj index 958d2f1..c73e0d1 100644 --- a/Order.Management/Order.Management.csproj +++ b/Order.Management/Order.Management.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.0 + netcoreapp3.1 diff --git a/Order.Management/Order.cs b/Order.Management/Order.cs index 235c789..90f7cb7 100644 --- a/Order.Management/Order.cs +++ b/Order.Management/Order.cs @@ -14,9 +14,6 @@ abstract class Order public abstract void GenerateReport(); - public string ToString() - { - return "\nName: " + CustomerName + " Address: " + Address + " Due Date: " + DueDate + " Order #: " + OrderNumber; - } + public override string ToString() => "\nName: " + CustomerName + " Address: " + Address + " Due Date: " + DueDate + " Order #: " + OrderNumber; } } diff --git a/Order.Management/PaintingReport.cs b/Order.Management/PaintingReport.cs index 9b61c83..d56f34d 100644 --- a/Order.Management/PaintingReport.cs +++ b/Order.Management/PaintingReport.cs @@ -7,21 +7,23 @@ namespace Order.Management class PaintingReport : Order { public int tableWidth = 73; + public PaintingReport(string customerName, string customerAddress, string dueDate, List shapes) { - base.CustomerName = customerName; + 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()); - generateTable(); + GenerateTable(); } - public void generateTable() + public void GenerateTable() { PrintLine(); PrintRow(" ", " Red ", " Blue ", " Yellow "); diff --git a/Order.Management/Program.cs b/Order.Management/Program.cs index 1422f85..b74fff8 100644 --- a/Order.Management/Program.cs +++ b/Order.Management/Program.cs @@ -5,7 +5,9 @@ namespace Order.Management { class Program { + // Main entry + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "")] static void Main(string[] args) { var (customerName, address, dueDate) = CustomerInfoInput(); @@ -23,11 +25,11 @@ static void Main(string[] args) 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 +39,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,18 +53,18 @@ public static Square OrderSquaresInput() public static Triangle OrderTrianglesInput() { Console.Write("\nPlease input the number of Red Triangles: "); - int redTriangle = Convert.ToInt32(userInput()); + int redTriangle = 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)) @@ -99,11 +101,11 @@ private static void InvoiceReport(string customerName, string address, string du private static (string customerName, string address, string dueDate) CustomerInfoInput() { Console.Write("Please input your Name: "); - string customerName = userInput(); + string customerName = UserInput(); Console.Write("Please input your Address: "); - string address = userInput(); + string address = UserInput(); Console.Write("Please input your Due Date: "); - string dueDate = userInput(); + string dueDate = UserInput(); return (customerName, address, dueDate); } @@ -114,10 +116,13 @@ private static List CustomerOrderInput() Triangle triangle = OrderTrianglesInput(); Circle circle = OrderCirclesInput(); - var orderedShapes = new List(); - orderedShapes.Add(square); - orderedShapes.Add(triangle); - orderedShapes.Add(circle); + var orderedShapes = new List + { + square, + triangle, + circle + }; + return orderedShapes; } } diff --git a/Order.Management/Shape.cs b/Order.Management/Shape.cs index 7f5c61c..b86e63c 100644 --- a/Order.Management/Shape.cs +++ b/Order.Management/Shape.cs @@ -7,11 +7,17 @@ namespace Order.Management abstract class Shape { public string Name { get; set; } + public int Price { get; set; } + public int AdditionalCharge { get; set; } + public int NumberOfRedShape { get; set; } + public int NumberOfBlueShape { get; set; } + public int NumberOfYellowShape { get; set; } + public int TotalQuantityOfShape() { return NumberOfRedShape + NumberOfBlueShape + NumberOfYellowShape; @@ -21,6 +27,7 @@ public int AdditionalChargeTotal() { return NumberOfRedShape * AdditionalCharge; } + public abstract int Total(); } diff --git a/Order.Management/Square.cs b/Order.Management/Square.cs index 017601e..0a701ac 100644 --- a/Order.Management/Square.cs +++ b/Order.Management/Square.cs @@ -28,10 +28,12 @@ public int RedSquaresTotal() { return (base.NumberOfRedShape * Price); } + public int BlueSquaresTotal() { return (base.NumberOfBlueShape * Price); } + public int YellowSquaresTotal() { return (base.NumberOfYellowShape * Price); diff --git a/Order.Management/Triangle.cs b/Order.Management/Triangle.cs index dbf48ff..2bdf241 100644 --- a/Order.Management/Triangle.cs +++ b/Order.Management/Triangle.cs @@ -7,6 +7,7 @@ namespace Order.Management class Triangle : Shape { public int TrianglePrice = 2; + public Triangle(int numberOfRedTriangles, int numberOfBlueTriangles, int numberOfYellowTriangles) { Name = "Triangle"; @@ -26,10 +27,12 @@ public int RedTrianglesTotal() { return (base.NumberOfRedShape * Price); } + public int BlueTrianglesTotal() { return (base.NumberOfBlueShape * Price); } + public int YellowTrianglesTotal() { return (base.NumberOfYellowShape * Price); From 83940d82223cf61bc4c4e7b12ad2394d61f169d4 Mon Sep 17 00:00:00 2001 From: cxprofile Date: Thu, 11 Feb 2021 13:38:08 +1300 Subject: [PATCH 2/2] code fixes relating to code review done on tag 39cd30d8 --- Order.Management/.editorconfig | 117 +++++++++++++++++++++++ Order.Management/Circle.cs | 37 +++---- Order.Management/CuttingListReport.cs | 56 +++-------- Order.Management/IReport.cs | 26 +++++ Order.Management/InvoiceReport.cs | 97 ++++--------------- Order.Management/Order.Management.csproj | 9 ++ Order.Management/Order.cs | 54 ++++++++++- Order.Management/PaintingReport.cs | 57 ++--------- Order.Management/Program.cs | 112 +++++++++++++++++----- Order.Management/Shape.cs | 19 +--- Order.Management/Square.cs | 34 ++----- Order.Management/Triangle.cs | 37 ++----- 12 files changed, 365 insertions(+), 290 deletions(-) create mode 100644 Order.Management/.editorconfig create mode 100644 Order.Management/IReport.cs diff --git a/Order.Management/.editorconfig b/Order.Management/.editorconfig new file mode 100644 index 0000000..f62b197 --- /dev/null +++ b/Order.Management/.editorconfig @@ -0,0 +1,117 @@ +# Rules in this file were initially inferred by Visual Studio IntelliCode from the D:\source\Serko\OrderManagement\OrderManagement\Order.Management\ codebase based on best match to current usage at 11/02/2021 +# You can modify the rules from these initially generated values to suit your own policies +# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference +[*.cs] + + +#Core editorconfig formatting - indentation + +#use soft tabs (spaces) for indentation +indent_style = space + +#Formatting - indentation options +# Indentation and spacing +indent_size = 4 +indent_style = space +tab_width = 4 + +# New line preferences +end_of_line = crlf +insert_final_newline = false + + +#indent switch case contents. +csharp_indent_case_contents = true +#indent switch labels +csharp_indent_switch_labels = true + +#Formatting - new line options + +#require members of object intializers to be on separate lines +csharp_new_line_before_members_in_object_initializers = true +#require braces to be on a new line for properties, accessors, methods, control_blocks, and types (also known as "Allman" style) +csharp_new_line_before_open_brace = properties, accessors, methods, control_blocks, types + +#Formatting - organize using options + +#sort System.* using directives alphabetically, and place them before other usings +dotnet_sort_system_directives_first = true + +#Formatting - spacing options + +#require a space before the colon for bases or interfaces in a type declaration +csharp_space_after_colon_in_inheritance_clause = true +#require a space after a keyword in a control flow statement such as a for loop +csharp_space_after_keywords_in_control_flow_statements = true +#require a space before the colon for bases or interfaces in a type declaration +csharp_space_before_colon_in_inheritance_clause = true +#remove space within empty argument list parentheses +csharp_space_between_method_call_empty_parameter_list_parentheses = false +#remove space between method call name and opening parenthesis +csharp_space_between_method_call_name_and_opening_parenthesis = false +#do not place space characters after the opening parenthesis and before the closing parenthesis of a method call +csharp_space_between_method_call_parameter_list_parentheses = false +#remove space within empty parameter list parentheses for a method declaration +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +#place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list. +csharp_space_between_method_declaration_parameter_list_parentheses = false + +#Formatting - wrapping options + +#leave code block on single line +csharp_preserve_single_line_blocks = true + +#Style - Code block preferences + +#prefer curly braces even for one line of code +csharp_prefer_braces = true:suggestion + +#Style - expression bodied member options + +#prefer expression-bodied members for methods +csharp_style_expression_bodied_methods = true:suggestion +#prefer expression-bodied members for properties +csharp_style_expression_bodied_properties = true:suggestion + +#Style - expression level options + +#prefer the language keyword for member access expressions, instead of the type name, for types that have a keyword to represent them +dotnet_style_predefined_type_for_member_access = true:suggestion + +#Style - Expression-level preferences + +#prefer inferred tuple element names +dotnet_style_prefer_inferred_tuple_names = true:suggestion + +#Style - implicit and explicit types + +#prefer explicit type over var in all cases, unless overridden by another code style rule +csharp_style_var_elsewhere = false:suggestion +#prefer explicit type over var to declare variables with built-in system types such as int +csharp_style_var_for_built_in_types = false:suggestion +#prefer explicit type over var when the type is already mentioned on the right-hand side of a declaration +csharp_style_var_when_type_is_apparent = false:suggestion + +#Style - language keyword and framework type options + +#prefer the language keyword for local variables, method parameters, and class members, instead of the type name, for types that have a keyword to represent them +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion + +#Style - modifier options + +#prefer accessibility modifiers to be specified +dotnet_style_require_accessibility_modifiers = always:suggestion + +#Style - Modifier preferences + +#when this rule is set to a list of modifiers, prefer the specified ordering. +csharp_preferred_modifier_order = public,private,protected,static,override,abstract,virtual:suggestion + +#Style - qualification options + +#prefer fields not to be prefaced with this. or Me. in Visual Basic +dotnet_style_qualification_for_field = false:suggestion +#prefer methods not to be prefaced with this. or Me. in Visual Basic +dotnet_style_qualification_for_method = false:suggestion +#prefer properties not to be prefaced with this. or Me. in Visual Basic +dotnet_style_qualification_for_property = false:suggestion diff --git a/Order.Management/Circle.cs b/Order.Management/Circle.cs index 08f8aa2..6c53595 100644 --- a/Order.Management/Circle.cs +++ b/Order.Management/Circle.cs @@ -1,37 +1,26 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Order.Management +namespace Order.Management { class Circle : Shape { public int circlePrice = 3; + public Circle(int red, int blue, int yellow) { Name = "Circle"; Price = circlePrice; AdditionalCharge = 1; - base.NumberOfRedShape = red; - base.NumberOfBlueShape = blue; - base.NumberOfYellowShape = yellow; - } - public override int Total() - { - return RedCirclesTotal() + BlueCirclesTotal() + YellowCirclesTotal(); + NumberOfRedShape = red; + NumberOfBlueShape = blue; + NumberOfYellowShape = yellow; } - public int RedCirclesTotal() - { - return (base.NumberOfRedShape * Price); - } - public int BlueCirclesTotal() - { - return (base.NumberOfBlueShape * Price); - } - public int YellowCirclesTotal() - { - return (base.NumberOfYellowShape * Price); - } + public override int Total => RedCirclesTotal+ BlueCirclesTotal+ YellowCirclesTotal; + + public int RedCirclesTotal => (NumberOfRedShape * Price); + + public int BlueCirclesTotal => (NumberOfBlueShape * Price); + + public int YellowCirclesTotal => (NumberOfYellowShape * Price); + } } diff --git a/Order.Management/CuttingListReport.cs b/Order.Management/CuttingListReport.cs index a25ba63..46691c8 100644 --- a/Order.Management/CuttingListReport.cs +++ b/Order.Management/CuttingListReport.cs @@ -1,68 +1,36 @@ using System; using System.Collections.Generic; -using System.Text; namespace Order.Management { class CuttingListReport : Order { - public int tableWidth = 20; - public CuttingListReport(string customerName, string customerAddress, string dueDate, List shapes) + public CuttingListReport(string customerName, string customerAddress, string dueDate, List shapes) : base(customerName, customerAddress, dueDate, shapes) { + tableWidth = 20; + OrderNumber += 1; CustomerName = customerName; - base.Address = customerAddress; - base.DueDate = dueDate; - base.OrderedBlocks = shapes; + Address = customerAddress; + DueDate = dueDate; + OrderedBlocks = shapes; } public override void GenerateReport() { Console.WriteLine("\nYour cutting list has been generated: "); - Console.WriteLine(base.ToString()); + Console.WriteLine(ToString()); GenerateTable(); } - public void GenerateTable() + + public override void GenerateTable() { PrintLine(); PrintRow(" ", " Qty "); PrintLine(); - PrintRow("Square",base.OrderedBlocks[0].TotalQuantityOfShape().ToString()); - PrintRow("Triangle", base.OrderedBlocks[1].TotalQuantityOfShape().ToString()); - PrintRow("Circle", base.OrderedBlocks[2].TotalQuantityOfShape().ToString()); + PrintRow("Square", OrderedBlocks[0].TotalQuantityOfShape.ToString()); + PrintRow("Triangle", OrderedBlocks[1].TotalQuantityOfShape.ToString()); + PrintRow("Circle", 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/IReport.cs b/Order.Management/IReport.cs new file mode 100644 index 0000000..af2d0ee --- /dev/null +++ b/Order.Management/IReport.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Order.Management +{ + interface IReport + { + public void GenerateTable(); + public void GenerateReport(); + + public void PrintLine() + { + } + + public void PrintRow(params string[] columns) + { + } + + public string AlignCentre(string text, int width) + { + return null; + } + + } +} diff --git a/Order.Management/InvoiceReport.cs b/Order.Management/InvoiceReport.cs index f29ca24..00f5398 100644 --- a/Order.Management/InvoiceReport.cs +++ b/Order.Management/InvoiceReport.cs @@ -1,24 +1,37 @@ using System; using System.Collections.Generic; -using System.Text; namespace Order.Management { class InvoiceReport : Order { - public int tableWidth = 73; - public InvoiceReport(string customerName, string customerAddress, string dueDate, List shapes) + public InvoiceReport(string customerName, string customerAddress, string dueDate, List orderedBlocks) : base (customerName, customerAddress, dueDate, orderedBlocks) { - base.CustomerName = customerName; - base.Address = customerAddress; - base.DueDate = dueDate; - base.OrderedBlocks = shapes; + tableWidth = 73; + OrderNumber += 1; + CustomerName = customerName; + Address = customerAddress; + DueDate = dueDate; + OrderedBlocks = orderedBlocks; } + public int TotalAmountOfRedShapes => OrderedBlocks[0].NumberOfRedShape + OrderedBlocks[1].NumberOfRedShape + + OrderedBlocks[2].NumberOfRedShape; + + public int TotalPriceRedPaintSurcharge => TotalAmountOfRedShapes* OrderedBlocks[0].AdditionalCharge; + + public void RedPaintSurcharge() => Console.WriteLine("Red Color Surcharge " + TotalAmountOfRedShapes + " @ $" + OrderedBlocks[0].AdditionalCharge + " ppi = $" + TotalPriceRedPaintSurcharge); + + public void OrderSquareDetails() => Console.WriteLine("\nSquares " + OrderedBlocks[0].TotalQuantityOfShape + " @ $" + OrderedBlocks[0].Price + " ppi = $" + OrderedBlocks[0].Total); + + public void OrderTriangleDetails() => Console.WriteLine("Triangles " + OrderedBlocks[1].TotalQuantityOfShape + " @ $" + OrderedBlocks[1].Price + " ppi = $" + OrderedBlocks[1].Total); + + public void OrderCircleDetails() => Console.WriteLine("Circles " + OrderedBlocks[2].TotalQuantityOfShape + " @ $" + OrderedBlocks[2].Price + " ppi = $" + OrderedBlocks[2].Total); + public override void GenerateReport() { Console.WriteLine("\nYour invoice report has been generated: "); - Console.WriteLine(base.ToString()); + Console.WriteLine(ToString()); GenerateTable(); OrderSquareDetails(); OrderTriangleDetails(); @@ -26,73 +39,5 @@ public override void GenerateReport() RedPaintSurcharge(); } - public void RedPaintSurcharge() - { - Console.WriteLine("Red Color Surcharge " + TotalAmountOfRedShapes() + " @ $" + base.OrderedBlocks[0].AdditionalCharge + " ppi = $" + TotalPriceRedPaintSurcharge()); - } - - public int TotalAmountOfRedShapes() - { - return OrderedBlocks[0].NumberOfRedShape + base.OrderedBlocks[1].NumberOfRedShape + - base.OrderedBlocks[2].NumberOfRedShape; - } - - public int TotalPriceRedPaintSurcharge() - { - return TotalAmountOfRedShapes() * base.OrderedBlocks[0].AdditionalCharge; - } - public void GenerateTable() - { - PrintLine(); - PrintRow(" ", " Red ", " Blue ", " Yellow "); - PrintLine(); - PrintRow("Square", base.OrderedBlocks[0].NumberOfRedShape.ToString(), base.OrderedBlocks[0].NumberOfBlueShape.ToString(), base.OrderedBlocks[0].NumberOfYellowShape.ToString()); - PrintRow("Triangle", base.OrderedBlocks[1].NumberOfRedShape.ToString(), base.OrderedBlocks[1].NumberOfBlueShape.ToString(), base.OrderedBlocks[1].NumberOfYellowShape.ToString()); - PrintRow("Circle", base.OrderedBlocks[2].NumberOfRedShape.ToString(), base.OrderedBlocks[2].NumberOfBlueShape.ToString(), base.OrderedBlocks[2].NumberOfYellowShape.ToString()); - PrintLine(); - } - public void OrderSquareDetails() - { - Console.WriteLine("\nSquares " + base.OrderedBlocks[0].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[0].Price + " ppi = $" + base.OrderedBlocks[0].Total()); - } - public void OrderTriangleDetails() - { - Console.WriteLine("Triangles " + base.OrderedBlocks[1].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[1].Price + " ppi = $" + base.OrderedBlocks[1].Total()); - } - public void OrderCircleDetails() - { - Console.WriteLine("Circles " + base.OrderedBlocks[2].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[2].Price + " ppi = $" + base.OrderedBlocks[2].Total()); - } - public void PrintLine() - { - Console.WriteLine(new string('-', tableWidth)); - } - - public void PrintRow(params string[] columns) - { - int width = (tableWidth - columns.Length) / columns.Length; - string row = "|"; - - foreach (string column in columns) - { - 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/Order.Management.csproj b/Order.Management/Order.Management.csproj index c73e0d1..8538d8a 100644 --- a/Order.Management/Order.Management.csproj +++ b/Order.Management/Order.Management.csproj @@ -2,7 +2,16 @@ Exe + netcoreapp3.1 + + + Order.Management.Program + + + + + diff --git a/Order.Management/Order.cs b/Order.Management/Order.cs index 90f7cb7..99e9a65 100644 --- a/Order.Management/Order.cs +++ b/Order.Management/Order.cs @@ -1,19 +1,67 @@ using System; using System.Collections.Generic; -using System.Text; namespace Order.Management { - abstract class Order + abstract class Order : IReport { public string CustomerName { get; set; } + public string Address { get; set; } + + protected Order(string customerName, string customerAddress, string dueDate, List orderedBlocks) + { + CustomerName = customerName ?? throw new ArgumentNullException(nameof(customerName)); + Address = customerAddress ?? throw new ArgumentNullException(nameof(customerAddress)); + DueDate = dueDate ?? throw new ArgumentNullException(nameof(dueDate)); + OrderedBlocks = orderedBlocks ?? throw new ArgumentNullException(nameof(orderedBlocks)); + } + public string DueDate { get; set; } + public int OrderNumber { get; set; } + public List OrderedBlocks { get; set; } + public override string ToString() => $"\nName: {CustomerName} Address: {Address} Due Date: {DueDate} Order #: {OrderNumber:0000}"; + + public UInt16 tableWidth = 20; public abstract void GenerateReport(); + + public string AlignCentre(string text, int width) + { + text = text.Length > width ? text.Substring(0, width - 3) + "..." : text; + + return string.IsNullOrEmpty(text) ? new string(' ', width) : text.PadRight(width - ((width - text.Length) / 2)).PadLeft(width); + } + + 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 override string ToString() => "\nName: " + CustomerName + " Address: " + Address + " Due Date: " + DueDate + " Order #: " + OrderNumber; + public virtual void GenerateTable() + { + PrintLine(); + PrintRow(" ", " Red ", " Blue ", " Yellow "); + PrintLine(); + PrintRow("Square", OrderedBlocks[0].NumberOfRedShape.ToString(), OrderedBlocks[0].NumberOfBlueShape.ToString(), OrderedBlocks[0].NumberOfYellowShape.ToString()); + PrintRow("Triangle", OrderedBlocks[1].NumberOfRedShape.ToString(), OrderedBlocks[1].NumberOfBlueShape.ToString(), OrderedBlocks[1].NumberOfYellowShape.ToString()); + PrintRow("Circle", OrderedBlocks[2].NumberOfRedShape.ToString(), OrderedBlocks[2].NumberOfBlueShape.ToString(), OrderedBlocks[2].NumberOfYellowShape.ToString()); + PrintLine(); + } } } diff --git a/Order.Management/PaintingReport.cs b/Order.Management/PaintingReport.cs index d56f34d..4aa7913 100644 --- a/Order.Management/PaintingReport.cs +++ b/Order.Management/PaintingReport.cs @@ -1,69 +1,26 @@ using System; using System.Collections.Generic; -using System.Text; namespace Order.Management { class PaintingReport : Order { - public int tableWidth = 73; - - public PaintingReport(string customerName, string customerAddress, string dueDate, List shapes) + public PaintingReport(string customerName, string customerAddress, string dueDate, List orderedBlocks) : base (customerName, customerAddress, dueDate, orderedBlocks) { + tableWidth = 73; + OrderNumber += 1; CustomerName = customerName; - base.Address = customerAddress; - base.DueDate = dueDate; - base.OrderedBlocks = shapes; + Address = customerAddress; + DueDate = dueDate; + OrderedBlocks = orderedBlocks; } public override void GenerateReport() { Console.WriteLine("\nYour painting report has been generated: "); - Console.WriteLine(base.ToString()); + Console.WriteLine(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); - } - } } } diff --git a/Order.Management/Program.cs b/Order.Management/Program.cs index b74fff8..b01ed16 100644 --- a/Order.Management/Program.cs +++ b/Order.Management/Program.cs @@ -1,18 +1,27 @@ using System; using System.Collections.Generic; +using System.Text.RegularExpressions; namespace Order.Management { + enum UserStrInputType + { + Name, + Address, + DueDate + } + class Program { // Main entry - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "")] +#pragma warning disable IDE0060 // Remove unused parameter static void Main(string[] args) +#pragma warning restore IDE0060 // Remove unused parameter { var (customerName, address, dueDate) = CustomerInfoInput(); - var orderedShapes = CustomerOrderInput(); + List orderedShapes = CustomerOrderInput(); InvoiceReport(customerName, address, dueDate, orderedShapes); @@ -20,30 +29,37 @@ static void Main(string[] args) PaintingReport(customerName, address, dueDate, orderedShapes); } - + // Order Circle Input - public static Circle OrderCirclesInput() + 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; + get + { + Console.Write("\nPlease input the number of Red Circle: "); + int redCircle = UserNumberInput(); + + Console.Write("Please input the number of Blue Circle: "); + int blueCircle = UserNumberInput(); + + Console.Write("Please input the number of Yellow Circle: "); + int yellowCircle = UserNumberInput(); + + 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()); + int redSquare = UserNumberInput(); + Console.Write("Please input the number of Blue Squares: "); - int blueSquare = Convert.ToInt32(UserInput()); + int blueSquare = UserNumberInput(); + Console.Write("Please input the number of Yellow Squares: "); - int yellowSquare = Convert.ToInt32(UserInput()); + int yellowSquare = UserNumberInput(); Square square = new Square(redSquare, blueSquare, yellowSquare); return square; @@ -53,18 +69,20 @@ public static Square OrderSquaresInput() public static Triangle OrderTrianglesInput() { Console.Write("\nPlease input the number of Red Triangles: "); - int redTriangle = Convert.ToInt32(UserInput()); + int redTriangle = UserNumberInput(); + Console.Write("Please input the number of Blue Triangles: "); - int blueTriangle = Convert.ToInt32(UserInput()); + int blueTriangle = UserNumberInput(); + Console.Write("Please input the number of Yellow Triangles: "); - int yellowTriangle = Convert.ToInt32(UserInput()); + int yellowTriangle = UserNumberInput(); Triangle triangle = new Triangle(redTriangle, blueTriangle, yellowTriangle); return triangle; } // User Console Input - public static string UserInput() + public static string UserInput() { string input = Console.ReadLine(); while (string.IsNullOrEmpty(input)) @@ -76,6 +94,45 @@ public static string UserInput() return input; } + //Add-on: User Console Number Input + public static int UserNumberInput() + { + string strInput = UserInput(); + while (!Regex.IsMatch(strInput, @"^(?=.{1,9}$)[0-9]+$")) + { + Console.WriteLine("Please only input numbers"); + strInput = UserInput(); + } + + return Convert.ToInt32(strInput); + } + + public static string UserStringInput(UserStrInputType inputType) + { + string strInput = UserInput(); + switch (inputType) + { + case UserStrInputType.Name: + case UserStrInputType.Address: + while (!Regex.IsMatch(strInput, @"^[0-9a-zA-Z]{3,}")) + { + Console.WriteLine("Requires minimum input of 3 characters"); + strInput = UserInput(); + } + break; + + case UserStrInputType.DueDate: + while (!Regex.IsMatch(strInput, @"^(?=.{2,11}$)(([0-9])|([0-2][0-9])|([3][0-1]))\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{4}")) + { + Console.WriteLine("Date input needs to be at least 11 characters in DD Mon YYYY format (e.g. 19 Jan 2019)"); + strInput = UserInput(); + } + break; + } + + return strInput; + } + // Generate Painting Report private static void PaintingReport(string customerName, string address, string dueDate, List orderedShapes) { @@ -101,11 +158,14 @@ private static void InvoiceReport(string customerName, string address, string du private static (string customerName, string address, string dueDate) CustomerInfoInput() { Console.Write("Please input your Name: "); - string customerName = UserInput(); - Console.Write("Please input your Address: "); - string address = UserInput(); + string customerName = UserStringInput(UserStrInputType.Name); + + Console.Write("Please input your Address: "); + string address = UserStringInput(UserStrInputType.Address); + Console.Write("Please input your Due Date: "); - string dueDate = UserInput(); + string dueDate = UserStringInput(UserStrInputType.DueDate); + return (customerName, address, dueDate); } @@ -114,7 +174,7 @@ private static List CustomerOrderInput() { Square square = OrderSquaresInput(); Triangle triangle = OrderTrianglesInput(); - Circle circle = OrderCirclesInput(); + Circle circle = OrderCirclesInput; var orderedShapes = new List { diff --git a/Order.Management/Shape.cs b/Order.Management/Shape.cs index b86e63c..4b2d406 100644 --- a/Order.Management/Shape.cs +++ b/Order.Management/Shape.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Order.Management +namespace Order.Management { abstract class Shape { @@ -18,17 +14,10 @@ abstract class Shape public int NumberOfYellowShape { get; set; } - public int TotalQuantityOfShape() - { - return NumberOfRedShape + NumberOfBlueShape + NumberOfYellowShape; - } - - public int AdditionalChargeTotal() - { - return NumberOfRedShape * AdditionalCharge; - } + public int TotalQuantityOfShape => NumberOfRedShape + NumberOfBlueShape + NumberOfYellowShape; - public abstract int Total(); + public int AdditionalChargeTotal => NumberOfRedShape * AdditionalCharge; + public abstract int Total { get; } } } diff --git a/Order.Management/Square.cs b/Order.Management/Square.cs index 0a701ac..304878b 100644 --- a/Order.Management/Square.cs +++ b/Order.Management/Square.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Order.Management +namespace Order.Management { class Square : Shape { @@ -12,31 +8,19 @@ class Square : Shape public Square(int numberOfRedSquares, int numberOfBlueSquares, int numberOfYellowSquares) { Name = "Square"; - base.Price = SquarePrice; + Price = SquarePrice; AdditionalCharge = 1; - base.NumberOfRedShape = numberOfRedSquares; - base.NumberOfBlueShape = numberOfBlueSquares; - base.NumberOfYellowShape = numberOfYellowSquares; + NumberOfRedShape = numberOfRedSquares; + NumberOfBlueShape = numberOfBlueSquares; + NumberOfYellowShape = numberOfYellowSquares; } - public override int Total() - { - return RedSquaresTotal() + BlueSquaresTotal() + YellowSquaresTotal(); - } + public override int Total => RedSquaresTotal+ BlueSquaresTotal+ YellowSquaresTotal; - public int RedSquaresTotal() - { - return (base.NumberOfRedShape * Price); - } + public int RedSquaresTotal => (NumberOfRedShape * Price); - public int BlueSquaresTotal() - { - return (base.NumberOfBlueShape * Price); - } + public int BlueSquaresTotal => (NumberOfBlueShape * Price); - public int YellowSquaresTotal() - { - return (base.NumberOfYellowShape * Price); - } + public int YellowSquaresTotal => (NumberOfYellowShape * Price); } } diff --git a/Order.Management/Triangle.cs b/Order.Management/Triangle.cs index 2bdf241..3a5ee1e 100644 --- a/Order.Management/Triangle.cs +++ b/Order.Management/Triangle.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Order.Management +namespace Order.Management { class Triangle : Shape { @@ -11,32 +7,19 @@ class Triangle : Shape public Triangle(int numberOfRedTriangles, int numberOfBlueTriangles, int numberOfYellowTriangles) { Name = "Triangle"; - base.Price = TrianglePrice; + Price = TrianglePrice; AdditionalCharge = 1; - base.NumberOfRedShape = numberOfRedTriangles; - base.NumberOfBlueShape = numberOfBlueTriangles; - base.NumberOfYellowShape = numberOfYellowTriangles; + NumberOfRedShape = numberOfRedTriangles; + NumberOfBlueShape = numberOfBlueTriangles; + NumberOfYellowShape = numberOfYellowTriangles; } - public override int Total() - { - return RedTrianglesTotal() + BlueTrianglesTotal() + YellowTrianglesTotal(); - } + public override int Total => RedTrianglesTotal+ BlueTrianglesTotal+ YellowTrianglesTotal; - public int RedTrianglesTotal() - { - return (base.NumberOfRedShape * Price); - } + public int RedTrianglesTotal => (NumberOfRedShape * Price); - public int BlueTrianglesTotal() - { - return (base.NumberOfBlueShape * Price); - } + public int BlueTrianglesTotal => (NumberOfBlueShape * Price); - public int YellowTrianglesTotal() - { - return (base.NumberOfYellowShape * Price); - } - -} + public int YellowTrianglesTotal => (NumberOfYellowShape * Price); + } }