Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.39 KB | None | 0 0
  1. Strategies
  2. The goal of this project is to give you experience with the strategy pattern. To complete this assignment, you will need to fork this project skeleton, follow the instructions below to complete the implementation, then commit/push your changes back to your GitHub fork (no pull requests, please!)
  3.  
  4. Note: The assignment must be completed in the specific manner described in the instructions. Any deviations from the instructions will possibly cause the automated grading to fail and will be considered incorrect. Following the instructions includes, but is not limited to:
  5.  
  6. Do not change the test code in any way. If the test code does not compile, change your implementation of the classes being tested, not the tests! (you may add additional tests)
  7. Do not modify interfaces and abstract classes provided to you in any way unless specifically instructed to do so.
  8. Do not modify class constructors, method signatures, or local field names unless specifically instructed to do so, or if it is required to conform to the tests provided.
  9. Do not add fields to any classes unless specifically instructed to do so.
  10. Note About Academic Honesty
  11. You should keep your code and repositories private and should not be sharing code under any circumstances. When forking your projects, you should make sure the repository is set to private and you should immediately remove the class's team CSC430 from your project and add me as a collaborator so that I will be the only person who can access your code other than you! If you do not do this and check in large amounts of code, I will consider this a violation of the academic honesty policies of MSU.
  12.  
  13. Instructions
  14. Please read through the following instructions at least once before actually starting your work on the project. Read through each step and the corresponding interfaces and classes in the project skeleton so that you will have at least a vague understanding of what you will need to do.
  15.  
  16. High Level Goal
  17. The general logic from Project 1 has been moved to a new BaseBlob class which supports the basic blob functionality. This class (among others) is provided to you in the form of a third party library that you must import into your project using Maven. You will need to use this library to complete the assignment.
  18.  
  19. Strategy Pattern
  20. The main thing we will do is create a new SimpleBlob class which can be provided with logic which will determine where the blob should move to next. We will do this by utilizing the Strategy Pattern. You will need to strategize the SimpleBlob and create a couple of MoveStrategys.
  21.  
  22. Testing
  23. You are provided with a basic test suite and should consider writing additional tests in order to make sure that your code works properly. As we progress through the semester you will receive fewer and fewer tests.
  24.  
  25. Adding API Dependency
  26. To access the blob-api.jar you will need to add the proper repository and dependency to your Maven project.
  27.  
  28. First, add a repositories element to your pom.xml file. Next, add the following code:
  29.  
  30. <repository>
  31. <id>BlobAPI-mvn-repo</id>
  32. <url>https://raw.github.com/MSUCSIS/csc430-maven/mvn-repo/</url>
  33. <snapshots>
  34. <enabled>true</enabled>
  35. <updatePolicy>always</updatePolicy>
  36. </snapshots>
  37. </repository>
  38. By default, Maven searches for dependencies on a hardcoded server called Maven Central. What we have done above is to tell Maven that it should also search for dependencies at the artifact repository for this course (since the blob-api library is not published on Maven central).
  39.  
  40. Next, you will need to add a dependency to your configuration using the following "coordinates":
  41.  
  42. Group ID: edu.murraystate.csc430
  43. Artifact ID: blob-api
  44. Version: 1.0
  45. Using the three pieces of data above, we can uniqueley identify the specific library that we need for this project.
  46.  
  47. At this point, you should be able to download this dependency and will have access to all of the classes and interfaces it provides.
  48.  
  49. Strategy Pattern
  50. SimpleBlob
  51. Now that we have our project configured, let's start working on the implementation. You need to create a SimpleBlob which extends the BaseBlob from the blob-api library. This class must do the following:
  52.  
  53. It must override the move() method. This method is called when the blob should move to a new location. No arguments are provided, as it is up to the blob to determine each move.
  54.  
  55. It must override the getReadOnlyView() method. If we pass around our SimpleBlob, other objects that have access to the SimpleBlob can change its location! So, we will isntead pass around a read only copy of the blob if we need to share the blob's state with other objects. Accordingly, this method must create a BlobView with the same location and size as the blob we are calling the method on.
  56.  
  57. As stated above, it is up to the blob to choose its next move, but we do not want to hard code the logic into SimpleBlob, because that would lead to a very inflexible solution. Instead, we want to use the Strategy Pattern. You are provided with a MoveStrategy interface which contains a single method:
  58.  
  59. public interface MoveStrategy {
  60. Optional<Point> move(final BlobView blobView);
  61. }
  62. Given instances of this interface, we would like to be able to use them to determine how our blobs will move. To make this happen, we must accept a MoveStrategy in the constructor of SimpleBlob and use the provided strategy when the move() method is called.
  63.  
  64. Finally, we want to override the toString() method so that it outputs a tuple containing the blob's current coordinates (as a nested tuple) and the blob's radius. For example, if a blob with a radius of 30 is located at (12,45), the string representation should be
  65. "((12,45),30)"
  66. Note: the radius should be the obtained by rounding the radius to an integer.
  67.  
  68. Strategies
  69. StraightLineMovement
  70. A strategized blob is kind of worthless without a strategy, so let's implement the MoveStrategy to create a StraightLineMovement. The behavior of this MoveStrategy is as follows:
  71.  
  72. The strategy will be constructed by giving x and y offsets.
  73. The strategy will then move any provided blob views point by those offsets.
  74. RandomMovement
  75. The next strategy we will create is a RandomMovement which will move the blob to a random position.
  76.  
  77. The strategy should be constructed with a Random object.
  78. The new position should be created by calling nextInt() to get the nex x and y coordinates (in that order!)
  79. Be sure to store a reference to the Random object in your class so that it can be reused.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement