diff --git a/README.md b/README.md index 958af5a7355045f496c3c379f14eaaff16755fcd..bd178f5334514e320c171116530b9f420d75668b 100644 --- a/README.md +++ b/README.md @@ -97,4 +97,7 @@ https://msdn.microsoft.com/en-us/library/ah19swz4.aspx https://msdn.microsoft.com/en-us/library/aa288471%28v=vs.71%29.aspx * Structs for ease of organization. +https://msdn.microsoft.com/en-us/library/hfw7t1ce.aspx +* Figured out how to use base in a void override method. + ## Known Problems, Issues, And/Or Errors in the Program diff --git a/cis237assignment3/Droid.cs b/cis237assignment3/Droid.cs index 18d54d9739cca65c0f52f67dc5dcf33ef95feeea..78f6cf1811b201e198b209d7e4b811a30acb530a 100644 --- a/cis237assignment3/Droid.cs +++ b/cis237assignment3/Droid.cs @@ -21,7 +21,8 @@ namespace cis237assignment3 protected string colorString; protected decimal baseCostDecimal; protected decimal totalCostDecimal; - protected decimal costPerFeature; // Standard cost per most features. + protected decimal costPerFeatureDecimal = 10; // Standard cost per most features. + protected int numberOfItemsInt; #endregion @@ -86,6 +87,11 @@ namespace cis237assignment3 get { return totalCostDecimal; } } + public int NumberOfItems + { + get { return numberOfItemsInt; } + } + #endregion @@ -100,22 +106,25 @@ namespace cis237assignment3 #region Public Methods + /// <summary> + /// Calculates total cost of droid. + /// </summary> public abstract void CalculateTotalCost(); /// <summary> /// Shortened string for displaying of many droids, each in single line format. /// </summary> - /// <returns>String of short Droid information.</returns> - public abstract string DisplayShortToString(); + /// <returns>Single ine formatted for list of droids.</returns> + public virtual string DisplayShortToString() + { + return (materialString + " " + modelString + " : " + colorString).PadRight(30) + totalCostDecimal.ToString("C").PadLeft(10); + } /// <summary> /// Full string for displaying of single droid spanning multiple lines. /// </summary> - /// <returns>String of full Droid information.</returns> - public virtual string DisplayFullToString() - { - return materialString + " " + modelString + " : " + colorString; - } + /// <returns>Full information regarding single droid.</returns> + public abstract string DisplayLongToString(); #endregion diff --git a/cis237assignment3/DroidCollection.cs b/cis237assignment3/DroidCollection.cs index 39dcab790dc38b701f48f79f4120c8259d81feb4..3eaa38fd1b7a03aef7326c8aacdab3cc7b775a5e 100644 --- a/cis237assignment3/DroidCollection.cs +++ b/cis237assignment3/DroidCollection.cs @@ -12,7 +12,12 @@ namespace cis237assignment3 { #region Variables - + private IDroid[] droidCollection; + private IDroid[] tempArray; + + private int indexInt; + private int lenghtOfArrayInt; // Total length of array, including null spots. + private int droidListSizeInt; // Number of droids actually taking up spots in array. #endregion @@ -25,23 +30,26 @@ namespace cis237assignment3 /// </summary> public DroidCollection() { - + droidListSizeInt = 0; + lenghtOfArrayInt = 10; + droidCollection = new Droid_Generic[lenghtOfArrayInt]; } - - public DroidCollection(IDroid aDroid) - { - - } - - #endregion #region Properties + public int DroidListSize + { + get { return droidListSizeInt; } + } + public IDroid[] DroidList + { + get { return droidCollection; } + } #endregion @@ -49,7 +57,32 @@ namespace cis237assignment3 #region Private Methods - + /// <summary> + /// Expands array to be one and a half times current size. + /// </summary> + public void ExpandArray() + { + // Set list size to be one and a half times the size of current. + lenghtOfArrayInt = droidListSizeInt + (droidListSizeInt / 2); + tempArray = new Droid_Generic[lenghtOfArrayInt]; + + indexInt = 0; + // While not through entire list of droids yet. + while (indexInt < droidListSizeInt) + { + // If reached a null space, force exit of while loop. + if (droidCollection[indexInt] == null) + { + indexInt = droidListSizeInt; + } + else + { + tempArray[indexInt] = droidCollection[indexInt]; + indexInt++; + } + droidCollection = tempArray; + } + } #endregion @@ -57,11 +90,32 @@ namespace cis237assignment3 #region Public Methods - public void PurchaseDroid() + /// <summary> + /// Adds a single droid to the current list. + /// </summary> + /// <param name="aDroid"></param> + public void AddDroid(IDroid aDroid) { - - - + // If there is room for more items in array. + if (droidListSizeInt < lenghtOfArrayInt) + { + indexInt = 0; + + // While current spot is not empty; + while (droidCollection[indexInt] != null) + { + indexInt++; + } + + // Adds droid to first empty spot. + droidCollection[indexInt] = aDroid; + droidListSizeInt++; + } + else + { + ExpandArray(); + AddDroid(aDroid); + } } #endregion diff --git a/cis237assignment3/Droid_Astromech.cs b/cis237assignment3/Droid_Astromech.cs index c0ad91059771052dbd369a0da3f5c2d8e7672daa..40d037cd50f1693742ed401872015244042b1dcf 100644 --- a/cis237assignment3/Droid_Astromech.cs +++ b/cis237assignment3/Droid_Astromech.cs @@ -19,6 +19,9 @@ namespace cis237assignment3 protected bool hasFireExtinguisherBool; protected int numberOfShipsInt; + protected decimal fireExtinguisherDecimal; + protected decimal numberOfShipsDecimal; + #endregion @@ -49,6 +52,9 @@ namespace cis237assignment3 { HasFireExtinguisher = hasFireExtinguisher; NumberOfShips = numberOfShips; + numberOfItemsInt = 8; + + CreateDroid(); } #endregion @@ -73,11 +79,53 @@ namespace cis237assignment3 - #region Methods + #region Private Methods + + private void CalculateFireExtinguisherCost() + { + if (hasFireExtinguisherBool) + { + fireExtinguisherDecimal = costPerFeatureDecimal; + } + else + { + fireExtinguisherDecimal = 0; + } + } + + private void CalculateNumberOfShipsCost() + { + + } + + #endregion + + + + #region Protected Methods + protected override void CreateDroid() + { + base.CreateDroid(); + + + + + } + + #endregion + + + + #region Public Methods + + /// <summary> + /// Calculates total cost of a Astromech droid. + /// </summary> public override void CalculateTotalCost() { base.CalculateTotalCost(); + totalCostDecimal += fireExtinguisherDecimal; } /// <summary> @@ -93,9 +141,9 @@ namespace cis237assignment3 /// Full string for displaying of single droid spanning multiple lines. /// </summary> /// <returns>String of full Droid information.</returns> - public override string DisplayFullToString() + public override string DisplayLongToString() { - return base.DisplayFullToString() + Environment.NewLine + + return base.DisplayLongToString() + Environment.NewLine + "Fire Extinguisher: " + YesNoString(hasFireExtinguisherBool) + Environment.NewLine; } diff --git a/cis237assignment3/Droid_Generic.cs b/cis237assignment3/Droid_Generic.cs index c971ed02b27f5a8a7f839891283d6399fdfc593a..fca2b69dfcd00913e8a5712027ad8f7ea5acdb73 100644 --- a/cis237assignment3/Droid_Generic.cs +++ b/cis237assignment3/Droid_Generic.cs @@ -33,7 +33,9 @@ namespace cis237assignment3 protected string selectedModelString; protected decimal selectedModelDecimal; public static string MODEL_1_STRING = "TI-84"; - public static string MODEL_2_STRING = "TI-84"; + public static string MODEL_2_STRING = "CAT5"; + public static string MODEL_3_STRING = "M7"; + private decimal model1Decimal; private decimal model2Decimal; @@ -79,7 +81,11 @@ namespace cis237assignment3 public Droid_Generic(string material, string model, string color) : base(material, model, color) { + SelectedMaterial = material; + SelectedModel = model; + SelectedColor = color; + CreateDroid(); } #endregion @@ -88,7 +94,20 @@ namespace cis237assignment3 #region Properties + public string SelectedModel + { + set { selectedModelString = value; } + } + public string SelectedMaterial + { + set { selectedMaterialString = value; } + } + + public string SelectedColor + { + set { selectedColorString = value; } + } #endregion @@ -276,20 +295,32 @@ namespace cis237assignment3 return Convert.ToDecimal(centsDouble); } + protected virtual void CreateDroid() + { + selectedModelDecimal = 10; + selectedMaterialDecimal = 10; + selectedColorDecimal = 10; + + CalculateTotalCost(); + } + #endregion #region Public Methods + /// <summary> + /// Calculates total cost of a Generic droid. + /// </summary> public override void CalculateTotalCost() { totalCostDecimal = selectedModelDecimal + selectedMaterialDecimal + selectedColorDecimal; } - public override string DisplayShortToString() + public override string DisplayLongToString() { - return "aaa"; + return (materialString + " " + modelString + " : " + colorString).PadRight(30) + totalCostDecimal.ToString("C").PadLeft(10); } #endregion diff --git a/cis237assignment3/Droid_Janitor.cs b/cis237assignment3/Droid_Janitor.cs index d2631957515ad76c3a3a5775c7e24515444fb6c3..efd3e1d816a709738caecbf6b04cbb2992b017a7 100644 --- a/cis237assignment3/Droid_Janitor.cs +++ b/cis237assignment3/Droid_Janitor.cs @@ -19,6 +19,9 @@ namespace cis237assignment3 protected bool hasTrashCompactorBool; protected bool hasVacuumBool; + protected decimal trashCompactorDecimal; + protected decimal vacuumDecimal; + #endregion @@ -49,6 +52,9 @@ namespace cis237assignment3 { HasTrashCompactor = hasTrashCompactor; HasVacuum = hasVacuum; + numberOfItemsInt = 8; + + CreateDroid(); } #endregion @@ -73,11 +79,61 @@ namespace cis237assignment3 - #region Methods + #region Private Methods + + private void CalculateTrashCompactorCost() + { + if (hasTrashCompactorBool) + { + trashCompactorDecimal = costPerFeatureDecimal; + } + else + { + trashCompactorDecimal = 0; + } + } + + private void CalculateVacuumCost() + { + if (hasVacuumBool) + { + vacuumDecimal = costPerFeatureDecimal; + } + else + { + vacuumDecimal = 0; + } + } + + #endregion + + + + #region Protected Methods + protected override void CreateDroid() + { + base.CreateDroid(); + + CalculateTrashCompactorCost(); + CalculateVacuumCost(); + + CalculateTotalCost(); + } + + #endregion + + + + #region Public Methods + + /// <summary> + /// Calculates total cost of a Janitor droid. + /// </summary> public override void CalculateTotalCost() { base.CalculateTotalCost(); + totalCostDecimal += trashCompactorDecimal + vacuumDecimal; } /// <summary> @@ -93,9 +149,9 @@ namespace cis237assignment3 /// Full string for displaying of single droid spanning multiple lines. /// </summary> /// <returns>String of full Droid information.</returns> - public override string DisplayFullToString() + public override string DisplayLongToString() { - return base.DisplayFullToString() + Environment.NewLine + + return base.DisplayLongToString() + Environment.NewLine + "Trash Compactor: " + YesNoString(hasTrashCompactorBool) + Environment.NewLine + "Vacuum: " + YesNoString(hasVacuumBool); } diff --git a/cis237assignment3/Droid_Protocol.cs b/cis237assignment3/Droid_Protocol.cs index 4e5d5872f649f88cea7af6b61ee35571f34488e8..383a51238bbbb693307c81605d460bf249ddb541 100644 --- a/cis237assignment3/Droid_Protocol.cs +++ b/cis237assignment3/Droid_Protocol.cs @@ -51,6 +51,9 @@ namespace cis237assignment3 : base(material, model, color) { NumberOfLanguages = numberOfLanguages; + numberOfItemsInt = 4; + + CreateDroid(); } #endregion @@ -65,11 +68,6 @@ namespace cis237assignment3 get { return numberOfLanguagesInt; } } - public decimal TotalLanguageCost - { - get { return numberOfLanguagesInt; } - } - #endregion @@ -88,12 +86,30 @@ namespace cis237assignment3 + #region Protected methods + + protected override void CreateDroid() + { + base.CreateDroid(); + + CalculateLanguageCost(); + + CalculateTotalCost(); + } + + #endregion + + #region Public Methods + /// <summary> + /// Calculates total cost of a Protocol droid. + /// </summary> public override void CalculateTotalCost() { - base.CalculateTotalCost(); //+ totalLanguageDecimal; + base.CalculateTotalCost(); + totalCostDecimal += totalLanguageDecimal; } /// <summary> @@ -109,9 +125,9 @@ namespace cis237assignment3 /// Full string for displaying of single droid spanning multiple lines. /// </summary> /// <returns>String of full Droid information.</returns> - public override string DisplayFullToString() + public override string DisplayLongToString() { - return base.DisplayFullToString() + Environment.NewLine + + return base.DisplayLongToString() + Environment.NewLine + "Languages: " + numberOfLanguagesInt; } diff --git a/cis237assignment3/Droid_Utility.cs b/cis237assignment3/Droid_Utility.cs index 9ad038bbc67f74b62015822c1f217d1f3b798db1..d171cef8fb74f3cba2533e5c049d0ba851dfd4c3 100644 --- a/cis237assignment3/Droid_Utility.cs +++ b/cis237assignment3/Droid_Utility.cs @@ -20,6 +20,10 @@ namespace cis237assignment3 protected bool hasComputerConnectiontBool; protected bool hasArmBool; + protected decimal toolBoxDecimal; + protected decimal computerConnectionDecimal; + protected decimal armDecimal; + #endregion @@ -49,6 +53,9 @@ namespace cis237assignment3 HasToolBox = hasToolBoxBool; HasComputerConnection = hasComputerConnection; HasArm = hasArm; + numberOfItemsInt = 6; + + CreateDroid(); } #endregion @@ -79,6 +86,48 @@ namespace cis237assignment3 + #region Private Methods + + private void CalculateToolBoxCost() + { + if (hasToolBoxBool) + { + toolBoxDecimal = costPerFeatureDecimal; + } + else + { + toolBoxDecimal = 0; + } + } + + private void CalculateConnectionCost() + { + if (hasComputerConnectiontBool) + { + computerConnectionDecimal = costPerFeatureDecimal; + } + else + { + computerConnectionDecimal = 0; + } + } + + private void CalculateArmCost() + { + if (hasArmBool) + { + armDecimal = costPerFeatureDecimal; + } + else + { + armDecimal = 0; + } + } + + #endregion + + + #region Protected Methods /// <summary> @@ -102,15 +151,30 @@ namespace cis237assignment3 return displayString; } + protected override void CreateDroid() + { + base.CreateDroid(); + + CalculateToolBoxCost(); + CalculateConnectionCost(); + CalculateArmCost(); + + CalculateTotalCost(); + } + #endregion #region Public Methods + /// <summary> + /// Calculates total cost of a Utility droid. + /// </summary> public override void CalculateTotalCost() { base.CalculateTotalCost(); + totalCostDecimal += toolBoxDecimal + computerConnectionDecimal + armDecimal; } /// <summary> @@ -126,9 +190,9 @@ namespace cis237assignment3 /// Full string for displaying of single droid spanning multiple lines. /// </summary> /// <returns>String of full Droid information.</returns> - public override string DisplayFullToString() + public override string DisplayLongToString() { - return base.DisplayFullToString() + Environment.NewLine + + return base.DisplayLongToString() + Environment.NewLine + "Toolbox: " + YesNoString(hasArmBool) + Environment.NewLine + "Computer Connection: " + YesNoString(hasComputerConnectiontBool) + Environment.NewLine + "Arm: " + YesNoString(hasArmBool); diff --git a/cis237assignment3/IDroid.cs b/cis237assignment3/IDroid.cs index 076dcbea265d410bc4cf0f61990ac5a4ccb93313..39f4ee7cb97a9d50589295ce099b477b6aa4c54c 100644 --- a/cis237assignment3/IDroid.cs +++ b/cis237assignment3/IDroid.cs @@ -14,8 +14,23 @@ namespace cis237assignment3 /// </summary> interface IDroid { + /// <summary> + /// Calculates total cost of droid. + /// </summary> void CalculateTotalCost(); decimal TotalCost { get; set; } + + /// <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> + /// <returns>Full information regarding single droid.</returns> + string DisplayLongToString(); } } diff --git a/cis237assignment3/RunProgram.cs b/cis237assignment3/RunProgram.cs index c5dbdcf6dfe8b4b1103d19a4967ff38ff06036de..2bf00ae0e42d7945cb06c55f716534972f3ea1b7 100644 --- a/cis237assignment3/RunProgram.cs +++ b/cis237assignment3/RunProgram.cs @@ -17,6 +17,9 @@ namespace cis237assignment3 private bool runProgram; private bool menusBool; // Used to exit back to main menu if user decides to. True to stay in menus. False if user typed to exit. + string displayString; + + private DroidCollection droidCollection; // Variables for getting/saving user input. private string userInputString; @@ -67,6 +70,7 @@ namespace cis237assignment3 /// </summary> private void Run() { + ResetList(); while (runProgram) { // Resets/initializes menu bool to allow user to stay in menus. @@ -78,6 +82,9 @@ namespace cis237assignment3 } } + /// <summary> + /// Handles Main Menu Selection. + /// </summary> private void MainMenuSelection() { switch (userInputString) @@ -92,36 +99,67 @@ namespace cis237assignment3 DisplaySingle(); break; case "4": + break; + case "5": Exit(); break; case "esc": Exit(); break; default: + UserInterface.DisplayError("Invalid selection."); break; } } + /// <summary> + /// User selection to add a new droid to list. + /// </summary> private void PurchaseDroid() { + UserInterface.ClearDisplayLine(); DroidTypeSelection(); } + /// <summary> + /// Displays information for full droid list. + /// </summary> private void DisplayReciept() { - + UserInterface.ClearDisplayLine(); + DisplayFullList(); } + /// <summary> + /// Displays information for single droid. + /// </summary> private void DisplaySingle() { + UserInterface.ClearDisplayLine(); + //DisplaySingleDroid(); + } + /// <summary> + /// Creates new android list and removes all information pertaining to old one. + /// </summary> + private void ResetList() + { + UserInterface.ClearDisplayLine(); + UserInterface.ClearList(); + droidCollection = new DroidCollection(); } + /// <summary> + /// Exits program. + /// </summary> private void Exit() { runProgram = false; } + /// <summary> + /// Handles user selection of droid Type. + /// </summary> private void DroidTypeSelection() { UserInterface.Menus.DisplayTypeSelectionMenu(); @@ -142,8 +180,11 @@ namespace cis237assignment3 PurchaseAstromech(); break; case "esc": + UserInterface.ClearDisplayLine(); break; default: + UserInterface.DisplayError("Invalid selection."); + DroidTypeSelection(); break; } } @@ -155,14 +196,17 @@ namespace cis237assignment3 { if (menusBool) { + UserInterface.ClearDisplayLine(); ModelSelection(); } if (menusBool) { + UserInterface.ClearDisplayLine(); MaterialSelection(); } if (menusBool) { + UserInterface.ClearDisplayLine(); ColorSelection(); } @@ -175,15 +219,19 @@ namespace cis237assignment3 { if (menusBool) { + UserInterface.ClearDisplayLine(); PurchaseGeneric(); } if (menusBool) { + UserInterface.ClearDisplayLine(); LanguageSelection(); } if (menusBool) { + UserInterface.ClearDisplayLine(); IDroid aDroid = new Droid_Protocol(selectedMaterialString, selectedModelString, selectedColorString, selectedLanguageInt); + droidCollection.AddDroid(aDroid); } } @@ -194,23 +242,29 @@ namespace cis237assignment3 { if (menusBool) { + UserInterface.ClearDisplayLine(); PurchaseGeneric(); } if (menusBool) { + UserInterface.ClearDisplayLine(); ToolBoxSelection(); } if (menusBool) { + UserInterface.ClearDisplayLine(); CompConnectionSelection(); } if (menusBool) { + UserInterface.ClearDisplayLine(); ArmSelection(); } if (menusBool) { + UserInterface.ClearDisplayLine(); IDroid aDroid = new Droid_Utility(selectedMaterialString, selectedModelString, selectedColorString, toolBoxBool, computerConnectionBool, armBool); + droidCollection.AddDroid(aDroid); } } @@ -221,19 +275,24 @@ namespace cis237assignment3 { if (menusBool) { + UserInterface.ClearDisplayLine(); PurchaseUtility(); } if (menusBool) { + UserInterface.ClearDisplayLine(); TrashCompactorSelection(); } if (menusBool) { + UserInterface.ClearDisplayLine(); VacuumSelection(); } if (menusBool) { + UserInterface.ClearDisplayLine(); IDroid aDroid = new Droid_Janitor(selectedMaterialString, selectedModelString, selectedColorString, toolBoxBool, computerConnectionBool, armBool, trashCompactorBool, vacuumBool); + droidCollection.AddDroid(aDroid); } } @@ -244,19 +303,24 @@ namespace cis237assignment3 { if (menusBool) { + UserInterface.ClearDisplayLine(); PurchaseUtility(); } if (menusBool) { + UserInterface.ClearDisplayLine(); FireExtinguisherSelection(); } if (menusBool) { + UserInterface.ClearDisplayLine(); NumberOfShipsSelection(); } if (menusBool) { + UserInterface.ClearDisplayLine(); IDroid aDroid = new Droid_Astromech(selectedMaterialString, selectedModelString, selectedColorString, toolBoxBool, computerConnectionBool, armBool, fireExtinguisherBool, selectedNumberOfShipsInt); + droidCollection.AddDroid(aDroid); } } @@ -267,7 +331,7 @@ namespace cis237assignment3 /// </summary> private void ModelSelection() { - UserInterface.Menus.DisplayModelSelectionMenu(Droid_Generic.MODEL_1_STRING, Droid_Generic.MODEL_2_STRING); + UserInterface.Menus.DisplayModelSelectionMenu(Droid_Generic.MODEL_1_STRING, Droid_Generic.MODEL_2_STRING, Droid_Generic.MODEL_3_STRING); userInputString = UserInterface.GetUserInput(); switch (userInputString) @@ -279,13 +343,15 @@ namespace cis237assignment3 selectedModelString = Droid_Generic.MODEL_2_STRING; break; case "3": - break; - case "4": + selectedModelString = Droid_Generic.MODEL_3_STRING; break; case "esc": + UserInterface.ClearDisplayLine(); menusBool = false; break; default: + UserInterface.DisplayError("Invalid Selection."); + ModelSelection(); break; } } @@ -316,9 +382,12 @@ namespace cis237assignment3 selectedMaterialString = Droid_Generic.MATERIAL_5_STRING; break; case "esc": + UserInterface.ClearDisplayLine(); menusBool = false; break; default: + UserInterface.DisplayError("Invalid Selection."); + MaterialSelection(); break; } } @@ -349,9 +418,12 @@ namespace cis237assignment3 selectedColorString = Droid_Generic.COLOR_5_STRING; break; case "esc": + UserInterface.ClearDisplayLine(); menusBool = false; break; default: + UserInterface.DisplayError("Invalid Selection"); + ColorSelection(); break; } } @@ -379,8 +451,13 @@ namespace cis237assignment3 selectedLanguageInt = Droid_Protocol.LANGUAGE_SELECTION_4; break; case "esc": + UserInterface.ClearDisplayLine(); menusBool = false; break; + default: + UserInterface.DisplayError("Invalid Selection"); + LanguageSelection(); + break; } } @@ -401,8 +478,13 @@ namespace cis237assignment3 toolBoxBool = false; break; case "esc": + UserInterface.ClearDisplayLine(); menusBool = false; break; + default: + UserInterface.DisplayError("Invalid Selection."); + ToolBoxSelection(); + break; } } @@ -423,8 +505,13 @@ namespace cis237assignment3 computerConnectionBool = false; break; case "esc": + UserInterface.ClearDisplayLine(); menusBool = false; break; + default: + UserInterface.DisplayError("Invalid Selection."); + CompConnectionSelection(); + break; } } @@ -445,8 +532,13 @@ namespace cis237assignment3 armBool = false; break; case "esc": + UserInterface.ClearDisplayLine(); menusBool = false; break; + default: + UserInterface.DisplayError("Invalid Selection."); + ArmSelection(); + break; } } @@ -467,8 +559,13 @@ namespace cis237assignment3 trashCompactorBool = false; break; case "esc": + UserInterface.ClearDisplayLine(); menusBool = false; break; + default: + UserInterface.DisplayError("Invalid Selection."); + TrashCompactorSelection(); + break; } } @@ -489,8 +586,13 @@ namespace cis237assignment3 vacuumBool = false; break; case "esc": + UserInterface.ClearDisplayLine(); menusBool = false; break; + default: + UserInterface.DisplayError("Invalid Selection."); + VacuumSelection(); + break; } } @@ -511,8 +613,13 @@ namespace cis237assignment3 fireExtinguisherBool = false; break; case "esc": + UserInterface.ClearDisplayLine(); menusBool = false; break; + default: + UserInterface.DisplayError("Invalid Selection."); + FireExtinguisherSelection(); + break; } } @@ -542,6 +649,7 @@ namespace cis237assignment3 } else { + UserInterface.ClearDisplayLine(); menusBool = false; } } @@ -549,6 +657,35 @@ 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 1127bb1a0383191dd5909ba15d3bc5829b45134b..77a116ddb6e03ea9393eb6d494de849d5d2bf1df 100644 --- a/cis237assignment3/UserInterface.cs +++ b/cis237assignment3/UserInterface.cs @@ -13,7 +13,7 @@ namespace cis237assignment3 /// Having one class handle everything UI helps create consistency. /// /// Note: Having the interface methods accept parameters instead of directly calling static variables prevents the - /// interface from having to directly access multiple classes itself. Only RunProgram will access multiple classes + /// interface from having to directly access multiple classes itself. Preferably, only RunProgram will access multiple classes /// due to it being the "binding" between all the classes. /// /// Instead, Interface just tells RunProgram what it needs to work and never deals directly with other classes. @@ -23,6 +23,7 @@ namespace cis237assignment3 #region Variables private static string userInputString; + private static int previousListSizeInt; #endregion @@ -76,6 +77,11 @@ namespace cis237assignment3 SetMenuCursor(); } + private static void ResetDroidDisplay() + { + + } + #endregion @@ -99,15 +105,24 @@ namespace cis237assignment3 return userInputString; } - + /// <summary> + /// Displays a line to console. + /// </summary> + /// <param name="displayString">String to display.</param> public static void DisplayLine(string displayString) { + ClearDisplayLine(); Console.WriteLine(displayString); } - + /// <summary> + /// Displays an error line to console. + /// </summary> + /// <param name="displayString">String of error to display.</param> public static void DisplayError(string displayString) { + ClearDisplayLine(); + Console.SetCursorPosition(1, 8); Console.ForegroundColor = ConsoleColor.Red; @@ -115,9 +130,13 @@ namespace cis237assignment3 Console.ForegroundColor = ConsoleColor.Gray; } + /// <summary> + /// Clears display line from console. + /// </summary> public static void ClearDisplayLine() { - + Console.SetCursorPosition(0, 8); + Console.WriteLine("".PadRight(Console.WindowWidth - 1)); } /// <summary> @@ -162,7 +181,7 @@ namespace cis237assignment3 /// </summary> /// <param name="model1">Droid Model 1.</param> /// <param name="model2">Droid Model 2.</param> - public static void DisplayModelSelectionMenu(string model1, string model2) + public static void DisplayModelSelectionMenu(string model1, string model2, string model3) { ResetMenuDisplay(); @@ -170,7 +189,8 @@ namespace cis237assignment3 " Select a Droid Model: " + Environment.NewLine + "" + Environment.NewLine + " 1) " + model1 + Environment.NewLine + - " 2) " + model2 + Environment.NewLine); + " 2) " + model2 + Environment.NewLine + + " 3) " + model3 + Environment.NewLine); } /// <summary> @@ -334,6 +354,46 @@ namespace cis237assignment3 } } + /// <summary> + /// Displays list of droids to console. + /// </summary> + /// <param name="displayString">String of droids to display.</param> + /// <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.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) + { + Console.WriteLine("".PadRight(Console.WindowWidth - 1)); + index++; + } + + } + } + #endregion }