From 85c971510ac338229badfbdf614192011c0ef47b Mon Sep 17 00:00:00 2001 From: Brandon Rodriguez <brodriguez8774@mail.kvcc.edu> Date: Fri, 16 Oct 2015 16:50:21 -0400 Subject: [PATCH] Improve UI display for listing droids. Updates list UI to be easier to follow. Most of the program/UI should have proper error handling now. SingleItem display still needs work. Should now be able to correctly add all droid types to collection. --- cis237assignment3/Droid.cs | 8 +- cis237assignment3/Droid_Astromech.cs | 18 +++-- cis237assignment3/Droid_Generic.cs | 27 ++++++- cis237assignment3/Droid_Janitor.cs | 10 +-- cis237assignment3/Droid_Protocol.cs | 10 +-- cis237assignment3/Droid_Utility.cs | 12 +-- cis237assignment3/RunProgram.cs | 111 +++++++++++++++++++-------- cis237assignment3/UserInterface.cs | 45 ++++++----- 8 files changed, 160 insertions(+), 81 deletions(-) diff --git a/cis237assignment3/Droid.cs b/cis237assignment3/Droid.cs index 78f6cf1..fc54dd1 100644 --- a/cis237assignment3/Droid.cs +++ b/cis237assignment3/Droid.cs @@ -19,10 +19,10 @@ namespace cis237assignment3 protected string materialString; protected string modelString; protected string colorString; - protected decimal baseCostDecimal; - protected decimal totalCostDecimal; + protected decimal baseCostDecimal; // Cost of droid before any extra features. IE, just the material, model, and color cost. + protected decimal totalCostDecimal; // Full cost of droid, including all extra features. protected decimal costPerFeatureDecimal = 10; // Standard cost per most features. - protected int numberOfItemsInt; + protected int numberOfItemsInt; // Number of individual items influencing droid price. #endregion @@ -117,7 +117,7 @@ namespace cis237assignment3 /// <returns>Single ine formatted for list of droids.</returns> public virtual string DisplayShortToString() { - return (materialString + " " + modelString + " : " + colorString).PadRight(30) + totalCostDecimal.ToString("C").PadLeft(10); + return (materialString + " ").PadRight(10) + (modelString + " - ").PadRight(10) + colorString.PadRight(10) + totalCostDecimal.ToString("C").PadLeft(10) + Environment.NewLine; } /// <summary> diff --git a/cis237assignment3/Droid_Astromech.cs b/cis237assignment3/Droid_Astromech.cs index 40d037c..506bc8c 100644 --- a/cis237assignment3/Droid_Astromech.cs +++ b/cis237assignment3/Droid_Astromech.cs @@ -95,7 +95,8 @@ namespace cis237assignment3 private void CalculateNumberOfShipsCost() { - + CalculateTotalCost(); + numberOfShipsDecimal = totalCostDecimal * numberOfItemsInt; } #endregion @@ -108,9 +109,9 @@ namespace cis237assignment3 { base.CreateDroid(); - - - + CalculateFireExtinguisherCost(); + CalculateNumberOfShipsCost(); + CalculateTotalCost(); } #endregion @@ -131,20 +132,21 @@ namespace cis237assignment3 /// <summary> /// Shortened string for displaying of many droids, each in single line format. /// </summary> - /// <returns>String of short Droid information.</returns> + /// <returns>Single ine formatted for list of droids.</returns> public override string DisplayShortToString() { - return "Astromech Droid: " + totalCostDecimal.ToString().PadLeft(10); + return "Astromech ".PadRight(10) + base.DisplayShortToString(); } /// <summary> /// Full string for displaying of single droid spanning multiple lines. /// </summary> - /// <returns>String of full Droid information.</returns> + /// <returns>Full information regarding single droid.</returns> public override string DisplayLongToString() { return base.DisplayLongToString() + Environment.NewLine + - "Fire Extinguisher: " + YesNoString(hasFireExtinguisherBool) + Environment.NewLine; + "".PadRight(5) + ("Fire Extinguisher: " + YesNoString(hasFireExtinguisherBool)).PadRight(30) + fireExtinguisherDecimal.ToString("C").PadLeft(10) + Environment.NewLine + + "".PadRight(5) + ("Outfitting onto " + numberOfItemsInt + " different ships.").PadRight(30) + numberOfShipsDecimal.ToString("C").PadLeft(10) + Environment.NewLine; } #endregion diff --git a/cis237assignment3/Droid_Generic.cs b/cis237assignment3/Droid_Generic.cs index fca2b69..18cbe2b 100644 --- a/cis237assignment3/Droid_Generic.cs +++ b/cis237assignment3/Droid_Generic.cs @@ -279,6 +279,15 @@ namespace cis237assignment3 * * */ + /// <summary> + /// Determines the base cost of a droid. This is the cost of the droid minus any additional features. + /// IE, only the cost in regards to the model, material, and color. + /// </summary> + public void CalculateBaseCost() + { + baseCostDecimal = selectedModelDecimal + selectedMaterialDecimal + selectedColorDecimal; + } + #endregion @@ -301,6 +310,7 @@ namespace cis237assignment3 selectedMaterialDecimal = 10; selectedColorDecimal = 10; + CalculateBaseCost(); CalculateTotalCost(); } @@ -315,12 +325,25 @@ namespace cis237assignment3 /// </summary> public override void CalculateTotalCost() { - totalCostDecimal = selectedModelDecimal + selectedMaterialDecimal + selectedColorDecimal; + totalCostDecimal = baseCostDecimal; + } + + /// <summary> + /// Shortened string for displaying of many droids, each in single line format. + /// </summary> + /// <returns>Single ine formatted for list of droids.</returns> + public override string DisplayShortToString() + { + return base.DisplayShortToString(); } + /// <summary> + /// Full string for displaying of single droid spanning multiple lines. + /// </summary> + /// <returns>Full information regarding single droid.</returns> public override string DisplayLongToString() { - return (materialString + " " + modelString + " : " + colorString).PadRight(30) + totalCostDecimal.ToString("C").PadLeft(10); + return (materialString + " ").PadRight(10) + (modelString + " - ").PadRight(10) + colorString.PadRight(10) + totalCostDecimal.ToString("C").PadLeft(10) + Environment.NewLine; } #endregion diff --git a/cis237assignment3/Droid_Janitor.cs b/cis237assignment3/Droid_Janitor.cs index efd3e1d..2b4ca22 100644 --- a/cis237assignment3/Droid_Janitor.cs +++ b/cis237assignment3/Droid_Janitor.cs @@ -139,21 +139,21 @@ namespace cis237assignment3 /// <summary> /// Shortened string for displaying of many droids, each in single line format. /// </summary> - /// <returns>String of short Droid information.</returns> + /// <returns>Single ine formatted for list of droids.</returns> public override string DisplayShortToString() { - return "Utility Droid: " + totalCostDecimal.ToString().PadLeft(10); + return "Janitor ".PadRight(10) + base.DisplayShortToString(); } /// <summary> /// Full string for displaying of single droid spanning multiple lines. /// </summary> - /// <returns>String of full Droid information.</returns> + /// <returns>Full information regarding single droid.</returns> public override string DisplayLongToString() { return base.DisplayLongToString() + Environment.NewLine + - "Trash Compactor: " + YesNoString(hasTrashCompactorBool) + Environment.NewLine + - "Vacuum: " + YesNoString(hasVacuumBool); + "".PadRight(5) + ("Trash Compactor: " + YesNoString(hasTrashCompactorBool)).PadRight(30) + trashCompactorDecimal.ToString("C").PadLeft(10) + Environment.NewLine + + "".PadRight(5) + ("Vacuum: " + YesNoString(hasVacuumBool)).PadRight(30) + vacuumDecimal.ToString("C").PadLeft(10) + Environment.NewLine; } #endregion diff --git a/cis237assignment3/Droid_Protocol.cs b/cis237assignment3/Droid_Protocol.cs index 383a512..a1a6d0e 100644 --- a/cis237assignment3/Droid_Protocol.cs +++ b/cis237assignment3/Droid_Protocol.cs @@ -115,20 +115,20 @@ namespace cis237assignment3 /// <summary> /// Shortened string for displaying of many droids, each in single line format. /// </summary> - /// <returns>String of short Droid information.</returns> + /// <returns>Single ine formatted for list of droids.</returns> public override string DisplayShortToString() { - return "Protocol Droid: " + totalCostDecimal.ToString().PadLeft(10); + return "Protocol ".PadRight(10) + base.DisplayShortToString(); } /// <summary> /// Full string for displaying of single droid spanning multiple lines. /// </summary> - /// <returns>String of full Droid information.</returns> + /// <returns>Full information regarding single droid.</returns> public override string DisplayLongToString() { - return base.DisplayLongToString() + Environment.NewLine + - "Languages: " + numberOfLanguagesInt; + return base.DisplayLongToString() + + "".PadRight(5) + ("Languages: " + numberOfLanguagesInt).PadRight(30) + totalLanguageDecimal.ToString("C").PadLeft(10) + Environment.NewLine; } #endregion diff --git a/cis237assignment3/Droid_Utility.cs b/cis237assignment3/Droid_Utility.cs index d171cef..25e5217 100644 --- a/cis237assignment3/Droid_Utility.cs +++ b/cis237assignment3/Droid_Utility.cs @@ -180,22 +180,22 @@ namespace cis237assignment3 /// <summary> /// Shortened string for displaying of many droids, each in single line format. /// </summary> - /// <returns>String of short Droid information.</returns> + /// <returns>Single ine formatted for list of droids.</returns> public override string DisplayShortToString() { - return "Utility Droid: " + totalCostDecimal.ToString().PadLeft(10); + return "Utility ".PadRight(10) + base.DisplayShortToString(); } /// <summary> /// Full string for displaying of single droid spanning multiple lines. /// </summary> - /// <returns>String of full Droid information.</returns> + /// <returns>Full information regarding single droid.</returns> public override string DisplayLongToString() { return base.DisplayLongToString() + Environment.NewLine + - "Toolbox: " + YesNoString(hasArmBool) + Environment.NewLine + - "Computer Connection: " + YesNoString(hasComputerConnectiontBool) + Environment.NewLine + - "Arm: " + YesNoString(hasArmBool); + "".PadRight(5) + ("Toolbox: " + YesNoString(hasArmBool)).PadRight(30) + toolBoxDecimal.ToString("C").PadLeft(10) + Environment.NewLine + + "".PadRight(5) + ("Computer Connection: " + YesNoString(hasComputerConnectiontBool)).PadRight(30) + computerConnectionDecimal.ToString("C").PadLeft(10) + Environment.NewLine + + "".PadRight(5) + ("Arm: " + YesNoString(hasArmBool)).PadRight(30) + armDecimal.ToString("C").PadLeft(10) + Environment.NewLine; } #endregion diff --git a/cis237assignment3/RunProgram.cs b/cis237assignment3/RunProgram.cs index 2bf00ae..777bf17 100644 --- a/cis237assignment3/RunProgram.cs +++ b/cis237assignment3/RunProgram.cs @@ -99,6 +99,7 @@ namespace cis237assignment3 DisplaySingle(); break; case "4": + ResetList(); break; case "5": Exit(); @@ -127,7 +128,15 @@ namespace cis237assignment3 private void DisplayReciept() { UserInterface.ClearDisplayLine(); - DisplayFullList(); + + if (droidCollection.DroidList[0] != null) + { + DisplayFullList(); + } + else + { + UserInterface.DisplayError("There is no reciept to display."); + } } /// <summary> @@ -136,7 +145,35 @@ namespace cis237assignment3 private void DisplaySingle() { UserInterface.ClearDisplayLine(); - //DisplaySingleDroid(); + + if (droidCollection.DroidList[0] != null) + { + UserInterface.Menus.DisplaySingleDroidSelectionMenu(); + + userInputString = UserInterface.GetUserInput(); + try + { + int tempInt = Convert.ToInt32(userInputString); + + if (tempInt > 0 && tempInt < droidCollection.DroidListSize) + { + tempInt--; + DisplaySingleDroid(tempInt); + } + else + { + UserInterface.DisplayError("There is no droid associated with that number."); + } + } + catch + { + UserInterface.DisplayError("You must enter a number."); + } + } + else + { + UserInterface.DisplayError("There are no droids to display."); + } } /// <summary> @@ -324,6 +361,35 @@ namespace cis237assignment3 } } + /// <summary> + /// Displays full list of droids. + /// </summary> + private void DisplayFullList() + { + displayString = ""; + int index = 0; + + foreach (Droid droid in droidCollection.DroidList) + { + if (droid != null) + { + index++; + displayString += (" "+ index + ") ").PadRight(5) + droid.DisplayShortToString(); + } + } + + UserInterface.DisplayList(displayString, index); + } + + /// <summary> + /// Displays information regarding a single droid. + /// </summary> + private void DisplaySingleDroid(int index) + { + displayString = droidCollection.DroidList[index].DisplayLongToString(); + } + + #region Individual Feature Selections /// <summary> @@ -639,7 +705,17 @@ namespace cis237assignment3 // Attempt to convert user input to int. try { - selectedNumberOfShipsInt = Convert.ToInt32(userInputString); + int temptInt = Convert.ToInt32(userInputString); + // Makes sure selection is between 0 and 10. + if (selectedNumberOfShipsInt > 0 && selectedNumberOfShipsInt < 10) + { + selectedNumberOfShipsInt = temptInt; + } + else + { + UserInterface.DisplayError("Must be between 0 and 10."); + NumberOfShipsSelection(); + } } catch { @@ -657,35 +733,6 @@ namespace cis237assignment3 #endregion - /// <summary> - /// Displays full list of droids. - /// </summary> - private void DisplayFullList() - { - displayString = ""; - int index = 0; - - foreach (Droid droid in droidCollection.DroidList) - { - if (droid != null) - { - displayString += " " + droid.DisplayShortToString(); - } - index++; - } - - UserInterface.DisplayList(displayString, index); - } - - /// <summary> - /// Displays information regarding a single droid. - /// </summary> - private void DisplaySingleDroid(int index) - { - displayString = droidCollection.DroidList[index].DisplayLongToString(); - - } - #endregion diff --git a/cis237assignment3/UserInterface.cs b/cis237assignment3/UserInterface.cs index 77a116d..87069be 100644 --- a/cis237assignment3/UserInterface.cs +++ b/cis237assignment3/UserInterface.cs @@ -157,7 +157,8 @@ namespace cis237assignment3 " 1) Purchase Droid" + Environment.NewLine + " 2) Display Full Reciept" + Environment.NewLine + " 3) Display Single Item" + Environment.NewLine + - " 4) Exit"); + " 4) New Customer" + Environment.NewLine + + " 5) Exit"); } /// <summary> @@ -350,10 +351,21 @@ namespace cis237assignment3 Console.WriteLine( " Outfit onto how many ships? " + Environment.NewLine + - "" + Environment.NewLine); + "" + Environment.NewLine + + " Note: This will multiply the cost by the number of droids you select. We can outfit up to 9 ships."); + } + + public static void DisplaySingleDroidSelectionMenu() + { + ResetMenuDisplay(); + + Console.WriteLine(" Input Droid Number: " + Environment.NewLine + + "" + Environment.NewLine + + " If needed, droid numbers can be viewed on the reciept." + Environment.NewLine); } } + /// <summary> /// Displays list of droids to console. /// </summary> @@ -361,37 +373,32 @@ namespace cis237assignment3 /// <param name="currentListSize">Current size of droid list.</param> public static void DisplayList(string displayString, int currentListSize) { - // If no previous list was displayed. - if (previousListSizeInt == null) - { - previousListSizeInt = 0; - } - ClearList(); previousListSizeInt = currentListSize; - Console.SetCursorPosition(1, 10); + Console.SetCursorPosition(0, 10); + + Console.WriteLine(" ".PadRight(5) + "Type".PadRight(10) + "Material".PadRight(10) + "Model".PadRight(10) + "Color".PadRight(10) + "Base Cost".PadLeft(10) + Environment.NewLine); Console.WriteLine(displayString); } + + /// <summary> /// Clears currently displayed list of androids. /// </summary> public static void ClearList() { - if (previousListSizeInt != null) + // Clear lines equal to size of last displayed droid list. + Console.SetCursorPosition(1, 10); + int index = 0; + while (index < previousListSizeInt + 2) { - // Clear lines equal to size of last displayed droid list. - Console.SetCursorPosition(1, 10); - int index = 0; - while (index < previousListSizeInt) - { - Console.WriteLine("".PadRight(Console.WindowWidth - 1)); - index++; - } - + Console.WriteLine("".PadRight(Console.WindowWidth - 1)); + index++; } + } #endregion -- GitLab