From 1e70e608985c4d9a99ba21057c090bd39d9b52fd Mon Sep 17 00:00:00 2001 From: Brandon Rodriguez <brodriguez8774@mail.kvcc.edu> Date: Sat, 17 Oct 2015 02:40:56 -0400 Subject: [PATCH] Fix errors in inheritance logic and improve single item display. Should be significantly less unecessary repeating via inheritance. SingleItem display formatting tweaked. Minor additional tweaks, mostly in logic of code. --- cis237assignment3/Droid.cs | 25 +++--- cis237assignment3/Droid_Astromech.cs | 35 ++++----- cis237assignment3/Droid_Generic.cs | 58 +++++++------- cis237assignment3/Droid_Janitor.cs | 31 ++++---- cis237assignment3/Droid_Protocol.cs | 25 +++--- cis237assignment3/Droid_Utility.cs | 37 +++++---- cis237assignment3/IDroid.cs | 12 +++ cis237assignment3/RunProgram.cs | 112 +++++++++++++++------------ cis237assignment3/UserInterface.cs | 35 +++++++-- 9 files changed, 206 insertions(+), 164 deletions(-) diff --git a/cis237assignment3/Droid.cs b/cis237assignment3/Droid.cs index fc54dd1..d6e5a60 100644 --- a/cis237assignment3/Droid.cs +++ b/cis237assignment3/Droid.cs @@ -16,9 +16,9 @@ namespace cis237assignment3 { #region Variables - protected string materialString; - protected string modelString; - protected string colorString; + protected string selectedMaterialString; + protected string selectedModelString; + protected string selectedColorString; 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. @@ -59,20 +59,20 @@ namespace cis237assignment3 public string Material { - set { materialString = value; } - get { return materialString; } + set { selectedMaterialString = value; } + get { return selectedMaterialString; } } public string Model { - set { modelString = value; } - get { return modelString; } + set { selectedModelString = value; } + get { return selectedModelString; } } public string Color { - set { colorString = value; } - get { return colorString; } + set { selectedColorString = value; } + get { return selectedColorString; } } public decimal BaseCost @@ -111,13 +111,18 @@ namespace cis237assignment3 /// </summary> public abstract void CalculateTotalCost(); + /// <summary> + /// Calculates individual feature costs of droid. + /// </summary> + public abstract void CalculateFeatures(); + /// <summary> /// Shortened string for displaying of many droids, each in single line format. /// </summary> /// <returns>Single ine formatted for list of droids.</returns> public virtual string DisplayShortToString() { - return (materialString + " ").PadRight(10) + (modelString + " - ").PadRight(10) + colorString.PadRight(10) + totalCostDecimal.ToString("C").PadLeft(10) + Environment.NewLine; + return (selectedMaterialString + " ").PadRight(11) + (selectedModelString + " ").PadRight(10) + (selectedColorString + " ").PadRight(10) + totalCostDecimal.ToString("C").PadLeft(10) + Environment.NewLine; } /// <summary> diff --git a/cis237assignment3/Droid_Astromech.cs b/cis237assignment3/Droid_Astromech.cs index 506bc8c..a215128 100644 --- a/cis237assignment3/Droid_Astromech.cs +++ b/cis237assignment3/Droid_Astromech.cs @@ -53,8 +53,6 @@ namespace cis237assignment3 HasFireExtinguisher = hasFireExtinguisher; NumberOfShips = numberOfShips; numberOfItemsInt = 8; - - CreateDroid(); } #endregion @@ -95,8 +93,7 @@ namespace cis237assignment3 private void CalculateNumberOfShipsCost() { - CalculateTotalCost(); - numberOfShipsDecimal = totalCostDecimal * numberOfItemsInt; + numberOfShipsDecimal = numberOfShipsInt * costPerFeatureDecimal; } #endregion @@ -105,13 +102,13 @@ namespace cis237assignment3 #region Protected Methods - protected override void CreateDroid() + /// <summary> + /// Creates string for droid type. Needed due to how inheritance works. + /// </summary> + /// <returns>String of droid's type.</returns> + protected override string TypeString() { - base.CreateDroid(); - - CalculateFireExtinguisherCost(); - CalculateNumberOfShipsCost(); - CalculateTotalCost(); + return "Astromech "; } #endregion @@ -126,16 +123,18 @@ namespace cis237assignment3 public override void CalculateTotalCost() { base.CalculateTotalCost(); - totalCostDecimal += fireExtinguisherDecimal; + totalCostDecimal += fireExtinguisherDecimal + numberOfShipsDecimal; } /// <summary> - /// Shortened string for displaying of many droids, each in single line format. + /// Calculates individual feature costs of droid. /// </summary> - /// <returns>Single ine formatted for list of droids.</returns> - public override string DisplayShortToString() + public override void CalculateFeatures() { - return "Astromech ".PadRight(10) + base.DisplayShortToString(); + base.CalculateFeatures(); + + CalculateFireExtinguisherCost(); + CalculateNumberOfShipsCost(); } /// <summary> @@ -144,9 +143,9 @@ namespace cis237assignment3 /// <returns>Full information regarding single droid.</returns> public override string DisplayLongToString() { - return base.DisplayLongToString() + 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; + return base.DisplayLongToString() + + "".PadRight(5) + "Fire Extinguisher: ".PadRight(25) + YesNoString(hasFireExtinguisherBool).PadRight(17) + fireExtinguisherDecimal.ToString("C").PadLeft(10) + Environment.NewLine + + "".PadRight(5) + ("Outfitted for " + numberOfShipsInt + " ships.").PadRight(42) + numberOfShipsDecimal.ToString("C").PadLeft(10) + Environment.NewLine; } #endregion diff --git a/cis237assignment3/Droid_Generic.cs b/cis237assignment3/Droid_Generic.cs index 18cbe2b..78a6eb7 100644 --- a/cis237assignment3/Droid_Generic.cs +++ b/cis237assignment3/Droid_Generic.cs @@ -16,7 +16,6 @@ namespace cis237assignment3 #region Variables // All the necessary variables for material selection. - private string selectedMaterialString; private decimal selectedMaterialDecimal; public static string MATERIAL_1_STRING = "Tin"; public static string MATERIAL_2_STRING = "Steel"; @@ -30,7 +29,6 @@ namespace cis237assignment3 private decimal material5Decimal; // All the necessary variables for model selection. - protected string selectedModelString; protected decimal selectedModelDecimal; public static string MODEL_1_STRING = "TI-84"; public static string MODEL_2_STRING = "CAT5"; @@ -40,7 +38,6 @@ namespace cis237assignment3 private decimal model2Decimal; // All the necessary variables for color selection. - private string selectedColorString; private decimal selectedColorDecimal; public static string COLOR_1_STRING = "White"; public static string COLOR_2_STRING = "Black"; @@ -81,11 +78,7 @@ namespace cis237assignment3 public Droid_Generic(string material, string model, string color) : base(material, model, color) { - SelectedMaterial = material; - SelectedModel = model; - SelectedColor = color; - CreateDroid(); } #endregion @@ -94,20 +87,7 @@ namespace cis237assignment3 #region Properties - public string SelectedModel - { - set { selectedModelString = value; } - } - - public string SelectedMaterial - { - set { selectedMaterialString = value; } - } - public string SelectedColor - { - set { selectedColorString = value; } - } #endregion @@ -288,6 +268,16 @@ namespace cis237assignment3 baseCostDecimal = selectedModelDecimal + selectedMaterialDecimal + selectedColorDecimal; } + /// <summary> + /// Creates string for droid type. Needed due to how inheritance works. + /// </summary> + /// <returns>String of droid's type.</returns> + protected virtual string TypeString() + { + return ""; + } + + #endregion @@ -304,16 +294,6 @@ namespace cis237assignment3 return Convert.ToDecimal(centsDouble); } - protected virtual void CreateDroid() - { - selectedModelDecimal = 10; - selectedMaterialDecimal = 10; - selectedColorDecimal = 10; - - CalculateBaseCost(); - CalculateTotalCost(); - } - #endregion @@ -328,13 +308,25 @@ namespace cis237assignment3 totalCostDecimal = baseCostDecimal; } + /// <summary> + /// Calculates individual feature costs of droid. + /// </summary> + public override void CalculateFeatures() + { + selectedModelDecimal = 10; + selectedMaterialDecimal = 10; + selectedColorDecimal = 10; + + CalculateBaseCost(); + } + /// <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(); + return TypeString().PadRight(11) + base.DisplayShortToString(); } /// <summary> @@ -343,7 +335,9 @@ namespace cis237assignment3 /// <returns>Full information regarding single droid.</returns> public override string DisplayLongToString() { - return (materialString + " ").PadRight(10) + (modelString + " - ").PadRight(10) + colorString.PadRight(10) + totalCostDecimal.ToString("C").PadLeft(10) + Environment.NewLine; + return "".PadRight(5) + TypeString().PadRight(11) + (selectedMaterialString + " ").PadRight(11) + (selectedModelString + " ").PadRight(10) + selectedColorString.PadRight(10) + baseCostDecimal.ToString("C").PadLeft(10) + Environment.NewLine + + Environment.NewLine + + Environment.NewLine; } #endregion diff --git a/cis237assignment3/Droid_Janitor.cs b/cis237assignment3/Droid_Janitor.cs index 2b4ca22..15f4fd8 100644 --- a/cis237assignment3/Droid_Janitor.cs +++ b/cis237assignment3/Droid_Janitor.cs @@ -53,8 +53,6 @@ namespace cis237assignment3 HasTrashCompactor = hasTrashCompactor; HasVacuum = hasVacuum; numberOfItemsInt = 8; - - CreateDroid(); } #endregion @@ -111,14 +109,13 @@ namespace cis237assignment3 #region Protected Methods - protected override void CreateDroid() + /// <summary> + /// Creates string for droid type. Needed due to how inheritance works. + /// </summary> + /// <returns>String of droid's type.</returns> + protected override string TypeString() { - base.CreateDroid(); - - CalculateTrashCompactorCost(); - CalculateVacuumCost(); - - CalculateTotalCost(); + return "Janitor "; } #endregion @@ -137,12 +134,14 @@ namespace cis237assignment3 } /// <summary> - /// Shortened string for displaying of many droids, each in single line format. + /// Calculates individual feature costs of droid. /// </summary> - /// <returns>Single ine formatted for list of droids.</returns> - public override string DisplayShortToString() + public override void CalculateFeatures() { - return "Janitor ".PadRight(10) + base.DisplayShortToString(); + base.CalculateFeatures(); + + CalculateTrashCompactorCost(); + CalculateVacuumCost(); } /// <summary> @@ -151,9 +150,9 @@ namespace cis237assignment3 /// <returns>Full information regarding single droid.</returns> public override string DisplayLongToString() { - return base.DisplayLongToString() + Environment.NewLine + - "".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; + return base.DisplayLongToString() + + "".PadRight(5) + "Trash Compactor: ".PadRight(25) + YesNoString(hasTrashCompactorBool).PadRight(17) + trashCompactorDecimal.ToString("C").PadLeft(10) + Environment.NewLine + + "".PadRight(5) + "Vacuum: ".PadRight(25) + YesNoString(hasVacuumBool).PadRight(17) + vacuumDecimal.ToString("C").PadLeft(10) + Environment.NewLine; } #endregion diff --git a/cis237assignment3/Droid_Protocol.cs b/cis237assignment3/Droid_Protocol.cs index a1a6d0e..1495299 100644 --- a/cis237assignment3/Droid_Protocol.cs +++ b/cis237assignment3/Droid_Protocol.cs @@ -52,8 +52,6 @@ namespace cis237assignment3 { NumberOfLanguages = numberOfLanguages; numberOfItemsInt = 4; - - CreateDroid(); } #endregion @@ -88,13 +86,13 @@ namespace cis237assignment3 #region Protected methods - protected override void CreateDroid() + /// <summary> + /// Creates string for droid type. Needed due to how inheritance works. + /// </summary> + /// <returns>String of droid's type.</returns> + protected override string TypeString() { - base.CreateDroid(); - - CalculateLanguageCost(); - - CalculateTotalCost(); + return "Protocol "; } #endregion @@ -113,12 +111,13 @@ namespace cis237assignment3 } /// <summary> - /// Shortened string for displaying of many droids, each in single line format. + /// Calculates individual feature costs of droid. /// </summary> - /// <returns>Single ine formatted for list of droids.</returns> - public override string DisplayShortToString() + public override void CalculateFeatures() { - return "Protocol ".PadRight(10) + base.DisplayShortToString(); + base.CalculateFeatures(); + + CalculateLanguageCost(); } /// <summary> @@ -128,7 +127,7 @@ namespace cis237assignment3 public override string DisplayLongToString() { return base.DisplayLongToString() + - "".PadRight(5) + ("Languages: " + numberOfLanguagesInt).PadRight(30) + totalLanguageDecimal.ToString("C").PadLeft(10) + Environment.NewLine; + "".PadRight(5) + "Languages: ".PadRight(25) + numberOfLanguagesInt.ToString().PadRight(17) + totalLanguageDecimal.ToString("C").PadLeft(10) + Environment.NewLine; } #endregion diff --git a/cis237assignment3/Droid_Utility.cs b/cis237assignment3/Droid_Utility.cs index 25e5217..451e0b1 100644 --- a/cis237assignment3/Droid_Utility.cs +++ b/cis237assignment3/Droid_Utility.cs @@ -50,12 +50,10 @@ namespace cis237assignment3 public Droid_Utility(string material, string model, string color, bool hasToolBox, bool hasComputerConnection, bool hasArm) : base(material, model, color) { - HasToolBox = hasToolBoxBool; + HasToolBox = hasToolBox; HasComputerConnection = hasComputerConnection; HasArm = hasArm; numberOfItemsInt = 6; - - CreateDroid(); } #endregion @@ -151,15 +149,13 @@ namespace cis237assignment3 return displayString; } - protected override void CreateDroid() + /// <summary> + /// Creates string for droid type. Needed due to how inheritance works. + /// </summary> + /// <returns>String of droid's type.</returns> + protected override string TypeString() { - base.CreateDroid(); - - CalculateToolBoxCost(); - CalculateConnectionCost(); - CalculateArmCost(); - - CalculateTotalCost(); + return "Utility "; } #endregion @@ -178,12 +174,15 @@ namespace cis237assignment3 } /// <summary> - /// Shortened string for displaying of many droids, each in single line format. + /// Calculates individual feature costs of droid. /// </summary> - /// <returns>Single ine formatted for list of droids.</returns> - public override string DisplayShortToString() + public override void CalculateFeatures() { - return "Utility ".PadRight(10) + base.DisplayShortToString(); + base.CalculateFeatures(); + + CalculateToolBoxCost(); + CalculateConnectionCost(); + CalculateArmCost(); } /// <summary> @@ -192,10 +191,10 @@ namespace cis237assignment3 /// <returns>Full information regarding single droid.</returns> public override string DisplayLongToString() { - return base.DisplayLongToString() + Environment.NewLine + - "".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; + return base.DisplayLongToString() + + "".PadRight(5) + "Toolbox: ".PadRight(25) + YesNoString(hasArmBool).PadRight(17) + toolBoxDecimal.ToString("C").PadLeft(10) + Environment.NewLine + + "".PadRight(5) + "Computer Connection: ".PadRight(25) + YesNoString(hasComputerConnectiontBool).PadRight(17) + computerConnectionDecimal.ToString("C").PadLeft(10) + Environment.NewLine + + "".PadRight(5) + "Arm: ".PadRight(25) + YesNoString(hasArmBool).PadRight(17) + armDecimal.ToString("C").PadLeft(10) + Environment.NewLine; } #endregion diff --git a/cis237assignment3/IDroid.cs b/cis237assignment3/IDroid.cs index 39f4ee7..8e2783a 100644 --- a/cis237assignment3/IDroid.cs +++ b/cis237assignment3/IDroid.cs @@ -19,14 +19,26 @@ namespace cis237assignment3 /// </summary> void CalculateTotalCost(); + /// <summary> + /// Calculates individual feature costs of droid. + /// </summary> + void CalculateFeatures(); + + // Total cost of droid. decimal TotalCost { get; set; } + + // Number of individual items influencing droid price. + int NumberOfItems { get; } + + /// <summary> /// Shortened string for displaying of many droids, each in single line format. /// </summary> /// <returns>Single ine formatted for list of droids.</returns> string DisplayShortToString(); + /// <summary> /// Full string for displaying of single droid spanning multiple lines. /// </summary> diff --git a/cis237assignment3/RunProgram.cs b/cis237assignment3/RunProgram.cs index 777bf17..975ea11 100644 --- a/cis237assignment3/RunProgram.cs +++ b/cis237assignment3/RunProgram.cs @@ -155,7 +155,7 @@ namespace cis237assignment3 { int tempInt = Convert.ToInt32(userInputString); - if (tempInt > 0 && tempInt < droidCollection.DroidListSize) + if (tempInt > 0 && tempInt <= droidCollection.DroidListSize) { tempInt--; DisplaySingleDroid(tempInt); @@ -206,15 +206,55 @@ namespace cis237assignment3 { case "1": PurchaseProtocol(); + + // After user selects values for droid, actually create it, add it to the collection, and calculate the various associated prices. + if (menusBool) + { + UserInterface.ClearDisplayLine(); + IDroid aDroid = new Droid_Protocol(selectedMaterialString, selectedModelString, selectedColorString, selectedLanguageInt); + droidCollection.AddDroid(aDroid); + droidCollection.DroidList[droidCollection.DroidListSize - 1].CalculateFeatures(); + droidCollection.DroidList[droidCollection.DroidListSize - 1].CalculateTotalCost(); + } break; case "2": PurchaseUtility(); + + // After user selects values for droid, actually create it, add it to the collection, and calculate the various associated prices. + if (menusBool) + { + UserInterface.ClearDisplayLine(); + IDroid aDroid = new Droid_Utility(selectedMaterialString, selectedModelString, selectedColorString, toolBoxBool, computerConnectionBool, armBool); + droidCollection.AddDroid(aDroid); + droidCollection.DroidList[droidCollection.DroidListSize - 1].CalculateFeatures(); + droidCollection.DroidList[droidCollection.DroidListSize - 1].CalculateTotalCost(); + } break; case "3": PurchaseJanitor(); + + // After user selects values for droid, actually create it, add it to the collection, and calculate the various associated prices. + if (menusBool) + { + UserInterface.ClearDisplayLine(); + IDroid aDroid = new Droid_Janitor(selectedMaterialString, selectedModelString, selectedColorString, toolBoxBool, computerConnectionBool, armBool, trashCompactorBool, vacuumBool); + droidCollection.AddDroid(aDroid); + droidCollection.DroidList[droidCollection.DroidListSize - 1].CalculateFeatures(); + droidCollection.DroidList[droidCollection.DroidListSize - 1].CalculateTotalCost(); + } break; case "4": PurchaseAstromech(); + + // After user selects values for droid, actually create it, add it to the collection, and calculate the various associated prices. + if (menusBool) + { + UserInterface.ClearDisplayLine(); + IDroid aDroid = new Droid_Astromech(selectedMaterialString, selectedModelString, selectedColorString, toolBoxBool, computerConnectionBool, armBool, fireExtinguisherBool, selectedNumberOfShipsInt); + droidCollection.AddDroid(aDroid); + droidCollection.DroidList[droidCollection.DroidListSize - 1].CalculateFeatures(); + droidCollection.DroidList[droidCollection.DroidListSize - 1].CalculateTotalCost(); + } break; case "esc": UserInterface.ClearDisplayLine(); @@ -264,12 +304,6 @@ namespace cis237assignment3 UserInterface.ClearDisplayLine(); LanguageSelection(); } - if (menusBool) - { - UserInterface.ClearDisplayLine(); - IDroid aDroid = new Droid_Protocol(selectedMaterialString, selectedModelString, selectedColorString, selectedLanguageInt); - droidCollection.AddDroid(aDroid); - } } /// <summary> @@ -297,12 +331,6 @@ namespace cis237assignment3 UserInterface.ClearDisplayLine(); ArmSelection(); } - if (menusBool) - { - UserInterface.ClearDisplayLine(); - IDroid aDroid = new Droid_Utility(selectedMaterialString, selectedModelString, selectedColorString, toolBoxBool, computerConnectionBool, armBool); - droidCollection.AddDroid(aDroid); - } } /// <summary> @@ -325,12 +353,6 @@ namespace cis237assignment3 UserInterface.ClearDisplayLine(); VacuumSelection(); } - if (menusBool) - { - UserInterface.ClearDisplayLine(); - IDroid aDroid = new Droid_Janitor(selectedMaterialString, selectedModelString, selectedColorString, toolBoxBool, computerConnectionBool, armBool, trashCompactorBool, vacuumBool); - droidCollection.AddDroid(aDroid); - } } /// <summary> @@ -353,12 +375,6 @@ namespace cis237assignment3 UserInterface.ClearDisplayLine(); NumberOfShipsSelection(); } - if (menusBool) - { - UserInterface.ClearDisplayLine(); - IDroid aDroid = new Droid_Astromech(selectedMaterialString, selectedModelString, selectedColorString, toolBoxBool, computerConnectionBool, armBool, fireExtinguisherBool, selectedNumberOfShipsInt); - droidCollection.AddDroid(aDroid); - } } /// <summary> @@ -387,6 +403,7 @@ namespace cis237assignment3 private void DisplaySingleDroid(int index) { displayString = droidCollection.DroidList[index].DisplayLongToString(); + UserInterface.DisplaySingleDroidInfo(displayString, droidCollection.DroidList[index].NumberOfItems, droidCollection.DroidList[index].TotalCost); } @@ -694,41 +711,38 @@ namespace cis237assignment3 /// </summary> private void NumberOfShipsSelection() { - while (menusBool) - { - UserInterface.Menus.DisplayNumberOfShipsSelectionMenu(); - userInputString = UserInterface.GetUserInput(); + UserInterface.Menus.DisplayNumberOfShipsSelectionMenu(); + userInputString = UserInterface.GetUserInput(); - // If user does not want to back out of menu. - if (userInputString != "esc") + // If user does not want to back out of menu. + if (userInputString != "esc") + { + // Attempt to convert user input to int. + try { - // Attempt to convert user input to int. - try + int temptInt = Convert.ToInt32(userInputString); + // Makes sure selection is between 0 and 10. + if (temptInt > 0 && temptInt < 10) { - 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(); - } + selectedNumberOfShipsInt = temptInt; } - catch + else { - UserInterface.DisplayError("Not a valid number."); + UserInterface.DisplayError("Must be between 0 and 10."); NumberOfShipsSelection(); } } - else + catch { - UserInterface.ClearDisplayLine(); - menusBool = false; + UserInterface.DisplayError("Not a valid number."); + NumberOfShipsSelection(); } } + else + { + UserInterface.ClearDisplayLine(); + menusBool = false; + } } #endregion diff --git a/cis237assignment3/UserInterface.cs b/cis237assignment3/UserInterface.cs index 87069be..fa4c614 100644 --- a/cis237assignment3/UserInterface.cs +++ b/cis237assignment3/UserInterface.cs @@ -350,9 +350,9 @@ namespace cis237assignment3 ResetMenuDisplay(); Console.WriteLine( - " Outfit onto how many ships? " + Environment.NewLine + + " Program for how many ship types? " + Environment.NewLine + "" + Environment.NewLine + - " Note: This will multiply the cost by the number of droids you select. We can outfit up to 9 ships."); + " Note: We can only program up to 9 ship types."); } public static void DisplaySingleDroidSelectionMenu() @@ -378,22 +378,20 @@ namespace cis237assignment3 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(" ".PadRight(5) + "Type".PadRight(11) + "Material".PadRight(11) + "Model".PadRight(10) + "Color".PadRight(10) + "Total Cost".PadLeft(10) + Environment.NewLine); Console.WriteLine(displayString); } - - /// <summary> /// Clears currently displayed list of androids. /// </summary> public static void ClearList() { // Clear lines equal to size of last displayed droid list. - Console.SetCursorPosition(1, 10); + Console.SetCursorPosition(0, 10); int index = 0; - while (index < previousListSizeInt + 2) + while (index < previousListSizeInt + 5) { Console.WriteLine("".PadRight(Console.WindowWidth - 1)); index++; @@ -401,6 +399,29 @@ namespace cis237assignment3 } + /// <summary> + /// Displays list of droids to console. + /// </summary> + /// <param name="displayString">String of droids to display.</param> + /// <param name="currentListSize">Number of items which effect droid's price.</param> + public static void DisplaySingleDroidInfo(string displayString, int numberOfItemsForDroid, decimal totalCost) + { + ClearList(); + previousListSizeInt = numberOfItemsForDroid; + + Console.SetCursorPosition(0, 10); + + Console.WriteLine(" ".PadRight(5) + "Type".PadRight(11) + "Material".PadRight(11) + "Model".PadRight(10) + "Color".PadRight(10) + "Base Cost".PadLeft(10) + Environment.NewLine + + Environment.NewLine + + Environment.NewLine + + "".PadRight(5) + "Feature".PadRight(25) + "Selection".PadRight(17) + "Cost".PadLeft(10)); + + Console.SetCursorPosition(0, 11); + Console.WriteLine(displayString); + + Console.WriteLine("".PadRight(5) + "Total Droid Cost: ".PadRight(25) + totalCost.ToString("C").PadLeft(15)); + } + #endregion } -- GitLab