From 5e75e5f6888b8b147eedbbe2e11d3e7fbca6fa57 Mon Sep 17 00:00:00 2001 From: David Barnes <dbarnes@kvcc.edu> Date: Mon, 26 Oct 2015 19:19:32 -0400 Subject: [PATCH] Update project to be called assignment4. Update README with assignment information. --- README.md | 86 +++++++++++++++---- ...37assignment3.sln => cis237assignment4.sln | 2 +- .../App.config | 0 .../AstromechDroid.cs | 2 +- .../Droid.cs | 2 +- .../DroidCollection.cs | 2 +- .../IDroid.cs | 2 +- .../IDroidCollection.cs | 2 +- .../JanitorDroid.cs | 2 +- .../Program.cs | 2 +- .../Properties/AssemblyInfo.cs | 0 .../ProtocolDroid.cs | 2 +- .../UserInterface.cs | 2 +- .../UtilityDroid.cs | 2 +- .../cis237assignment4.csproj | 3 +- 15 files changed, 81 insertions(+), 30 deletions(-) rename cis237assignment3.sln => cis237assignment4.sln (93%) rename {cis237assignment3 => cis237assignment4}/App.config (100%) rename {cis237assignment3 => cis237assignment4}/AstromechDroid.cs (98%) rename {cis237assignment3 => cis237assignment4}/Droid.cs (98%) rename {cis237assignment3 => cis237assignment4}/DroidCollection.cs (99%) rename {cis237assignment3 => cis237assignment4}/IDroid.cs (92%) rename {cis237assignment3 => cis237assignment4}/IDroidCollection.cs (97%) rename {cis237assignment3 => cis237assignment4}/JanitorDroid.cs (98%) rename {cis237assignment3 => cis237assignment4}/Program.cs (98%) rename {cis237assignment3 => cis237assignment4}/Properties/AssemblyInfo.cs (100%) rename {cis237assignment3 => cis237assignment4}/ProtocolDroid.cs (98%) rename {cis237assignment3 => cis237assignment4}/UserInterface.cs (99%) rename {cis237assignment3 => cis237assignment4}/UtilityDroid.cs (98%) rename cis237assignment3/cis237assignment3.csproj => cis237assignment4/cis237assignment4.csproj (98%) diff --git a/README.md b/README.md index e5d178a..ed682a3 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,78 @@ -# Assignment 3 - Inheritance, Abstract Classes, Interfaces, and Polymorphism -## Due: 10-20-2015 +# Assignment 4 - Interfaces, Stacks, Queues, Generics, and Merge Sort. Project uses Assignment 3 solution. +## Due: 11-10-2015 ## Author -David Barnes + ## Description +The Jawas on Tatooine are pleased with the job you have done on the droid system so far. Since they started using it, they have decided that they would like to be able to sort thier list of droids in two different ways. It is your job to create these sorts for them. + +They would like to sort the droids by category. If the list is printed from this sort, the program will display the droids in the following order: (Astromech, Janitor, Utility, Protocol). There does not need to be any order to the droids within those categories. + +They would also like to sort the droids by the Total Cost ranging from the cheapest droid to the most expensive droid. + +You need to add menu options and methods to a finished assignment 3 to complete assignment 4, and add the above mentioned functionality. + +You should fork, and clone my Assignment 4. This will give you my finished implementation of Assignment 3 as a starting place. If you would rather use your implementation of assignment 3, just delete all of my classes, and add your classes in it's place. (Or replace the code of my classes with the code from your classes). This way you can still make a pull request. You are not required to use your implementation of Assignment 3. In fact, it would be easier for me to grade if you used mine, but you are free to use your own if that is easier, or what you would like to do. + +You should add some dummy data to the program to make testing easier. Once the droid collection is intanciated, you should hard code the insertion of some droids into the collection. Do enough so that you can test both sorts without having to use the UI to create droids. Personally I did 12, but any number that proves the sorts work is sufficent. + +The method by which both of these sorts get done is described below: + +### Categorize by model (Bucket sort) +In order to sort the list by category, you will do the following things: +* Add a method to your droid collection that will do this sort on the collection. +* Create a generic stack class that can be used to store any type the user specifies. The implementation should be in the style of a linked list. (This is just like the generics we did in class. The Algorithms book has an implementation.) +* Create a generic queue class that can be used to store any type the user specifies. The implementation should be in the style of a linked list. (The Algorithms book has an implementation.) +* Create a stack for each type of droid (4 in total) +* Create a queue of type high enough on the inheritance chain to store all of the droids (Just 1 of these) +* Loop through your list of droids, and for each one +* Determine what type of droid it is and Push the droid onto the appropriate stack. +* Once all of the droids are on the various stacks, start Popping the droids off of the stacks and enqueue them in the Generic Queue. (Make sure you process the stacks in the correct order so that the order of the queue is the order specified above for the sort) +* Once all of the droids are in the Queue, replace the original array / list of droids with the droids in the queue by dequeuing a droid one at a time, and placing it back into the array / list at the proper location. + +### Sort by Total Cost using Merge Sort +In order to sort the list by the Total Cost, you will do the following things: +* Add a method to your droid collection that will do this sort on the collection. +* Make the IDroid Interface inherit from the built in interface called IComparable. This will require you to implement the CompareTo method in the Droid class. +* Implement CompareTo in the Droid class, which will aid in the merge sort class +* Create a MergeSort class that takes in an array by reference of type IComparabe[]. This wil allow the merge sort to sort any array that implements IComparable thanks to polymorphism. Any implementation is fine for this class, but it may be easier to do an array version (NOT linked list), and use an auxilary array to store temporary information. (The Algorithms book has a nice implementation that uses IComparable. I believe that they call it just Comparable in the Algorithms book, but it is the same thing.) + +The menu options and methods that you add should only sort the droid collection. Printing it should still be delegated to the print menu option that already exists. This means that sorting it will overwrite the original order, and that's okay. + +You are free to do anything above an beyond what is listed here. The only "Requirements" are listed below. + +Solution Must: +* Add some hard coded droids to the droid collection. +* Create Generic Stack class. +* Create Generic Queue class. +* Stack and Queue class must be Generic. +* Update IDroid to inherit from IComparable. +* Create MergeSort class. +* Mergesort class must take an IComparable array as the input. +* Update Program to allow options to sort by model, or by Total Cost. +* Add methods to the Droid Collection class to do each of the sorts. +* Use the Stack, and Queue to perform a bucket sort categorizing by model. +* Use the MergeSort to perform a sort on the TotalCost. + +Below is the original Assignment 3 description for reference. + +### Notes + +Be sure to think about what the time complexity for the bucket sort will be. Think about how it compares to that of a normal sort such as Merge or Bubble. Also consider the space complexity compared to that of merge or bubble sort. You may see questions related to this on the next exam. + +## Outside Resources Used + + + +## Known Problems, Issues, And/Or Errors in the Program + + + +## Assignment 3 Description for reference + The Jawas on Tatooine have recently opened a droid factory and they want to hire you to write a program to hold a list of the available droids, and the price of each droid. The price is based on the type: (protocol, utility, janitor, or astromech), the material used and the options selected by the Jawa creating the list. The program will keep a list of Droids that are created. This list can be either an array or in the form of one of the C# List classes. The array or list should be of a type that is high enough on the inheritance chain that all droids no matter what type they are can be stored in it. (Think Polymorphism) @@ -85,17 +151,3 @@ Solution Must: * Use private, public and protected appropriately. * Use abstract, virtual, and override appropriately. * Have sufficient comments about what you are doing in the code. - -### Notes - -If you did not do well on Assignment 1, you may want to look at the Assignment 1 Key that I did for some help related to UI classes, Collection classes, arrays, and structure. - -It may be benificial for you to create extra methods within the droid sub classes. You are not limited to the ones mentioned. You may even find it useful to make some additional ones that are protected and virtual. - -## Outside Resources Used - -None - -## Known Problems, Issues, And/Or Errors in the Program - -None that I know of \ No newline at end of file diff --git a/cis237assignment3.sln b/cis237assignment4.sln similarity index 93% rename from cis237assignment3.sln rename to cis237assignment4.sln index b9f2dbe..c11d221 100644 --- a/cis237assignment3.sln +++ b/cis237assignment4.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cis237assignment3", "cis237assignment3\cis237assignment3.csproj", "{1FBB9307-E772-4AD6-A641-1B8D3258D579}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cis237assignment4", "cis237assignment4\cis237assignment4.csproj", "{1FBB9307-E772-4AD6-A641-1B8D3258D579}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/cis237assignment3/App.config b/cis237assignment4/App.config similarity index 100% rename from cis237assignment3/App.config rename to cis237assignment4/App.config diff --git a/cis237assignment3/AstromechDroid.cs b/cis237assignment4/AstromechDroid.cs similarity index 98% rename from cis237assignment3/AstromechDroid.cs rename to cis237assignment4/AstromechDroid.cs index a5296fa..4863318 100644 --- a/cis237assignment3/AstromechDroid.cs +++ b/cis237assignment4/AstromechDroid.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace cis237assignment3 +namespace cis237assignment4 { //Class that inherits from the Utility Droid class AstromechDroid : UtilityDroid diff --git a/cis237assignment3/Droid.cs b/cis237assignment4/Droid.cs similarity index 98% rename from cis237assignment3/Droid.cs rename to cis237assignment4/Droid.cs index 4d98adc..97e0ea5 100644 --- a/cis237assignment3/Droid.cs +++ b/cis237assignment4/Droid.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace cis237assignment3 +namespace cis237assignment4 { //Abstract class that implements the IDroid interface abstract class Droid : IDroid diff --git a/cis237assignment3/DroidCollection.cs b/cis237assignment4/DroidCollection.cs similarity index 99% rename from cis237assignment3/DroidCollection.cs rename to cis237assignment4/DroidCollection.cs index 7cb3ba2..523a977 100644 --- a/cis237assignment3/DroidCollection.cs +++ b/cis237assignment4/DroidCollection.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace cis237assignment3 +namespace cis237assignment4 { //Class Droid Collection implements the IDroidCollection interface. //All methods declared in the Interface must be implemented in this class diff --git a/cis237assignment3/IDroid.cs b/cis237assignment4/IDroid.cs similarity index 92% rename from cis237assignment3/IDroid.cs rename to cis237assignment4/IDroid.cs index 0427326..deb2901 100644 --- a/cis237assignment3/IDroid.cs +++ b/cis237assignment4/IDroid.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace cis237assignment3 +namespace cis237assignment4 { interface IDroid { diff --git a/cis237assignment3/IDroidCollection.cs b/cis237assignment4/IDroidCollection.cs similarity index 97% rename from cis237assignment3/IDroidCollection.cs rename to cis237assignment4/IDroidCollection.cs index 71dc25e..5f7970e 100644 --- a/cis237assignment3/IDroidCollection.cs +++ b/cis237assignment4/IDroidCollection.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace cis237assignment3 +namespace cis237assignment4 { //Interface that I added to declare what methods MUST be implemeted in any class that implements this interface. interface IDroidCollection diff --git a/cis237assignment3/JanitorDroid.cs b/cis237assignment4/JanitorDroid.cs similarity index 98% rename from cis237assignment3/JanitorDroid.cs rename to cis237assignment4/JanitorDroid.cs index f17e84c..27ed890 100644 --- a/cis237assignment3/JanitorDroid.cs +++ b/cis237assignment4/JanitorDroid.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace cis237assignment3 +namespace cis237assignment4 { //Class that inherits from the Utility class class JanitorDroid : UtilityDroid diff --git a/cis237assignment3/Program.cs b/cis237assignment4/Program.cs similarity index 98% rename from cis237assignment3/Program.cs rename to cis237assignment4/Program.cs index 739e5d0..016ed7a 100644 --- a/cis237assignment3/Program.cs +++ b/cis237assignment4/Program.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace cis237assignment3 +namespace cis237assignment4 { class Program { diff --git a/cis237assignment3/Properties/AssemblyInfo.cs b/cis237assignment4/Properties/AssemblyInfo.cs similarity index 100% rename from cis237assignment3/Properties/AssemblyInfo.cs rename to cis237assignment4/Properties/AssemblyInfo.cs diff --git a/cis237assignment3/ProtocolDroid.cs b/cis237assignment4/ProtocolDroid.cs similarity index 98% rename from cis237assignment3/ProtocolDroid.cs rename to cis237assignment4/ProtocolDroid.cs index 94de060..4f1ca6c 100644 --- a/cis237assignment3/ProtocolDroid.cs +++ b/cis237assignment4/ProtocolDroid.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace cis237assignment3 +namespace cis237assignment4 { //Class that is instantiable. It inherits from the abstract droid class class ProtocolDroid : Droid diff --git a/cis237assignment3/UserInterface.cs b/cis237assignment4/UserInterface.cs similarity index 99% rename from cis237assignment3/UserInterface.cs rename to cis237assignment4/UserInterface.cs index e11fe53..0a8f79e 100644 --- a/cis237assignment3/UserInterface.cs +++ b/cis237assignment4/UserInterface.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace cis237assignment3 +namespace cis237assignment4 { //Class to handle all of the User Interface operations class UserInterface diff --git a/cis237assignment3/UtilityDroid.cs b/cis237assignment4/UtilityDroid.cs similarity index 98% rename from cis237assignment3/UtilityDroid.cs rename to cis237assignment4/UtilityDroid.cs index f7128a5..22721e8 100644 --- a/cis237assignment3/UtilityDroid.cs +++ b/cis237assignment4/UtilityDroid.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace cis237assignment3 +namespace cis237assignment4 { //Derived from the abstract class Droid. Can be instanciated class UtilityDroid : Droid diff --git a/cis237assignment3/cis237assignment3.csproj b/cis237assignment4/cis237assignment4.csproj similarity index 98% rename from cis237assignment3/cis237assignment3.csproj rename to cis237assignment4/cis237assignment4.csproj index 4c819f5..0adf41b 100644 --- a/cis237assignment3/cis237assignment3.csproj +++ b/cis237assignment4/cis237assignment4.csproj @@ -7,7 +7,7 @@ <ProjectGuid>{1FBB9307-E772-4AD6-A641-1B8D3258D579}</ProjectGuid> <OutputType>Exe</OutputType> <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>cis237assignment3</RootNamespace> + <RootNamespace>cis237assignment4</RootNamespace> <AssemblyName>cis237assignment3</AssemblyName> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> @@ -41,7 +41,6 @@ <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> - <Compile Include="AstromechDroid.cs" /> <Compile Include="Droid.cs" /> <Compile Include="DroidCollection.cs" /> -- GitLab