-
Notifications
You must be signed in to change notification settings - Fork 38
Clone solution for Code Review #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text; | ||
|
|
||
| namespace Order.Management | ||
| { | ||
| class Circle : Shape | ||
| { | ||
| public int circlePrice = 3; | ||
| public Circle(int red, int blue, int yellow) | ||
| { | ||
| Name = "Circle"; | ||
| base.Price = circlePrice; | ||
| AdditionalCharge = 1; | ||
| base.NumberOfRedShape = red; | ||
| base.NumberOfBlueShape = blue; | ||
| base.NumberOfYellowShape = yellow; | ||
| } | ||
| public override int Total() | ||
| { | ||
| return RedCirclesTotal() + BlueCirclesTotal() + YellowCirclesTotal(); | ||
| } | ||
|
|
||
| public int RedCirclesTotal() | ||
| { | ||
| return (base.NumberOfRedShape * Price); | ||
| } | ||
| public int BlueCirclesTotal() | ||
| { | ||
| return (base.NumberOfBlueShape * Price); | ||
| } | ||
| public int YellowCirclesTotal() | ||
| { | ||
| return (base.NumberOfYellowShape * Price); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| 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<Shape> shapes) | ||
| { | ||
| 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(); | ||
| } | ||
| public void generateTable() | ||
| { | ||
| PrintLine(); | ||
| PrintRow(" ", " Qty "); | ||
| PrintLine(); | ||
| PrintRow("Square",base.OrderedBlocks[0].TotalQuantityOfShape().ToString()); | ||
| PrintRow("Triangle", base.OrderedBlocks[1].TotalQuantityOfShape().ToString()); | ||
| PrintRow("Circle", base.OrderedBlocks[2].TotalQuantityOfShape().ToString()); | ||
| PrintLine(); | ||
| } | ||
| 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); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| 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<Shape> shapes) | ||
| { | ||
| 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()); | ||
| GenerateTable(); | ||
| OrderSquareDetails(); | ||
| OrderTriangleDetails(); | ||
| OrderCircleDetails(); | ||
| RedPaintSurcharge(); | ||
| } | ||
|
|
||
| public void RedPaintSurcharge() | ||
| { | ||
| Console.WriteLine("Red Color Surcharge " + TotalAmountOfRedShapes() + " @ $" + base.OrderedBlocks[0].AdditionalCharge + " ppi = $" + TotalPriceRedPaintSurcharge()); | ||
| } | ||
|
|
||
| public int TotalAmountOfRedShapes() | ||
| { | ||
| return base.OrderedBlocks[0].NumberOfRedShape + base.OrderedBlocks[1].NumberOfRedShape + | ||
| base.OrderedBlocks[2].NumberOfRedShape; | ||
| } | ||
|
|
||
| public int TotalPriceRedPaintSurcharge() | ||
| { | ||
| return TotalAmountOfRedShapes() * base.OrderedBlocks[0].AdditionalCharge; | ||
| } | ||
| public void GenerateTable() | ||
| { | ||
| PrintLine(); | ||
| PrintRow(" ", " Red ", " Blue ", " Yellow "); | ||
| PrintLine(); | ||
| PrintRow("Square", base.OrderedBlocks[0].NumberOfRedShape.ToString(), base.OrderedBlocks[0].NumberOfBlueShape.ToString(), base.OrderedBlocks[0].NumberOfYellowShape.ToString()); | ||
| PrintRow("Triangle", base.OrderedBlocks[1].NumberOfRedShape.ToString(), base.OrderedBlocks[1].NumberOfBlueShape.ToString(), base.OrderedBlocks[1].NumberOfYellowShape.ToString()); | ||
| PrintRow("Circle", base.OrderedBlocks[2].NumberOfRedShape.ToString(), base.OrderedBlocks[2].NumberOfBlueShape.ToString(), base.OrderedBlocks[2].NumberOfYellowShape.ToString()); | ||
| PrintLine(); | ||
| } | ||
| public void OrderSquareDetails() | ||
| { | ||
| Console.WriteLine("\nSquares " + base.OrderedBlocks[0].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[0].Price + " ppi = $" + base.OrderedBlocks[0].Total()); | ||
| } | ||
| public void OrderTriangleDetails() | ||
| { | ||
| Console.WriteLine("Triangles " + base.OrderedBlocks[1].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[1].Price + " ppi = $" + base.OrderedBlocks[1].Total()); | ||
| } | ||
| public void OrderCircleDetails() | ||
| { | ||
| Console.WriteLine("Circles " + base.OrderedBlocks[2].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[2].Price + " ppi = $" + base.OrderedBlocks[2].Total()); | ||
| } | ||
| public void PrintLine() | ||
| { | ||
| Console.WriteLine(new string('-', tableWidth)); | ||
| } | ||
|
|
||
| public void PrintRow(params string[] columns) | ||
| { | ||
| int width = (tableWidth - columns.Length) / columns.Length; | ||
| string row = "|"; | ||
|
|
||
| foreach (string column in columns) | ||
| { | ||
| 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); | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>netcoreapp3.0</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text; | ||
|
|
||
| namespace Order.Management | ||
| { | ||
| abstract class Order | ||
| { | ||
| public string CustomerName { get; set; } | ||
| public string Address { get; set; } | ||
| public string DueDate { get; set; } | ||
| public int OrderNumber { get; set; } | ||
| public List<Shape> OrderedBlocks { get; set; } | ||
|
|
||
| public abstract void GenerateReport(); | ||
|
|
||
| public string ToString() | ||
| { | ||
| return "\nName: " + CustomerName + " Address: " + Address + " Due Date: " + DueDate + " Order #: " + OrderNumber; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| 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<Shape> shapes) | ||
| { | ||
| 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()); | ||
| generateTable(); | ||
| } | ||
|
|
||
| public void generateTable() | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| { | ||
| PrintLine(); | ||
| PrintRow(" ", " Red ", " Blue ", " Yellow "); | ||
| PrintLine(); | ||
| PrintRow("Square", base.OrderedBlocks[0].NumberOfRedShape.ToString(), base.OrderedBlocks[0].NumberOfBlueShape.ToString(), base.OrderedBlocks[0].NumberOfYellowShape.ToString()); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All OrderedBlocks are the same structure, which is built by Square, Triangle, and Circle. So we could use a strong type for OrderedBlocks, such as It will make the code more readable and not error-prone. |
||
| 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); | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PaintingReport, CuttingListReport, or InvoiceReport are not different types of Orders. Instead, they are different types of Report services that could generate different reports from the Order. Therefore, we should move the
GenerateReportmethod to anIReportServiceinterface. PaintingReport, CuttingListReport, or InvoiceReport should be the derived class which implement theIReportServiceinterface.