From 70b8ac4533f5e805ed2c446e34785ec7ee2dc770 Mon Sep 17 00:00:00 2001 From: Brandon Rodriguez <brodriguez8774@mail.kvcc.edu> Date: Sun, 8 Nov 2015 13:03:24 -0500 Subject: [PATCH] Import of assignment 3. --- cis237assignment4/AstromechDroid.cs | 67 -- cis237assignment4/Droid.cs | 208 ++++-- cis237assignment4/DroidCollection.cs | 184 +++-- cis237assignment4/Droid_Astromech.cs | 154 +++++ cis237assignment4/Droid_Janitor.cs | 161 +++++ cis237assignment4/Droid_Protocol.cs | 136 ++++ cis237assignment4/Droid_Utility.cs | 203 ++++++ cis237assignment4/IDroid.cs | 39 +- cis237assignment4/IDroidCollection.cs | 21 - cis237assignment4/JanitorDroid.cs | 55 -- cis237assignment4/Program.cs | 48 +- cis237assignment4/ProtocolDroid.cs | 40 -- cis237assignment4/RunProgram.cs | 754 +++++++++++++++++++++ cis237assignment4/UserInterface.cs | 594 +++++++++------- cis237assignment4/UtilityDroid.cs | 72 -- cis237assignment4/cis237assignment4.csproj | 10 +- 16 files changed, 2052 insertions(+), 694 deletions(-) delete mode 100644 cis237assignment4/AstromechDroid.cs create mode 100644 cis237assignment4/Droid_Astromech.cs create mode 100644 cis237assignment4/Droid_Janitor.cs create mode 100644 cis237assignment4/Droid_Protocol.cs create mode 100644 cis237assignment4/Droid_Utility.cs delete mode 100644 cis237assignment4/IDroidCollection.cs delete mode 100644 cis237assignment4/JanitorDroid.cs delete mode 100644 cis237assignment4/ProtocolDroid.cs create mode 100644 cis237assignment4/RunProgram.cs delete mode 100644 cis237assignment4/UtilityDroid.cs diff --git a/cis237assignment4/AstromechDroid.cs b/cis237assignment4/AstromechDroid.cs deleted file mode 100644 index 4863318..0000000 --- a/cis237assignment4/AstromechDroid.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace cis237assignment4 -{ - //Class that inherits from the Utility Droid - class AstromechDroid : UtilityDroid - { - //class level variables unique to this class. Set as protected so children classes can access them. - protected bool hasFireExtinguisher; - protected int numberOfShips; - - //Protected constant for the cost per ship. Children can access this too. - protected decimal COST_PER_SHIP = 45.00m; - - //Constructor that uses the Base Constuctor to do most of the work. - public AstromechDroid(string Material, string Model, string Color, - bool HasToolbox, bool HasComputerConnection, bool HasArm, bool HasFireExtinquisher, int NumberOfShips) : - base(Material, Model, Color, HasToolbox, HasComputerConnection, HasArm) - { - //Assign the values for the constructor that are not handled by the base constructor - this.hasFireExtinguisher = HasFireExtinquisher; - this.numberOfShips = NumberOfShips; - } - - //Overridden method to calculate the cost of options. Uses the base class to do some of the calculations - protected override decimal CalculateCostOfOptions() - { - decimal optionsCost = 0; - - optionsCost += base.CalculateCostOfOptions(); - - if (hasFireExtinguisher) - { - optionsCost += COST_PER_OPTION; - } - - return optionsCost; - } - - //Protected virtual method that can be overriden in child classes. - //Caclulates the cost of ships. - protected virtual decimal CalculateCostOfShips() - { - return COST_PER_SHIP * numberOfShips; - } - - //Overriden method to calculate the total cost. Uses work from the base class to achive the answer. - public override void CalculateTotalCost() - { - this.CalculateBaseCost(); - - this.totalCost = this.baseCost + this.CalculateCostOfOptions() + this.CalculateCostOfShips(); - } - - //Overriden ToString method to output the information for this droid. Uses work done in the base class - public override string ToString() - { - return base.ToString() + - "Has Fire Extinguisher: " + this.hasFireExtinguisher + Environment.NewLine + - "Number Of Ships: " + this.numberOfShips + Environment.NewLine; - } - } -} diff --git a/cis237assignment4/Droid.cs b/cis237assignment4/Droid.cs index 97e0ea5..0e16ea7 100644 --- a/cis237assignment4/Droid.cs +++ b/cis237assignment4/Droid.cs @@ -1,70 +1,188 @@ -using System; +// Brandon Rodriguez + +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace cis237assignment4 +namespace cis237assignment3 { - //Abstract class that implements the IDroid interface + /// <summary> + /// Abstract class for Droids. Handles "higher level" thinking/rules. + /// Derives from IDroid interface. + /// </summary> abstract class Droid : IDroid { - //some protected variables for the class - protected string material; - protected string model; - protected string color; + #region Variables + + 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; // Number of individual items influencing droid price. + + + // All the necessary variables for material selection. + protected string selectedMaterialString; + private decimal selectedMaterialDecimal; + public static string MATERIAL_1_STRING = "Tin"; + public static string MATERIAL_2_STRING = "Steel"; + public static string MATERIAL_3_STRING = "Titanium"; + public static string MATERIAL_4_STRING = "Mythril"; + public static string MATERIAL_5_STRING = "Unobtanium"; + + // 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"; + public static string MODEL_3_STRING = "M7"; + + // All the necessary variables for color selection. + protected string selectedColorString; + private decimal selectedColorDecimal; + public static string COLOR_1_STRING = "White"; + public static string COLOR_2_STRING = "Black"; + public static string COLOR_3_STRING = "Blue"; + public static string COLOR_4_STRING = "Red"; + public static string COLOR_5_STRING = "Green"; + + #endregion + + + + #region Constructor + + /// <summary> + /// Base constructor. + /// </summary> + public Droid() + { + + } + + /// <summary> + /// + /// </summary> + /// <param name="material"></param> + /// <param name="model"></param> + /// <param name="color"></param> + public Droid(string material, string model, string color) + { + Material = material; + Model = model; + Color = color; + } + + #endregion + + + + #region Properties + + public string Material + { + set { selectedMaterialString = value; } + get { return selectedMaterialString; } + } + + public string Model + { + set { selectedModelString = value; } + get { return selectedModelString; } + } - protected decimal baseCost; - protected decimal totalCost; + public string Color + { + set { selectedColorString = value; } + get { return selectedColorString; } + } + + public decimal BaseCost + { + set { baseCostDecimal = value; } + get { return baseCostDecimal; } + } - //The public property for TotalCost public decimal TotalCost { - get { return totalCost; } - set { totalCost = value; } + set { totalCostDecimal = value; } + get { return totalCostDecimal; } + } + + public int NumberOfItems + { + get { return numberOfItemsInt; } + } + + #endregion + + + + #region Protected Methods + + /// <summary> + /// Creates string for droid type. Needed due to how inheritance works. + /// </summary> + /// <returns>String of droid's type.</returns> + protected abstract string TypeString(); + + #endregion + + + + #region Public Methods + + /// <summary> + /// Calculates total cost of droid. + /// </summary> + public virtual void CalculateTotalCost() + { + totalCostDecimal = baseCostDecimal; } - //Constructor that takes the main 3 parameters shared amongst all 4 types of droids - public Droid(string Material, string Model, string Color) + /// <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() { - this.material = Material; - this.model = Model; - this.color = Color; + baseCostDecimal = selectedModelDecimal + selectedMaterialDecimal + selectedColorDecimal; } - //Virtual method that can be overridden in the derived classes if needed. - //This implementation calculates the cost based on the material used for the droid - protected virtual void CalculateBaseCost() + /// <summary> + /// Calculates individual feature costs of droid. + /// </summary> + public virtual void CalculateFeatures() { - switch (this.material) - { - case "Carbonite": - this.baseCost = 100.00m; - break; - - case "Vanadium": - this.baseCost = 120.00m; - break; - - case "Quadranium": - this.baseCost = 150.00m; - break; - - default: - this.baseCost = 50.00m; - break; - } + selectedModelDecimal = 10; + selectedMaterialDecimal = 10; + selectedColorDecimal = 10; + + CalculateBaseCost(); } - //Abstract method that MUST be overriden in the derived class to calculate the total cost - public abstract void CalculateTotalCost(); + /// <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 TypeString().PadRight(11) + (selectedMaterialString + " ").PadRight(11) + (selectedModelString + " ").PadRight(10) + (selectedColorString + " ").PadRight(10) + totalCostDecimal.ToString("C").PadLeft(10) + Environment.NewLine; + } - //Overriden toString method that will return a string representing the basic information for any droid - public override string ToString() + /// <summary> + /// Full string for displaying of single droid spanning multiple lines. + /// </summary> + /// <returns>Full information regarding single droid.</returns> + public virtual string DisplayLongToString() { - return "Material: " + this.material + Environment.NewLine + - "Model: " + this.model + Environment.NewLine + - "Color: " + this.color + 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/cis237assignment4/DroidCollection.cs b/cis237assignment4/DroidCollection.cs index 523a977..205cc8a 100644 --- a/cis237assignment4/DroidCollection.cs +++ b/cis237assignment4/DroidCollection.cs @@ -1,128 +1,124 @@ -using System; +// Brandon Rodriguez + +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace cis237assignment4 +namespace cis237assignment3 { - //Class Droid Collection implements the IDroidCollection interface. - //All methods declared in the Interface must be implemented in this class - class DroidCollection : IDroidCollection + class DroidCollection { - //Private variable to hold the collection of droids + #region Variables + private IDroid[] droidCollection; - //Private variable to hold the length of the Collection - private int lengthOfCollection; + 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 + + - //Constructor that takes in the size of the collection. - //It sets the size of the internal array that will be used. - //It also sets the length of the collection to zero since nothing is added yet. - public DroidCollection(int sizeOfCollection) + #region Constructor + + /// <summary> + /// Base constructor. + /// </summary> + public DroidCollection() { - //Make new array for the collection - droidCollection = new IDroid[sizeOfCollection]; - //set length of collection to 0 - lengthOfCollection = 0; + droidListSizeInt = 0; + lenghtOfArrayInt = 10; + droidCollection = new Droid[lenghtOfArrayInt]; } - //The Add method for a Protocol Droid. The parameters passed in match those needed for a protocol droid - public bool Add(string Material, string Model, string Color, int NumberOfLanguages) + #endregion + + + + #region Properties + + public int DroidListSize { - //If there is room to add the new droid - if (lengthOfCollection < (droidCollection.Length - 1)) - { - //Add the new droid. Note that the droidCollection is of type IDroid, but the droid being stored is - //of type Protocol Droid. This is okay because of Polymorphism. - droidCollection[lengthOfCollection] = new ProtocolDroid(Material, Model, Color, NumberOfLanguages); - //Increase the length of the collection - lengthOfCollection++; - //return that it was successful - return true; - } - //Else, there is no room for the droid - else - { - //Return false - return false; - } + get { return droidListSizeInt; } } - //The Add method for a Utility droid. Code is the same as the above method except for the type of droid being created. - //The method can be redeclared as Add since it takes different parameters. This is called method overloading. - public bool Add(string Material, string Model, string Color, bool HasToolBox, bool HasComputerConnection, bool HasArm) + public IDroid[] DroidList { - if (lengthOfCollection < (droidCollection.Length - 1)) - { - droidCollection[lengthOfCollection] = new UtilityDroid(Material, Model, Color, HasToolBox, HasComputerConnection, HasArm); - lengthOfCollection++; - return true; - } - else - { - return false; - } + get { return droidCollection; } } - //The Add method for a Janitor droid. Code is the same as the above method except for the type of droid being created. - public bool Add(string Material, string Model, string Color, bool HasToolBox, bool HasComputerConnection, bool HasArm, bool HasTrashCompactor, bool HasVaccum) + #endregion + + + + #region Private Methods + + /// <summary> + /// Expands array to be one and a half times current size. + /// </summary> + public void ExpandArray() { - if (lengthOfCollection < (droidCollection.Length - 1)) - { - droidCollection[lengthOfCollection] = new JanitorDroid(Material, Model, Color, HasToolBox, HasComputerConnection, HasArm, HasTrashCompactor, HasVaccum); - lengthOfCollection++; - return true; - } - else + // Set list size to be one and a half times the size of current. + lenghtOfArrayInt = droidListSizeInt + (droidListSizeInt / 2); + tempArray = new Droid[lenghtOfArrayInt]; + + indexInt = 0; + // While not through entire list of droids yet. + while (indexInt < droidListSizeInt) { - return false; + // If reached a null space, force exit of while loop. + if (droidCollection[indexInt] == null) + { + indexInt = droidListSizeInt; + } + else + { + tempArray[indexInt] = droidCollection[indexInt]; + indexInt++; + } + droidCollection = tempArray; } } - //The Add method for a Astromech droid. Code is the same as the above method except for the type of droid being created. - public bool Add(string Material, string Model, string Color, bool HasToolBox, bool HasComputerConnection, bool HasArm, bool HasFireExtinguisher, int NumberOfShips) + #endregion + + + + #region Public Methods + + /// <summary> + /// Adds a single droid to the current list. + /// </summary> + /// <param name="aDroid"></param> + public void AddDroid(IDroid aDroid) { - if (lengthOfCollection < (droidCollection.Length - 1)) + // If there is room for more items in array. + if (droidListSizeInt < lenghtOfArrayInt) { - droidCollection[lengthOfCollection] = new AstromechDroid(Material, Model, Color, HasToolBox, HasComputerConnection, HasArm, HasFireExtinguisher, NumberOfShips); - lengthOfCollection++; - return true; + indexInt = 0; + + // While current spot is not empty; + while (droidCollection[indexInt] != null) + { + indexInt++; + } + + // Adds droid to first empty spot. + droidCollection[indexInt] = aDroid; + droidListSizeInt++; } else { - return false; + ExpandArray(); + AddDroid(aDroid); } } - //The last method that must be implemented due to implementing the interface. - //This method iterates through the list of droids and creates a printable string that could - //be either printed to the screen, or sent to a file. - public string GetPrintString() - { - //Declare the return string - string returnString = ""; - - //For each droid in the droidCollection - foreach (IDroid droid in droidCollection) - { - //If the droid is not null (It might be since the array may not be full) - if (droid != null) - { - //Calculate the total cost of the droid. Since we are using inheritance and Polymorphism - //the program will automatically know which version of CalculateTotalCost it needs to call based - //on which particular type it is looking at during the foreach loop. - droid.CalculateTotalCost(); - //Create the string now that the total cost has been calculated - returnString += "******************************" + Environment.NewLine; - returnString += droid.ToString() + Environment.NewLine + Environment.NewLine; - returnString += "Total Cost: " + droid.TotalCost.ToString("C") + Environment.NewLine; - returnString += "******************************" + Environment.NewLine; - returnString += Environment.NewLine; - } - } + #endregion - //return the completed string - return returnString; - } } } diff --git a/cis237assignment4/Droid_Astromech.cs b/cis237assignment4/Droid_Astromech.cs new file mode 100644 index 0000000..a215128 --- /dev/null +++ b/cis237assignment4/Droid_Astromech.cs @@ -0,0 +1,154 @@ +// Brandon Rodriguez + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace cis237assignment3 +{ + /// <summary> + /// Class for Droids of type Astromech. + /// Inherits from Utility which inherits from Droid. + /// </summary> + class Droid_Astromech : Droid_Utility + { + #region Variables + + protected bool hasFireExtinguisherBool; + protected int numberOfShipsInt; + + protected decimal fireExtinguisherDecimal; + protected decimal numberOfShipsDecimal; + + #endregion + + + + #region Constructor + + /// <summary> + /// Base constructor. + /// </summary> + public Droid_Astromech() + { + + } + + /// <summary> + /// + /// </summary> + /// <param name="material"></param> + /// <param name="model"></param> + /// <param name="color"></param> + /// <param name="hasToolBox"></param> + /// <param name="hasComputerConnection"></param> + /// <param name="hasArm"></param> + /// <param name="hasFireExtinguisher"></param> + /// <param name="numberOfShips"></param> + public Droid_Astromech(string material, string model, string color, bool hasToolBox, bool hasComputerConnection, bool hasArm, bool hasFireExtinguisher, int numberOfShips) + : base(material, model, color, hasToolBox, hasComputerConnection, hasArm) + { + HasFireExtinguisher = hasFireExtinguisher; + NumberOfShips = numberOfShips; + numberOfItemsInt = 8; + } + + #endregion + + + + #region Properties + + public bool HasFireExtinguisher + { + set { hasFireExtinguisherBool = value; } + get { return hasFireExtinguisherBool; } + } + + public int NumberOfShips + { + set { numberOfShipsInt = value; } + get { return numberOfShipsInt; } + } + + #endregion + + + + #region Private Methods + + private void CalculateFireExtinguisherCost() + { + if (hasFireExtinguisherBool) + { + fireExtinguisherDecimal = costPerFeatureDecimal; + } + else + { + fireExtinguisherDecimal = 0; + } + } + + private void CalculateNumberOfShipsCost() + { + numberOfShipsDecimal = numberOfShipsInt * costPerFeatureDecimal; + } + + #endregion + + + + #region Protected Methods + + /// <summary> + /// Creates string for droid type. Needed due to how inheritance works. + /// </summary> + /// <returns>String of droid's type.</returns> + protected override string TypeString() + { + return "Astromech "; + } + + #endregion + + + + #region Public Methods + + /// <summary> + /// Calculates total cost of a Astromech droid. + /// </summary> + public override void CalculateTotalCost() + { + base.CalculateTotalCost(); + totalCostDecimal += fireExtinguisherDecimal + numberOfShipsDecimal; + } + + /// <summary> + /// Calculates individual feature costs of droid. + /// </summary> + public override void CalculateFeatures() + { + base.CalculateFeatures(); + + CalculateFireExtinguisherCost(); + CalculateNumberOfShipsCost(); + } + + /// <summary> + /// Full string for displaying of single droid spanning multiple lines. + /// </summary> + /// <returns>Full information regarding single droid.</returns> + public override string DisplayLongToString() + { + 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/cis237assignment4/Droid_Janitor.cs b/cis237assignment4/Droid_Janitor.cs new file mode 100644 index 0000000..15f4fd8 --- /dev/null +++ b/cis237assignment4/Droid_Janitor.cs @@ -0,0 +1,161 @@ +// Brandon Rodriguez + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace cis237assignment3 +{ + /// <summary> + /// Class for Droids of type Janitor. + /// Inherits from Utility which inherits from Droid. + /// </summary> + class Droid_Janitor : Droid_Utility + { + #region Variables + + protected bool hasTrashCompactorBool; + protected bool hasVacuumBool; + + protected decimal trashCompactorDecimal; + protected decimal vacuumDecimal; + + #endregion + + + + #region Constructor + + /// <summary> + /// Base constructor. + /// </summary> + public Droid_Janitor() + { + + } + + /// <summary> + /// + /// </summary> + /// <param name="material"></param> + /// <param name="model"></param> + /// <param name="color"></param> + /// <param name="hasToolBox"></param> + /// <param name="hasComputerConnection"></param> + /// <param name="hasArm"></param> + /// <param name="hasTrashCompactor"></param> + /// <param name="hasVacuum"></param> + public Droid_Janitor(string material, string model, string color, bool hasToolBox, bool hasComputerConnection, bool hasArm, bool hasTrashCompactor, bool hasVacuum) + : base(material, model, color, hasToolBox, hasComputerConnection, hasArm) + { + HasTrashCompactor = hasTrashCompactor; + HasVacuum = hasVacuum; + numberOfItemsInt = 8; + } + + #endregion + + + + #region Properties + + public bool HasTrashCompactor + { + set { hasTrashCompactorBool = value; } + get { return hasTrashCompactorBool; } + } + + public bool HasVacuum + { + set { hasVacuumBool = value; } + get { return hasVacuumBool; } + } + + #endregion + + + + #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 + + /// <summary> + /// Creates string for droid type. Needed due to how inheritance works. + /// </summary> + /// <returns>String of droid's type.</returns> + protected override string TypeString() + { + return "Janitor "; + } + + #endregion + + + + #region Public Methods + + /// <summary> + /// Calculates total cost of a Janitor droid. + /// </summary> + public override void CalculateTotalCost() + { + base.CalculateTotalCost(); + totalCostDecimal += trashCompactorDecimal + vacuumDecimal; + } + + /// <summary> + /// Calculates individual feature costs of droid. + /// </summary> + public override void CalculateFeatures() + { + base.CalculateFeatures(); + + CalculateTrashCompactorCost(); + CalculateVacuumCost(); + } + + /// <summary> + /// Full string for displaying of single droid spanning multiple lines. + /// </summary> + /// <returns>Full information regarding single droid.</returns> + public override string DisplayLongToString() + { + 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/cis237assignment4/Droid_Protocol.cs b/cis237assignment4/Droid_Protocol.cs new file mode 100644 index 0000000..f492d49 --- /dev/null +++ b/cis237assignment4/Droid_Protocol.cs @@ -0,0 +1,136 @@ +// Brandon Rodriguez + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace cis237assignment3 +{ + /// <summary> + /// Class for Droids of type Protocol. + /// Inherits only from Droid. + /// </summary> + class Droid_Protocol : Droid + { + #region Variables + + protected int numberOfLanguagesInt; + protected const decimal COST_PER_LANGUAGE = 1; // Temp cost placeholder. + protected decimal totalLanguageDecimal; + + // Language selection constants + public const int LANGUAGE_SELECTION_1 = 1; + public const int LANGUAGE_SELECTION_2 = 3; + public const int LANGUAGE_SELECTION_3 = 7; + public const int LANGUAGE_SELECTION_4 = 15; + + #endregion + + + + #region Constructor + + /// <summary> + /// Base constructor. + /// </summary> + public Droid_Protocol() + { + + } + + /// <summary> + /// + /// </summary> + /// <param name="material"></param> + /// <param name="model"></param> + /// <param name="color"></param> + /// <param name="numberOfLanguages"></param> + public Droid_Protocol(string material, string model, string color, int numberOfLanguages) + : base(material, model, color) + { + NumberOfLanguages = numberOfLanguages; + numberOfItemsInt = 4; + } + + #endregion + + + + #region Properties + + public int NumberOfLanguages + { + set { numberOfLanguagesInt = value; } + get { return numberOfLanguagesInt; } + } + + #endregion + + + + #region Private Methods + + /// <summary> + /// Determines total language cost for droid. + /// </summary> + private void CalculateLanguageCost() + { + totalLanguageDecimal = numberOfLanguagesInt * COST_PER_LANGUAGE; + } + + #endregion + + + + #region Protected methods + + /// <summary> + /// Creates string for droid type. Needed due to how inheritance works. + /// </summary> + /// <returns>String of droid's type.</returns> + protected override string TypeString() + { + return "Protocol "; + } + + #endregion + + + + #region Public Methods + + /// <summary> + /// Calculates total cost of a Protocol droid. + /// </summary> + public override void CalculateTotalCost() + { + base.CalculateTotalCost(); + totalCostDecimal += totalLanguageDecimal; + } + + /// <summary> + /// Calculates individual feature costs of droid. + /// </summary> + public override void CalculateFeatures() + { + base.CalculateFeatures(); + + CalculateLanguageCost(); + } + + /// <summary> + /// Full string for displaying of single droid spanning multiple lines. + /// </summary> + /// <returns>Full information regarding single droid.</returns> + public override string DisplayLongToString() + { + return base.DisplayLongToString() + + "".PadRight(5) + "Languages: ".PadRight(25) + numberOfLanguagesInt.ToString().PadRight(17) + totalLanguageDecimal.ToString("C").PadLeft(10) + Environment.NewLine; + } + + #endregion + + } +} diff --git a/cis237assignment4/Droid_Utility.cs b/cis237assignment4/Droid_Utility.cs new file mode 100644 index 0000000..a76a9fb --- /dev/null +++ b/cis237assignment4/Droid_Utility.cs @@ -0,0 +1,203 @@ +// Brandon Rodriguez + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace cis237assignment3 +{ + /// <summary> + /// Class for Droids of type Utility. + /// Inherits only from Droid. + /// </summary> + class Droid_Utility : Droid + { + #region Variables + + protected bool hasToolBoxBool; + protected bool hasComputerConnectiontBool; + protected bool hasArmBool; + + protected decimal toolBoxDecimal; + protected decimal computerConnectionDecimal; + protected decimal armDecimal; + + #endregion + + + + #region Constructor + + /// <summary> + /// Base constructor. + /// </summary> + public Droid_Utility() + { + + } + + /// <summary> + /// + /// </summary> + /// <param name="material"></param> + /// <param name="model"></param> + /// <param name="color"></param> + /// <param name="hasToolbox"></param> + /// <param name="hasComputerConnection"></param> + /// <param name="hasArm"></param> + public Droid_Utility(string material, string model, string color, bool hasToolBox, bool hasComputerConnection, bool hasArm) + : base(material, model, color) + { + HasToolBox = hasToolBox; + HasComputerConnection = hasComputerConnection; + HasArm = hasArm; + numberOfItemsInt = 6; + } + + #endregion + + + + #region Properties + + public bool HasToolBox + { + set { hasToolBoxBool = value; } + get { return hasToolBoxBool; } + } + + public bool HasComputerConnection + { + set { hasComputerConnectiontBool = value; } + get { return hasComputerConnectiontBool; } + } + + public bool HasArm + { + set { hasArmBool = value; } + get { return hasArmBool; } + } + + #endregion + + + + #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> + /// Mostly used for UI display. Transforms bool display from "true/false" to "yes/no." + /// </summary> + /// <param name="validationBool">Bool to convert for display.</param> + /// <returns>Appropriate string based on bool.</returns> + protected virtual string YesNoString(bool validationBool) + { + string displayString; + + if (validationBool) + { + displayString = "Yes"; + } + else + { + displayString = "No"; + } + + return displayString; + } + + /// <summary> + /// Creates string for droid type. Needed due to how inheritance works. + /// </summary> + /// <returns>String of droid's type.</returns> + protected override string TypeString() + { + return "Utility "; + } + + #endregion + + + + #region Public Methods + + /// <summary> + /// Calculates total cost of a Utility droid. + /// </summary> + public override void CalculateTotalCost() + { + base.CalculateTotalCost(); + totalCostDecimal += toolBoxDecimal + computerConnectionDecimal + armDecimal; + } + + /// <summary> + /// Calculates individual feature costs of droid. + /// </summary> + public override void CalculateFeatures() + { + base.CalculateFeatures(); + + CalculateToolBoxCost(); + CalculateConnectionCost(); + CalculateArmCost(); + } + + /// <summary> + /// Full string for displaying of single droid spanning multiple lines. + /// </summary> + /// <returns>Full information regarding single droid.</returns> + public override string DisplayLongToString() + { + 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/cis237assignment4/IDroid.cs b/cis237assignment4/IDroid.cs index deb2901..8e2783a 100644 --- a/cis237assignment4/IDroid.cs +++ b/cis237assignment4/IDroid.cs @@ -1,17 +1,48 @@ -using System; +// Brandon Rodriguez + +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace cis237assignment4 +namespace cis237assignment3 { + /// <summary> + /// Interface for all droid objects. + /// Acts as a "universal blueprint/contract" of sorts. + /// </summary> interface IDroid { - //Method to calculate the total cost of a droid + /// <summary> + /// Calculates total cost of droid. + /// </summary> void CalculateTotalCost(); - //property to get the total cost of a droid + /// <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> + /// <returns>Full information regarding single droid.</returns> + string DisplayLongToString(); } } diff --git a/cis237assignment4/IDroidCollection.cs b/cis237assignment4/IDroidCollection.cs deleted file mode 100644 index 5f7970e..0000000 --- a/cis237assignment4/IDroidCollection.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace cis237assignment4 -{ - //Interface that I added to declare what methods MUST be implemeted in any class that implements this interface. - interface IDroidCollection - { - //Various overloaded Add methods to add a new droid to the collection - bool Add(string Material, string Model, string Color, int NumberOfLanguages); - bool Add(string Material, string Model, string Color, bool HasToolBox, bool HasComputerConnection, bool HasArm); - bool Add(string Material, string Model, string Color, bool HasToolBox, bool HasComputerConnection, bool HasArm, bool HasTrashCompactor, bool HasVaccum); - bool Add(string Material, string Model, string Color, bool HasToolBox, bool HasComputerConnection, bool HasArm, bool HasFireExtinguisher, int NumberOfShips); - - //Method to get the data for a droid into a nicely formated string that can be output. - string GetPrintString(); - } -} diff --git a/cis237assignment4/JanitorDroid.cs b/cis237assignment4/JanitorDroid.cs deleted file mode 100644 index 27ed890..0000000 --- a/cis237assignment4/JanitorDroid.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace cis237assignment4 -{ - //Class that inherits from the Utility class - class JanitorDroid : UtilityDroid - { - //Some protected variables that can be accessed in derived classes - protected bool hasTrashCompactor; - protected bool hasVacuum; - - //Constuctor that takes lots of parameters to create the droid. The base constructor is used to do some of the work - public JanitorDroid(string Material, string Model, string Color, - bool HasToolbox, bool HasComputerConnection, bool HasArm, bool HasTrashCompactor, bool HasVacuum) : - base(Material, Model, Color, HasToolbox, HasComputerConnection, HasArm) - { - //Assign the values that the base constructor is not taking care of. - this.hasTrashCompactor = HasTrashCompactor; - this.hasVacuum = HasVacuum; - } - - //Override the CalculateCostOfOptions method. - //Use the base class implementation of the method, and tack on the cost of the new options - protected override decimal CalculateCostOfOptions() - { - decimal optionsCost = 0; - - optionsCost += base.CalculateCostOfOptions(); - - if (hasTrashCompactor) - { - optionsCost += COST_PER_OPTION; - } - - if (hasVacuum) - { - optionsCost += COST_PER_OPTION; - } - - return optionsCost; - } - - //Overridden ToString that uses the base ToString method, and appends the missing information. - public override string ToString() - { - return base.ToString() + - "Has Trash Compactor: " + this.hasTrashCompactor + Environment.NewLine + - "Has Vacuum: " + this.hasVacuum + Environment.NewLine; - } - } -} diff --git a/cis237assignment4/Program.cs b/cis237assignment4/Program.cs index 016ed7a..6e1ec0a 100644 --- a/cis237assignment4/Program.cs +++ b/cis237assignment4/Program.cs @@ -1,52 +1,22 @@ -using System; +// Brandon Rodriguez + +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace cis237assignment4 +namespace cis237assignment3 { class Program { + /// <summary> + /// Main. + /// </summary> + /// <param name="args">Command-line args.</param> static void Main(string[] args) { - //Create a new droid collection and set the size of it to 100. - IDroidCollection droidCollection = new DroidCollection(100); - - //Create a user interface and pass the droidCollection into it as a dependency - UserInterface userInterface = new UserInterface(droidCollection); - - //Display the main greeting for the program - userInterface.DisplayGreeting(); - - //Display the main menu for the program - userInterface.DisplayMainMenu(); - - //Get the choice that the user makes - int choice = userInterface.GetMenuChoice(); - - //While the choice is not equal to 3, continue to do work with the program - while (choice != 3) - { - //Test which choice was made - switch (choice) - { - //Choose to create a droid - case 1: - userInterface.CreateDroid(); - break; - - //Choose to Print the droid - case 2: - userInterface.PrintDroidList(); - break; - } - //Re-display the menu, and re-prompt for the choice - userInterface.DisplayMainMenu(); - choice = userInterface.GetMenuChoice(); - } - - + RunProgram run = new RunProgram(); } } } diff --git a/cis237assignment4/ProtocolDroid.cs b/cis237assignment4/ProtocolDroid.cs deleted file mode 100644 index 4f1ca6c..0000000 --- a/cis237assignment4/ProtocolDroid.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace cis237assignment4 -{ - //Class that is instantiable. It inherits from the abstract droid class - class ProtocolDroid : Droid - { - //Private variables unique to this class - protected int numberOfLanguages; - protected const decimal COST_PER_LANGUAGE = 25.00m; - - //Constructor that takes in the standard parameters, and the number of languages it knows. - //The base constructor is called to do the work of assigning the standard parameters - public ProtocolDroid(string Material, string Model, string Color, int NumberOfLanguages) : base(Material, Model, Color) - { - this.numberOfLanguages = NumberOfLanguages; - } - - //Overriden abstract method from the droid class. - //It calculates the total cost using the baseCost method. - public override void CalculateTotalCost() - { - //Calculate the base cost - this.CalculateBaseCost(); - //Calculate the total cost using the result of the base cost - this.totalCost = this.baseCost + (numberOfLanguages * COST_PER_LANGUAGE); - } - - //Override the ToString method to use the base ToString, and append new information to it. - public override string ToString() - { - return base.ToString() + - "Number Of Languages: " + this.numberOfLanguages + Environment.NewLine; - } - } -} diff --git a/cis237assignment4/RunProgram.cs b/cis237assignment4/RunProgram.cs new file mode 100644 index 0000000..05d8fbd --- /dev/null +++ b/cis237assignment4/RunProgram.cs @@ -0,0 +1,754 @@ +// Brandon Rodriguez + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace cis237assignment3 +{ + /// <summary> + /// Handles main operations of program. + /// </summary> + class RunProgram + { + #region Variables + + 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; + + private string selectedMaterialString; + private string selectedModelString; + private string selectedColorString; + private int selectedLanguageInt; + private bool toolBoxBool; + private bool computerConnectionBool; + private bool armBool; + private bool trashCompactorBool; + private bool vacuumBool; + private bool fireExtinguisherBool; + private int selectedNumberOfShipsInt; + + #endregion + + + + #region Constructor + + /// <summary> + /// Base constructor. + /// </summary> + public RunProgram() + { + runProgram = true; + Run(); + } + + #endregion + + + + #region Properties + + + + #endregion + + + + #region Methods + + /// <summary> + /// Holds program in loop until exit is chosen. + /// </summary> + private void Run() + { + ResetList(); + while (runProgram) + { + // Resets/initializes menu bool to allow user to stay in menus. + menusBool = true; + + UserInterface.Menus.DisplayMainMenu(); + userInputString = UserInterface.GetUserInput(); + MainMenuSelection(); + } + } + + /// <summary> + /// Handles Main Menu Selection. + /// </summary> + private void MainMenuSelection() + { + switch (userInputString) + { + case "1": + PurchaseDroid(); + break; + case "2": + DisplayReciept(); + break; + case "3": + DisplaySingle(); + break; + case "4": + ResetList(); + 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(); + + if (droidCollection.DroidList[0] != null) + { + DisplayFullList(); + } + else + { + UserInterface.DisplayError("There is no reciept to display."); + } + } + + /// <summary> + /// Displays information for single droid. + /// </summary> + private void DisplaySingle() + { + UserInterface.ClearDisplayLine(); + + 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> + /// 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(); + userInputString = UserInterface.GetUserInput(); + + switch (userInputString) + { + 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(); + break; + default: + UserInterface.DisplayError("Invalid selection."); + DroidTypeSelection(); + break; + } + } + + /// <summary> + /// Methods to run if purchasing any kind of droid at all (generic). + /// </summary> + private void PurchaseGeneric() + { + if (menusBool) + { + UserInterface.ClearDisplayLine(); + ModelSelection(); + } + if (menusBool) + { + UserInterface.ClearDisplayLine(); + MaterialSelection(); + } + if (menusBool) + { + UserInterface.ClearDisplayLine(); + ColorSelection(); + } + + } + + /// <summary> + /// Methods to run if purchasing a droid of type Protocol. + /// </summary> + private void PurchaseProtocol() + { + if (menusBool) + { + UserInterface.ClearDisplayLine(); + PurchaseGeneric(); + } + if (menusBool) + { + UserInterface.ClearDisplayLine(); + LanguageSelection(); + } + } + + /// <summary> + /// Methods to run if purchasing a droid of type Utility. + /// </summary> + private void PurchaseUtility() + { + if (menusBool) + { + UserInterface.ClearDisplayLine(); + PurchaseGeneric(); + } + if (menusBool) + { + UserInterface.ClearDisplayLine(); + ToolBoxSelection(); + } + if (menusBool) + { + UserInterface.ClearDisplayLine(); + CompConnectionSelection(); + } + if (menusBool) + { + UserInterface.ClearDisplayLine(); + ArmSelection(); + } + } + + /// <summary> + /// Methods to run if purchasing a droid of type Janitor. + /// </summary> + private void PurchaseJanitor() + { + if (menusBool) + { + UserInterface.ClearDisplayLine(); + PurchaseUtility(); + } + if (menusBool) + { + UserInterface.ClearDisplayLine(); + TrashCompactorSelection(); + } + if (menusBool) + { + UserInterface.ClearDisplayLine(); + VacuumSelection(); + } + } + + /// <summary> + /// Methods to run if purchasing a droid of type Astromech. + /// </summary> + private void PurchaseAstromech() + { + if (menusBool) + { + UserInterface.ClearDisplayLine(); + PurchaseUtility(); + } + if (menusBool) + { + UserInterface.ClearDisplayLine(); + FireExtinguisherSelection(); + } + if (menusBool) + { + UserInterface.ClearDisplayLine(); + NumberOfShipsSelection(); + } + } + + /// <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(); + UserInterface.DisplaySingleDroidInfo(displayString, droidCollection.DroidList[index].NumberOfItems, droidCollection.DroidList[index].TotalCost); + } + + + #region Individual Feature Selections + + /// <summary> + /// Handles user selection of droid Model. + /// </summary> + private void ModelSelection() + { + UserInterface.Menus.DisplayModelSelectionMenu(Droid.MODEL_1_STRING, Droid.MODEL_2_STRING, Droid.MODEL_3_STRING); + userInputString = UserInterface.GetUserInput(); + + switch (userInputString) + { + case "1": + selectedModelString = Droid.MODEL_1_STRING; + break; + case "2": + selectedModelString = Droid.MODEL_2_STRING; + break; + case "3": + selectedModelString = Droid.MODEL_3_STRING; + break; + case "esc": + UserInterface.ClearDisplayLine(); + menusBool = false; + break; + default: + UserInterface.DisplayError("Invalid Selection."); + ModelSelection(); + break; + } + } + + /// <summary> + /// Handles user selection of droid Material. + /// </summary> + private void MaterialSelection() + { + UserInterface.Menus.DisplayMaterialSelectionMenu(Droid.MATERIAL_1_STRING, Droid.MATERIAL_2_STRING, Droid.MATERIAL_3_STRING, Droid.MATERIAL_4_STRING, Droid.MATERIAL_5_STRING); + userInputString = UserInterface.GetUserInput(); + + switch (userInputString) + { + case "1": + selectedMaterialString = Droid.MATERIAL_1_STRING; + break; + case "2": + selectedMaterialString = Droid.MATERIAL_2_STRING; + break; + case "3": + selectedMaterialString = Droid.MATERIAL_3_STRING; + break; + case "4": + selectedMaterialString = Droid.MATERIAL_4_STRING; + break; + case "5": + selectedMaterialString = Droid.MATERIAL_5_STRING; + break; + case "esc": + UserInterface.ClearDisplayLine(); + menusBool = false; + break; + default: + UserInterface.DisplayError("Invalid Selection."); + MaterialSelection(); + break; + } + } + + /// <summary> + /// Handles user selection of droid Color. + /// </summary> + private void ColorSelection() + { + UserInterface.Menus.DisplayColorSelectionMenu(Droid.COLOR_1_STRING, Droid.COLOR_2_STRING, Droid.COLOR_3_STRING, Droid.COLOR_4_STRING, Droid.COLOR_5_STRING); + userInputString = UserInterface.GetUserInput(); + + switch (userInputString) + { + case "1": + selectedColorString = Droid.COLOR_1_STRING; + break; + case "2": + selectedColorString = Droid.COLOR_2_STRING; + break; + case "3": + selectedColorString = Droid.COLOR_3_STRING; + break; + case "4": + selectedColorString = Droid.COLOR_4_STRING; + break; + case "5": + selectedColorString = Droid.COLOR_5_STRING; + break; + case "esc": + UserInterface.ClearDisplayLine(); + menusBool = false; + break; + default: + UserInterface.DisplayError("Invalid Selection"); + ColorSelection(); + break; + } + } + + /// <summary> + /// Handles user selection of droid Language. + /// </summary> + private void LanguageSelection() + { + UserInterface.Menus.DisplayLanguageSelectionMenu(Droid_Protocol.LANGUAGE_SELECTION_1, Droid_Protocol.LANGUAGE_SELECTION_2, Droid_Protocol.LANGUAGE_SELECTION_3, Droid_Protocol.LANGUAGE_SELECTION_4); + userInputString = UserInterface.GetUserInput(); + + switch (userInputString) + { + case "1": + selectedLanguageInt = Droid_Protocol.LANGUAGE_SELECTION_1; + break; + case "2": + selectedLanguageInt = Droid_Protocol.LANGUAGE_SELECTION_2; + break; + case "3": + selectedLanguageInt = Droid_Protocol.LANGUAGE_SELECTION_3; + break; + case "4": + selectedLanguageInt = Droid_Protocol.LANGUAGE_SELECTION_4; + break; + case "esc": + UserInterface.ClearDisplayLine(); + menusBool = false; + break; + default: + UserInterface.DisplayError("Invalid Selection"); + LanguageSelection(); + break; + } + } + + /// <summary> + /// Handles user selection of droid Tool Box. + /// </summary> + private void ToolBoxSelection() + { + UserInterface.Menus.DisplayToolBoxSelectionMenu(); + userInputString = UserInterface.GetUserInput(); + + switch (userInputString) + { + case "1": + toolBoxBool = true; + break; + case "2": + toolBoxBool = false; + break; + case "esc": + UserInterface.ClearDisplayLine(); + menusBool = false; + break; + default: + UserInterface.DisplayError("Invalid Selection."); + ToolBoxSelection(); + break; + } + } + + /// <summary> + /// Handles user selection of droid Computer Connection. + /// </summary> + private void CompConnectionSelection() + { + UserInterface.Menus.DisplayComputerConnectionSelectionMenu(); + userInputString = UserInterface.GetUserInput(); + + switch (userInputString) + { + case "1": + computerConnectionBool = true; + break; + case "2": + computerConnectionBool = false; + break; + case "esc": + UserInterface.ClearDisplayLine(); + menusBool = false; + break; + default: + UserInterface.DisplayError("Invalid Selection."); + CompConnectionSelection(); + break; + } + } + + /// <summary> + /// Handles user selection of droid Arm. + /// </summary> + private void ArmSelection() + { + UserInterface.Menus.DisplayArmSelectionMenu(); + userInputString = UserInterface.GetUserInput(); + + switch (userInputString) + { + case "1": + armBool = true; + break; + case "2": + armBool = false; + break; + case "esc": + UserInterface.ClearDisplayLine(); + menusBool = false; + break; + default: + UserInterface.DisplayError("Invalid Selection."); + ArmSelection(); + break; + } + } + + /// <summary> + /// Handles user selection of droid Trash Compactor. + /// </summary> + private void TrashCompactorSelection() + { + UserInterface.Menus.DisplayTrashCompactorSelectionMenu(); + userInputString = UserInterface.GetUserInput(); + + switch (userInputString) + { + case "1": + trashCompactorBool = true; + break; + case "2": + trashCompactorBool = false; + break; + case "esc": + UserInterface.ClearDisplayLine(); + menusBool = false; + break; + default: + UserInterface.DisplayError("Invalid Selection."); + TrashCompactorSelection(); + break; + } + } + + /// <summary> + /// Handles user selection of droid Vacuum. + /// </summary> + private void VacuumSelection() + { + UserInterface.Menus.DisplayVacuumSelectionMenu(); + userInputString = UserInterface.GetUserInput(); + + switch (userInputString) + { + case "1": + vacuumBool = true; + break; + case "2": + vacuumBool = false; + break; + case "esc": + UserInterface.ClearDisplayLine(); + menusBool = false; + break; + default: + UserInterface.DisplayError("Invalid Selection."); + VacuumSelection(); + break; + } + } + + /// <summary> + /// Handles user selection of droid Fire Extinguisher. + /// </summary> + private void FireExtinguisherSelection() + { + UserInterface.Menus.DisplayFireExtinguisherSelectionMenu(); + userInputString = UserInterface.GetUserInput(); + + switch (userInputString) + { + case "1": + fireExtinguisherBool = true; + break; + case "2": + fireExtinguisherBool = false; + break; + case "esc": + UserInterface.ClearDisplayLine(); + menusBool = false; + break; + default: + UserInterface.DisplayError("Invalid Selection."); + FireExtinguisherSelection(); + break; + } + } + + /// <summary> + /// Handles user selection of droid Ship-outfitting number. + /// </summary> + private void NumberOfShipsSelection() + { + UserInterface.Menus.DisplayNumberOfShipsSelectionMenu(); + userInputString = UserInterface.GetUserInput(); + + // If user does not want to back out of menu. + if (userInputString != "esc") + { + // 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) + { + selectedNumberOfShipsInt = temptInt; + } + else + { + UserInterface.DisplayError("Must be between 0 and 10."); + NumberOfShipsSelection(); + } + } + catch + { + UserInterface.DisplayError("Not a valid number."); + NumberOfShipsSelection(); + } + } + else + { + UserInterface.ClearDisplayLine(); + menusBool = false; + } + } + + #endregion + + + #endregion + + } +} diff --git a/cis237assignment4/UserInterface.cs b/cis237assignment4/UserInterface.cs index 0a8f79e..fa4c614 100644 --- a/cis237assignment4/UserInterface.cs +++ b/cis237assignment4/UserInterface.cs @@ -1,338 +1,428 @@ -using System; +// Brandon Rodriguez + +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace cis237assignment4 +namespace cis237assignment3 { - //Class to handle all of the User Interface operations - class UserInterface + /// <summary> + /// Handles all display to user and reading of user input. + /// 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. 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. + /// </summary> + static class UserInterface { - //Create a class level variable for the droid collection - IDroidCollection droidCollection; + #region Variables - //Constructor that will take in a droid collection to use - public UserInterface(IDroidCollection DroidCollection) - { - this.droidCollection = DroidCollection; - } + private static string userInputString; + private static int previousListSizeInt; - //Method to display the welcome message of the program - public void DisplayGreeting() - { - Console.WriteLine("Welcome to the Droid Inventory System"); - Console.WriteLine(); - } + #endregion - //Method to display the main menu - public void DisplayMainMenu() - { - Console.WriteLine("What would you like to do?"); - Console.WriteLine("1. Add a new droid to the system"); - Console.WriteLine("2. Print the list of droids out"); - Console.WriteLine("3. Exit the program"); - } - //Method to get a menu choice - public int GetMenuChoice() - { - //Display prompt and get the input from the user - Console.Write("> "); - string choice = Console.ReadLine(); - //Set a variable for the menu choice to 0. Try to parse the input, if successful, return the menu choice. - int menuChoice = 0; - try - { - menuChoice = Int32.Parse(choice); - } - catch (Exception e) - { - menuChoice = 0; - } + #region Constructor - return menuChoice; - } - //Method to do the work of creating a new droid - public void CreateDroid() - { - //Prompt for color selection - this.displayColorSelection(); - //Get the choice that the user makes - int choice = this.GetMenuChoice(); - //If the choice is not valid, loop until it is valid, or the user cancels the operation - while(choice < 1 || choice > 4) - { - //Prompt for a valid choice - this.displayColorSelection(); - choice = this.GetMenuChoice(); - } + #endregion - //Check the choice against the possibilities - //If there is one found, work on getting the next piece of information. - switch(choice) - { - case 1: - this.chooseMaterial("Bronze"); - break; - case 2: - this.chooseMaterial("Silver"); - break; - case 3: - this.chooseMaterial("Gold"); - break; - } - } + #region Properties + + + + #endregion - //Method to print out the droid list - public void PrintDroidList() - { - Console.WriteLine(); - Console.WriteLine(this.droidCollection.GetPrintString()); - } - //Display the Model Selection - private void displayModelSelection() + + #region Private Methods + + /// <summary> + /// Sets cursor position for menus. + /// </summary> + private static void SetMenuCursor() { - Console.WriteLine(); - Console.WriteLine("What type of droid is it?"); - Console.WriteLine("1. Protocol"); - Console.WriteLine("2. Utility"); - Console.WriteLine("3. Janitorial"); - Console.WriteLine("4. Astromech"); - Console.WriteLine("5. Cancel This Operation"); + Console.SetCursorPosition(0, 1); } - //Display the Material Selection - private void displayMaterialSelection() + private static void ResetMenuDisplay() { - Console.WriteLine(); - Console.WriteLine("What material is the droid made out of?"); - Console.WriteLine("1. Carbonite"); - Console.WriteLine("2. Vanadium"); - Console.WriteLine("3. Quadranium"); - Console.WriteLine("4. Cancel This Operation"); + // Section to remove everything currently displayed. + SetMenuCursor(); + Console.WriteLine( + "".PadRight(Console.WindowWidth - 1) + Environment.NewLine + + "".PadRight(Console.WindowWidth - 1) + Environment.NewLine + + "".PadRight(Console.WindowWidth - 1) + Environment.NewLine + + "".PadRight(Console.WindowWidth - 1) + Environment.NewLine + + "".PadRight(Console.WindowWidth - 1) + Environment.NewLine + + "".PadRight(Console.WindowWidth - 1) + Environment.NewLine + + "".PadRight(Console.WindowWidth - 1) + Environment.NewLine); + + // Section to add back "esc to go back" display section. + // Recreated each time incase a menu string at some point is too long and writes over it. + SetMenuCursor(); + Console.WriteLine("Type 'esc' at any point to exit out. ".PadLeft(Console.WindowWidth - 1)); + + // Sets cursor for new menu to actually display. + SetMenuCursor(); } - //Display the Color Selection - private void displayColorSelection() + private static void ResetDroidDisplay() { - Console.WriteLine(); - Console.WriteLine("What color is the droid?"); - Console.WriteLine("1. Bronze"); - Console.WriteLine("2. Silver"); - Console.WriteLine("3. Gold"); - Console.WriteLine("4. Cancel This Operation"); + } - //Display the Number of Languages Selection - private void displayNumberOfLanguageSelection() + #endregion + + + + #region Public Methods + + /// <summary> + /// Gets user input from console. + /// </summary> + /// <returns>String of user's input.</returns> + public static string GetUserInput() { - Console.WriteLine(); - Console.WriteLine("How many languages does the droid know?"); + Console.SetCursorPosition(1, 9); + + userInputString = Console.ReadLine().Trim().ToLower(); + + // Removing of user input after recieving it. + Console.SetCursorPosition(0, 9); + Console.WriteLine("".PadRight(Console.WindowWidth - 1)); + + return userInputString; } - //Display and get the utility options - private bool[] displayAndGetUtilityOptions() + /// <summary> + /// Displays a line to console. + /// </summary> + /// <param name="displayString">String to display.</param> + public static void DisplayLine(string displayString) { - Console.WriteLine(); - bool option1 = this.displayAndGetOption("Does the droid have a toolbox?"); - Console.WriteLine(); - bool option2 = this.displayAndGetOption("Does the droid have a computer connection?"); - Console.WriteLine(); - bool option3 = this.displayAndGetOption("Does the droid have an arm?"); - - bool[] returnArray = {option1, option2, option3}; - return returnArray; + ClearDisplayLine(); + Console.WriteLine(displayString); } - //Display and get the Janatorial options - private bool[] displayAndGetJanatorialOptions() + /// <summary> + /// Displays an error line to console. + /// </summary> + /// <param name="displayString">String of error to display.</param> + public static void DisplayError(string displayString) { - Console.WriteLine(); - bool option1 = this.displayAndGetOption("Does the droid have a trash compactor?"); - Console.WriteLine(); - bool option2 = this.displayAndGetOption("Does the droid have a vaccum?"); + ClearDisplayLine(); - bool[] returnArray = { option1, option2 }; - return returnArray; + Console.SetCursorPosition(1, 8); + + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(displayString.PadRight(Console.WindowWidth - 1)); + Console.ForegroundColor = ConsoleColor.Gray; } - //Display and get the astromech options - private bool displayAndGetAstromechOption() + /// <summary> + /// Clears display line from console. + /// </summary> + public static void ClearDisplayLine() { - Console.WriteLine(); - return this.displayAndGetOption("Does the droid have a fire extinguisher?"); + Console.SetCursorPosition(0, 8); + Console.WriteLine("".PadRight(Console.WindowWidth - 1)); } - //Display and get the number of ships - private int displayAndGetAstromechNumberOfShips() + /// <summary> + /// Struct to hold overbloated list of menus. + /// </summary> + public struct Menus { - Console.WriteLine(); - Console.WriteLine("How many ships has the droid worked on?"); - int choice = this.GetMenuChoice(); - - while (choice <= 0) + /// <summary> + /// Displays Main Menu to user. + /// </summary> + public static void DisplayMainMenu() { - Console.WriteLine("Not a valid number of ships"); - Console.WriteLine("How many ships as the droid worked on?"); - choice = this.GetMenuChoice(); + ResetMenuDisplay(); + + Console.WriteLine( + " Select an option: " + Environment.NewLine + + "" + Environment.NewLine + + " 1) Purchase Droid" + Environment.NewLine + + " 2) Display Full Reciept" + Environment.NewLine + + " 3) Display Single Item" + Environment.NewLine + + " 4) New Customer" + Environment.NewLine + + " 5) Exit"); } - return choice; - } - //Method to display and get a general option - //It ensures that Y or N is the typed response - private bool displayAndGetOption(string optionString) - { - Console.WriteLine(optionString + " (y/n)"); - string choice = Console.ReadLine(); - while (choice.ToUpper() != "Y" && choice.ToUpper() != "N") + /// <summary> + /// Displays droid Type selection to user. + /// </summary> + public static void DisplayTypeSelectionMenu() { - Console.WriteLine(optionString); - choice = Console.ReadLine(); + ResetMenuDisplay(); + + Console.WriteLine( + " Select a Droid Type: " + Environment.NewLine + + "" + Environment.NewLine + + " 1) Protocol Droid" + Environment.NewLine + + " 2) Utility Droid" + Environment.NewLine + + " 3) Janitor Droid" + Environment.NewLine + + " 4) Astromech Droid" + Environment.NewLine); } - if (choice.ToUpper() == "Y") + + /// <summary> + /// Displays droid Model selection to user. + /// </summary> + /// <param name="model1">Droid Model 1.</param> + /// <param name="model2">Droid Model 2.</param> + public static void DisplayModelSelectionMenu(string model1, string model2, string model3) { - return true; + ResetMenuDisplay(); + + Console.WriteLine( + " Select a Droid Model: " + Environment.NewLine + + "" + Environment.NewLine + + " 1) " + model1 + Environment.NewLine + + " 2) " + model2 + Environment.NewLine + + " 3) " + model3 + Environment.NewLine); } - else + + /// <summary> + /// Displays droid Material selection to user. + /// </summary> + /// <param name="material1">Droid Material 1.</param> + /// <param name="material2">Droid Material 2.</param> + /// <param name="material3">Droid Material 3.</param> + /// <param name="material4">Droid Material 4.</param> + /// <param name="material5">Droid Material 5.</param> + public static void DisplayMaterialSelectionMenu(string material1, string material2, string material3, string material4, string material5) { - return false; + ResetMenuDisplay(); + + Console.WriteLine( + " Select a Droid Material: " + Environment.NewLine + + "" + Environment.NewLine + + " 1) " + material1 + Environment.NewLine + + " 2) " + material2 + Environment.NewLine + + " 3) " + material3 + Environment.NewLine + + " 4) " + material4 + Environment.NewLine + + " 5) " + material5 + Environment.NewLine); } - } - //Method to choose the Material for the droid. It accepts Color as the parameter - private void chooseMaterial(string Color) - { - //Display the material selection - this.displayMaterialSelection(); - //get the users choice - int choice = this.GetMenuChoice(); + /// <summary> + /// Displays droid Color selection to user. + /// </summary> + /// <param name="color1">Droid Color 1.</param> + /// <param name="color2">Droid Color 2.</param> + /// <param name="color3">Droid Color 3.</param> + /// <param name="color4">Droid Color 4.</param> + /// <param name="color5">Droid Color 5.</param> + public static void DisplayColorSelectionMenu(string color1, string color2, string color3, string color4, string color5) + { + ResetMenuDisplay(); + + Console.WriteLine( + " Select a Droid Color: " + Environment.NewLine + + "" + Environment.NewLine + + " 1) " + color1 + Environment.NewLine + + " 2) " + color2 + Environment.NewLine + + " 3) " + color3 + Environment.NewLine + + " 4) " + color4 + Environment.NewLine + + " 5) " + color5 + Environment.NewLine); + } - //while the chioce is not valid, wait until there is a valid one - while (choice < 0 || choice > 4) + /// <summary> + /// Displays droid Language selection to user. + /// </summary> + /// <param name="langSelection1">Droid Language 1.</param> + /// <param name="langSelection2">Droid Language 2.</param> + /// <param name="langSelection3">Droid Language 3.</param> + /// <param name="langSelection4">Droid Language 4.</param> + public static void DisplayLanguageSelectionMenu(int langSelection1, int langSelection2, int langSelection3, int langSelection4) { - this.displayMaterialSelection(); - choice = this.GetMenuChoice(); + ResetMenuDisplay(); + + Console.WriteLine( + " Select number of Built in Languages: " + Environment.NewLine + + "" + Environment.NewLine + + " 1) " + langSelection1 + Environment.NewLine + + " 2) " + langSelection2 + Environment.NewLine + + " 3) " + langSelection3 + Environment.NewLine + + " 4) " + langSelection4 + Environment.NewLine); } - //Check to see which choice was chosen. Call choose model and pass the color an material over - //to the method to get the model - switch(choice) + /// <summary> + /// Displays droid Tool Box selection to user. + /// </summary> + public static void DisplayToolBoxSelectionMenu() { - case 1: - this.chooseModel(Color, "Carbonite"); - break; - - case 2: - this.chooseModel(Color, "Vanadium"); - break; - - case 3: - this.chooseModel(Color, "Quadranium"); - break; + ResetMenuDisplay(); + Console.WriteLine( + " Add Toolbox Functionality? " + Environment.NewLine + + "" + Environment.NewLine + + " 1) Yes" + Environment.NewLine + + " 2) No" +Environment.NewLine); } - } - //Method to choose a model and decide what other input is needed based on the selected model - private void chooseModel(string Color, string Material) - { - //Display the menu to choose which model - this.displayModelSelection(); - //Get the model choice - int choice = this.GetMenuChoice(); + /// <summary> + /// Displays droid Computer Connection selection to user. + /// </summary> + public static void DisplayComputerConnectionSelectionMenu() + { + ResetMenuDisplay(); - //While the choice is not valid, keep prompting for a choice - while (choice < 0 || choice > 5) + Console.WriteLine( + " Add Network Functionality? " + Environment.NewLine + + "" + Environment.NewLine + + " 1) Yes" + Environment.NewLine + + " 2) No" + Environment.NewLine); + } + + /// <summary> + /// Displays droid Arm selection to user. + /// </summary> + public static void DisplayArmSelectionMenu() { - //Display the menu again, and ask for the option again. - this.displayModelSelection(); - choice = this.GetMenuChoice(); + ResetMenuDisplay(); + + Console.WriteLine( + " Add Mechanical Arm Functionality? " + Environment.NewLine + + "" + Environment.NewLine + + " 1) Yes" + Environment.NewLine + + " 2) No" + Environment.NewLine); } - //Based on the choice, call the next set of crieteria that needs to be determined - switch (choice) + /// <summary> + /// Displays droid Color selection to user. + /// </summary> + public static void DisplayTrashCompactorSelectionMenu() { - case 1: - this.chooseNumberOfLanguages(Color, Material, "Protocol"); - break; + ResetMenuDisplay(); - case 2: - this.chooseOptions(Color, Material, "Utility"); - break; + Console.WriteLine( + " Add Trash Compactor Functionality? " + Environment.NewLine + + "" + Environment.NewLine + + " 1) Yes" + Environment.NewLine + + " 2) No" + Environment.NewLine); + } - case 3: - this.chooseOptions(Color, Material, "Janatorial"); - break; + /// <summary> + /// Displays droid Vacuum selection to user. + /// </summary> + public static void DisplayVacuumSelectionMenu() + { + ResetMenuDisplay(); - case 4: - this.chooseOptions(Color, Material, "Astromech"); - break; + Console.WriteLine( + " Add Vacuum Functionality? " + Environment.NewLine + + "" + Environment.NewLine + + " 1) Yes" + Environment.NewLine + + " 2) No" + Environment.NewLine); } - } - //Method to choose the number of langages that a droid knows. It accepts the values that were determined - //in the past methods. This method will also add a droid based on the collected information. - private void chooseNumberOfLanguages(string Color, string Material, string Model) - { - //Display the number of languages selection - this.displayNumberOfLanguageSelection(); - //Get the users choice - int choice = this.GetMenuChoice(); + /// <summary> + /// Displays droid Fire Extinguisher selection to user. + /// </summary> + public static void DisplayFireExtinguisherSelectionMenu() + { + ResetMenuDisplay(); + + Console.WriteLine( + " Add built in Fire Extinguisher? " + Environment.NewLine + + "" + Environment.NewLine + + " 1) Yes" + Environment.NewLine + + " 2) No" + Environment.NewLine); + } - //While the choice is not valid, keep prompting for a valid one. - while (choice < 0) + /// <summary> + /// Displays droid Ship-outfitting Number selection to user. + /// </summary> + public static void DisplayNumberOfShipsSelectionMenu() { - Console.WriteLine("Not a valid number of languages"); - this.displayNumberOfLanguageSelection(); - choice = this.GetMenuChoice(); + ResetMenuDisplay(); + + Console.WriteLine( + " Program for how many ship types? " + Environment.NewLine + + "" + Environment.NewLine + + " Note: We can only program up to 9 ship types."); } - //The only droid that we can add with this criteria is a protocol droid, so add it to the droid collection - this.droidCollection.Add(Material, Model, Color, choice); + 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); + } } - //Method to figure out which of the utility droids the user is creating, and then work on collecting the rest - //of the needed information to create the droid. - private void chooseOptions(string Color, string Material, string Model) + + /// <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) { - //Display and get the utility options. - bool[] standardOptions = this.displayAndGetUtilityOptions(); + ClearList(); + previousListSizeInt = currentListSize; + + Console.SetCursorPosition(0, 10); - //Based on the model chosen, figure out the remaining information needed. - switch(Model) + 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(0, 10); + int index = 0; + while (index < previousListSizeInt + 5) { - //If it is a utility - case "Utility": - this.droidCollection.Add(Material, Model, Color, standardOptions[0], standardOptions[1], standardOptions[2]); - break; - - //If it is a Janatorial - case "Janatorial": - //Get the rest of the options for a Janatorial droid. - bool[] janatorialOptions = this.displayAndGetJanatorialOptions(); - //Add it to the collection - this.droidCollection.Add(Material, Model, Color, standardOptions[0], standardOptions[1], standardOptions[2], janatorialOptions[0], janatorialOptions[1]); - break; - - //If it is a Astromech - case "Astromech": - //Get the rest of the options for an astromech - bool astromechOption = this.displayAndGetAstromechOption(); - int astromechNumberOfShips = this.displayAndGetAstromechNumberOfShips(); - //Add it to the collection - this.droidCollection.Add(Material, Model, Color, standardOptions[0], standardOptions[1], standardOptions[2], astromechOption, astromechNumberOfShips); - break; + Console.WriteLine("".PadRight(Console.WindowWidth - 1)); + index++; } + } + /// <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 + } } diff --git a/cis237assignment4/UtilityDroid.cs b/cis237assignment4/UtilityDroid.cs deleted file mode 100644 index 22721e8..0000000 --- a/cis237assignment4/UtilityDroid.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace cis237assignment4 -{ - //Derived from the abstract class Droid. Can be instanciated - class UtilityDroid : Droid - { - //Class level variables that can be used in this class, or any children of this class - protected bool hasToolbox; - protected bool hasComputerConnection; - protected bool hasArm; - - //A constant that can be used in this class or any child classes - protected const decimal COST_PER_OPTION = 35.00m; - - //Constructor that takes the standard parameters, and ones specific to this droid. - //Calls the base constructor to do some of the work already written in the droid class. - public UtilityDroid(string Material, string Model, string Color, bool HasToolbox, bool HasComputerConnection, bool HasArm) : base(Material, Model, Color) - { - this.hasToolbox = HasToolbox; - this.hasComputerConnection = HasComputerConnection; - this.hasArm = HasArm; - } - - //virtual method to calculate the cost of the options. This method can be overridden in child classes - //to calculate the cost of options - protected virtual decimal CalculateCostOfOptions() - { - decimal optionsCost = 0; - - if (hasToolbox) - { - optionsCost += COST_PER_OPTION; - } - - if (hasComputerConnection) - { - optionsCost += COST_PER_OPTION; - } - - if (hasArm) - { - optionsCost += COST_PER_OPTION; - } - - return optionsCost; - } - - //Overridden method to calculate the total cost. This method uses the base cost from the parent droid class, - //and the cost of the options of this class to create the total cost. - public override void CalculateTotalCost() - { - this.CalculateBaseCost(); - - this.totalCost = this.baseCost + this.CalculateCostOfOptions(); - } - - //Overridden ToString method to output the information for this droid. - //uses the base ToString method and appends more information to it. - public override string ToString() - { - return base.ToString() + - "Has Tool Box: " + this.hasToolbox + Environment.NewLine + - "Has Computer Connection: " + this.hasComputerConnection + Environment.NewLine + - "Has Arm: " + this.hasArm + Environment.NewLine; - } - } -} diff --git a/cis237assignment4/cis237assignment4.csproj b/cis237assignment4/cis237assignment4.csproj index 0adf41b..99c404d 100644 --- a/cis237assignment4/cis237assignment4.csproj +++ b/cis237assignment4/cis237assignment4.csproj @@ -41,17 +41,17 @@ <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> - <Compile Include="AstromechDroid.cs" /> <Compile Include="Droid.cs" /> <Compile Include="DroidCollection.cs" /> + <Compile Include="Droid_Astromech.cs" /> + <Compile Include="Droid_Janitor.cs" /> + <Compile Include="Droid_Protocol.cs" /> + <Compile Include="Droid_Utility.cs" /> <Compile Include="IDroid.cs" /> - <Compile Include="IDroidCollection.cs" /> - <Compile Include="JanitorDroid.cs" /> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> - <Compile Include="ProtocolDroid.cs" /> + <Compile Include="RunProgram.cs" /> <Compile Include="UserInterface.cs" /> - <Compile Include="UtilityDroid.cs" /> </ItemGroup> <ItemGroup> <None Include="App.config" /> -- GitLab