diff --git a/Order.Management/Circle.cs b/Order.Management/Circle.cs index 9824ecc..95ec542 100644 --- a/Order.Management/Circle.cs +++ b/Order.Management/Circle.cs @@ -6,32 +6,32 @@ namespace Order.Management { class Circle : Shape { - public int circlePrice = 3; + private double circlePrice = 3; public Circle(int red, int blue, int yellow) { Name = "Circle"; - base.Price = circlePrice; + Price = circlePrice; AdditionalCharge = 1; - base.NumberOfRedShape = red; - base.NumberOfBlueShape = blue; - base.NumberOfYellowShape = yellow; + NumberOfRedShape = red; + NumberOfBlueShape = blue; + NumberOfYellowShape = yellow; } - public override int Total() + public override double Total() { return RedCirclesTotal() + BlueCirclesTotal() + YellowCirclesTotal(); } - public int RedCirclesTotal() + public double RedCirclesTotal() { - return (base.NumberOfRedShape * Price); + return (NumberOfRedShape * Price); } - public int BlueCirclesTotal() + public double BlueCirclesTotal() { - return (base.NumberOfBlueShape * Price); + return (NumberOfBlueShape * Price); } - public int YellowCirclesTotal() + public double YellowCirclesTotal() { - return (base.NumberOfYellowShape * Price); + return (NumberOfYellowShape * Price); } } } diff --git a/Order.Management/CuttingListReport.cs b/Order.Management/CuttingListReport.cs index 125d45f..bb415f7 100644 --- a/Order.Management/CuttingListReport.cs +++ b/Order.Management/CuttingListReport.cs @@ -6,35 +6,33 @@ namespace Order.Management { class CuttingListReport : Order { - public int tableWidth = 20; + private int tableWidth = 20; public CuttingListReport(string customerName, string customerAddress, string dueDate, List shapes) { - base.CustomerName = customerName; - base.Address = customerAddress; - base.DueDate = dueDate; - base.OrderedBlocks = shapes; + CustomerName = customerName; + 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() { - PrintLine(); + PrintLine(new string('-', tableWidth)); 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)); + PrintLine(new string('-', tableWidth)); + PrintRow("Square", OrderedBlocks[0].TotalQuantityOfShape().ToString()); + PrintRow("Triangle", OrderedBlocks[1].TotalQuantityOfShape().ToString()); + PrintRow("Circle", OrderedBlocks[2].TotalQuantityOfShape().ToString()); + PrintLine(new string('-', tableWidth)); } + //Consider moving this to the base class + public void PrintRow(params string[] columns) { diff --git a/Order.Management/InvoiceReport.cs b/Order.Management/InvoiceReport.cs index 78443c3..15aaa32 100644 --- a/Order.Management/InvoiceReport.cs +++ b/Order.Management/InvoiceReport.cs @@ -6,13 +6,13 @@ namespace Order.Management { class InvoiceReport : Order { - public int tableWidth = 73; + private int tableWidth = 73; public InvoiceReport(string customerName, string customerAddress, string dueDate, List shapes) { - base.CustomerName = customerName; - base.Address = customerAddress; - base.DueDate = dueDate; - base.OrderedBlocks = shapes; + CustomerName = customerName; + Address = customerAddress; + DueDate = dueDate; + OrderedBlocks = shapes; } public override void GenerateReport() @@ -28,45 +28,42 @@ 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() + " @ $" + OrderedBlocks[0].AdditionalCharge + " ppi = $" + TotalPriceRedPaintSurcharge()); } public int TotalAmountOfRedShapes() { - return base.OrderedBlocks[0].NumberOfRedShape + base.OrderedBlocks[1].NumberOfRedShape + - base.OrderedBlocks[2].NumberOfRedShape; + return OrderedBlocks[0].NumberOfRedShape + OrderedBlocks[1].NumberOfRedShape + + OrderedBlocks[2].NumberOfRedShape; } public int TotalPriceRedPaintSurcharge() { - return TotalAmountOfRedShapes() * base.OrderedBlocks[0].AdditionalCharge; + return TotalAmountOfRedShapes() * OrderedBlocks[0].AdditionalCharge; } public void GenerateTable() { - PrintLine(); + PrintLine(new string('-', tableWidth)); 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(); + PrintLine(new string('-', tableWidth)); + 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(new string('-', tableWidth)); } public void OrderSquareDetails() { - Console.WriteLine("\nSquares " + base.OrderedBlocks[0].TotalQuantityOfShape() + " @ $" + base.OrderedBlocks[0].Price + " ppi = $" + base.OrderedBlocks[0].Total()); + Console.WriteLine("\nSquares " + OrderedBlocks[0].TotalQuantityOfShape() + " @ $" + OrderedBlocks[0].Price + " ppi = $" + 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 " + OrderedBlocks[1].TotalQuantityOfShape() + " @ $" + OrderedBlocks[1].Price + " ppi = $" + 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)); + Console.WriteLine("Circles " + OrderedBlocks[2].TotalQuantityOfShape() + " @ $" + OrderedBlocks[2].Price + " ppi = $" + OrderedBlocks[2].Total()); } + //Consider moving this to the base class public void PrintRow(params string[] columns) { diff --git a/Order.Management/Order.cs b/Order.Management/Order.cs index 235c789..2645cc3 100644 --- a/Order.Management/Order.cs +++ b/Order.Management/Order.cs @@ -13,10 +13,16 @@ abstract class Order public List OrderedBlocks { get; set; } public abstract void GenerateReport(); - - public string ToString() + + // Add override to eliminate warning + public override string ToString() { return "\nName: " + CustomerName + " Address: " + Address + " Due Date: " + DueDate + " Order #: " + OrderNumber; } + + public void PrintLine(string lineToPrint) + { + Console.WriteLine(lineToPrint); + } } } diff --git a/Order.Management/PaintingReport.cs b/Order.Management/PaintingReport.cs index 9b61c83..9be2a4f 100644 --- a/Order.Management/PaintingReport.cs +++ b/Order.Management/PaintingReport.cs @@ -9,10 +9,10 @@ class PaintingReport : Order public int tableWidth = 73; public PaintingReport(string customerName, string customerAddress, string dueDate, List shapes) { - base.CustomerName = customerName; - base.Address = customerAddress; - base.DueDate = dueDate; - base.OrderedBlocks = shapes; + CustomerName = customerName; + Address = customerAddress; + DueDate = dueDate; + OrderedBlocks = shapes; } public override void GenerateReport() { @@ -23,19 +23,15 @@ public override void GenerateReport() public void generateTable() { - PrintLine(); + PrintLine(new string('-', tableWidth)); 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)); + PrintLine(new string('-', tableWidth)); + 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(new string('-', tableWidth)); } + //Consider moving this to the base class public void PrintRow(params string[] columns) { diff --git a/Order.Management/Program.cs b/Order.Management/Program.cs index 1422f85..c3fee54 100644 --- a/Order.Management/Program.cs +++ b/Order.Management/Program.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Text.RegularExpressions; namespace Order.Management { @@ -22,12 +23,9 @@ static void Main(string[] args) // 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()); + int redCircle = ReadInt("\nPlease input the number of Red Circle: "); + int blueCircle = ReadInt("Please input the number of Blue Circle: "); + int yellowCircle = ReadInt("Please input the number of Yellow Circle: "); Circle circle = new Circle(redCircle, blueCircle, yellowCircle); return circle; @@ -36,12 +34,9 @@ public static Circle OrderCirclesInput() // 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()); + int redSquare = ReadInt("\nPlease input the number of Red Squares: "); + int blueSquare = ReadInt("Please input the number of Blue Squares: "); + int yellowSquare = ReadInt("Please input the number of Yellow Squares: "); Square square = new Square(redSquare, blueSquare, yellowSquare); return square; @@ -50,30 +45,14 @@ public static Square OrderSquaresInput() // 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()); + int redTriangle = ReadInt("\nPlease input the number of Red Triangles: "); + int blueTriangle = ReadInt("Please input the number of Blue Triangles: "); + int yellowTriangle = ReadInt("Please input the number of Yellow Triangles: "); 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) { @@ -98,12 +77,9 @@ private static void InvoiceReport(string customerName, string address, string du // 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(); + string customerName = ReadName("Please input your Name: "); + string address = ReadAddress("Please input your Address: "); + string dueDate = ReadDate("Please input your Due Date: ").ToString(); return (customerName, address, dueDate); } @@ -120,5 +96,56 @@ private static List CustomerOrderInput() orderedShapes.Add(circle); return orderedShapes; } + + // Create a funcion to read int only + private static int ReadInt(string prompt) + { + Console.Write(prompt); + string number = Console.ReadLine(); + int value; + while(!Int32.TryParse(number, out value)) + { + Console.Write("Not a valid number, try again: "); + number = Console.ReadLine(); + } + return value; + } + // Create a function to read names only {first name + last name} + private static string ReadName(string prompt) + { + Console.Write(prompt); + string name = Console.ReadLine(); + while (!Regex.IsMatch(name, @"^[A-Za-zÀ-ú]+ [A-Za-zÀ-ú]+$")) + { + Console.Write("Name must be 1-35 alfanum, try again: "); + name = Console.ReadLine(); + } + return name; + } + // Create a fuction to read string only. This can be improved depending on the address format + public static string ReadAddress(string prompt) + { + Console.Write(prompt); + string input = Console.ReadLine(); + while (string.IsNullOrEmpty(input)) + { + Console.Write("Please enter a valid address: "); + input = Console.ReadLine(); + } + return input; + } + // Create a function that returns a DateTime type only + private static DateTime ReadDate(string prompt) + { + Console.Write(prompt); + string date = Console.ReadLine(); + DateTime value; + while (!DateTime.TryParse(date, out value)) + { + Console.Write("Not a valid date, try again: "); + date = Console.ReadLine(); + } + return value; + } } } diff --git a/Order.Management/Shape.cs b/Order.Management/Shape.cs index 7f5c61c..4d0963e 100644 --- a/Order.Management/Shape.cs +++ b/Order.Management/Shape.cs @@ -4,10 +4,26 @@ namespace Order.Management { + /* + The main Math class + Contains all methods for performing basic math functions +*/ + /// + /// The main Shape class. + /// Abstract class contains all methods for performing basic shape functions. + /// + /// + /// More specific shapes can inherit this class. + /// abstract class Shape { public string Name { get; set; } - public int Price { get; set; } + private double _price; + //Price is decimal value of 2 decimal places + public double Price { + get { return Math.Round(_price, 2); } + set { _price = value; } + } public int AdditionalCharge { get; set; } public int NumberOfRedShape { get; set; } public int NumberOfBlueShape { get; set; } @@ -16,12 +32,11 @@ public int TotalQuantityOfShape() { return NumberOfRedShape + NumberOfBlueShape + NumberOfYellowShape; } - public int AdditionalChargeTotal() { return NumberOfRedShape * AdditionalCharge; } - public abstract int Total(); + public abstract double Total(); } } diff --git a/Order.Management/Square.cs b/Order.Management/Square.cs index 017601e..0b82331 100644 --- a/Order.Management/Square.cs +++ b/Order.Management/Square.cs @@ -7,34 +7,34 @@ namespace Order.Management class Square : Shape { - public int SquarePrice = 1; + private double squarePrice = 1; 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() + public override double Total() { return RedSquaresTotal() + BlueSquaresTotal() + YellowSquaresTotal(); } - public int RedSquaresTotal() + public double RedSquaresTotal() { - return (base.NumberOfRedShape * Price); + return (NumberOfRedShape * Price); } - public int BlueSquaresTotal() + public double BlueSquaresTotal() { - return (base.NumberOfBlueShape * Price); + return (NumberOfBlueShape * Price); } - public int YellowSquaresTotal() + public double YellowSquaresTotal() { - return (base.NumberOfYellowShape * Price); + return (NumberOfYellowShape * Price); } } } diff --git a/Order.Management/Triangle.cs b/Order.Management/Triangle.cs index dbf48ff..f142728 100644 --- a/Order.Management/Triangle.cs +++ b/Order.Management/Triangle.cs @@ -6,33 +6,33 @@ namespace Order.Management { class Triangle : Shape { - public int TrianglePrice = 2; + private double trianglePrice = 2; 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() + public override double Total() { return RedTrianglesTotal() + BlueTrianglesTotal() + YellowTrianglesTotal(); } - public int RedTrianglesTotal() + public double RedTrianglesTotal() { - return (base.NumberOfRedShape * Price); + return (NumberOfRedShape * Price); } - public int BlueTrianglesTotal() + public double BlueTrianglesTotal() { - return (base.NumberOfBlueShape * Price); + return (NumberOfBlueShape * Price); } - public int YellowTrianglesTotal() + public double YellowTrianglesTotal() { - return (base.NumberOfYellowShape * Price); + return (NumberOfYellowShape * Price); } }