Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this independent learning activity well start with a small exercise of creating a class that can be used to represent actions taken by a

For this independent learning activity well start with a small exercise of creating a class that can be used to represent actions taken by a user in a program. Think of how many programs have the ability to undo and redo actions. To have this kind of functionality you have to know what the user did that needs to be undone etc. We will simulate this by first creating a UserActions class that will hold a string to represent an action performed by the user. Well then create an ActionTracker class that will keep an array of UserActions that we can add to (do action) and eventually remove from (undo action). In this ILA youll: create a class use an array of class objects as a field in another class use an array of class objects like a stack new items are added or stacked on top of previous items remove items starting from the top and working your way down to the bottom items Console cursor positioning and resetting Selectively clearing part of the console Only drawing console items that have changed Instructions: Make sure to complete the Setup Confirmation assignment. It will walk you through how to prepare a Visual Studio project. Download the supplied starter project: See download link Extract the project from the zip file to a location on your hard drive. (I recommend a location like Documents/FullSail/DES1/Assignments). *** NOTE *** The project will have errors in Program.cs until you complete the UserAction and ActionTracker classes. That is ok. Follow the instructions and all will be well :) In visual studio with the starter project open, complete the following steps Create the UserAction class in UserAction add the following methods (The body will be empty for now well add the functionality for these methods later Overloaded Constructor public UserAction(string NewActionTaken) {} Public getters / setters public string GetAction() {} This method will cause a compilation error until it returns something so just have it return null for now. { return null; } Create the ActionTracker class in ActionTracker add the following methods (The body will be empty for now well add the functionality for these methods later). Overloaded Constructor public ActionTracker(int MaxNumberOfActions) {} Public methods / behaviors public void AddAction(UserAction NewAction) {} public void DisplayActions() {} This will be enough to compile and run the program though it wont do much until we implement the functionality for our classes. in UserAction well add the following items to make it usable add field of type string to hold the users action private string ActionTaken; in the constructor we need to assign the value of NewActionTaken to the ActionTaken field ActionTaken = NewActionTaken; in GetAction we need to return the action held by our ActionTaken field instead of null return ActionTaken; in ActionTracker well add the following items to make it usable add field UserAction array named ActionStack private UserAction[] ActionStack; in the constructor we need to initialize the size of the array to hold the MaxNumberOfActions ActionStack = new UserAction[MaxNumberOfActions]; in AddAction we need to write logic so that we can place the UserAction being passed as a parameter into our array of UserActions. When we do this well need to keep track of which spot in the array is the next empty spot to use - if we dont then the only info we have for the array is the size of the array. To track the NextEmptSpotIndex well need to add another field to the class private int NextEmptySpotIndex; We need the NextEmptySpotIndex to start at 0 so that will have to be initialized in the constructor NextEmptySpotIndex = 0; Now in AddAction we are ready to write the logic ActionStack[NextEmptySpotIndex] = NewAction; this will assign NewAction to the next empty spot in the array. After doing this we need to increase the value of NextEmptySpotIndex by 1 or the next add call will replace the action that we just put in the array. NextEmptySpotIndex++; There is one issue with this method. Do you know what it is? What happens if we try to add more than MaxNumberOfActions to the ActionStack array? NextEmptySpotIndex will keep going even past the end of our array and cause a crash on the next add call. We need to add logic to prevent this. Around the other two lines in AddAction we need to place an if check and {}s if (NextEmptySpotIndex

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Usability

Authors: Jakob Nielsen, Raluca Budiu

1st Edition

0133122131, 9780133122138

More Books

Students also viewed these Programming questions

Question

What are the benefits of making a to-do list? (p. 299)

Answered: 1 week ago

Question

53. If X is uniform over (0, 1), calculate E[Xn] and Var(Xn).

Answered: 1 week ago