Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .idea/.idea.Order.Management/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.idea.Order.Management/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/.idea.Order.Management/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.Order.Management/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.Order.Management/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/.idea.OrderManagementPR/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.idea.OrderManagementPR/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/.idea.OrderManagementPR/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.OrderManagementPR/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.OrderManagementPR/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions Order.Management.PR/Circle.cs
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);
}
}
}
68 changes: 68 additions & 0 deletions Order.Management.PR/CuttingListReport.cs
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);
}
}


}
}
98 changes: 98 additions & 0 deletions Order.Management.PR/InvoiceReport.cs
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);
}
}
}
}
8 changes: 8 additions & 0 deletions Order.Management.PR/Order.Management.csproj
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>
22 changes: 22 additions & 0 deletions Order.Management.PR/Order.cs
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();
Copy link
Author

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 GenerateReport method to an IReportService interface. PaintingReport, CuttingListReport, or InvoiceReport should be the derived class which implement the IReportService interface.


public string ToString()
{
return "\nName: " + CustomerName + " Address: " + Address + " Due Date: " + DueDate + " Order #: " + OrderNumber;
}
}
}
67 changes: 67 additions & 0 deletions Order.Management.PR/PaintingReport.cs
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()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generateTable method could be private. And for keeping the consistency, we should use pascal case naming, which is GenerateTable

{
PrintLine();
PrintRow(" ", " Red ", " Blue ", " Yellow ");
PrintLine();
PrintRow("Square", base.OrderedBlocks[0].NumberOfRedShape.ToString(), base.OrderedBlocks[0].NumberOfBlueShape.ToString(), base.OrderedBlocks[0].NumberOfYellowShape.ToString());
Copy link
Author

Choose a reason for hiding this comment

The 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

internal class OrderedBlocks
        {
            public Square Square { get; set; }
            public Triangle Triangle { get; set; }
            public Circle Circle { get; set; }
        }

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);
}
}
}
}
Loading