CS-2510 Assignment E2 - Exam 2 Extra Credit

Due: November 17th @ 10:00 pm

Purpose:

To demonstrate understanding of concepts from the exam and allow for redemption of some exam points.

Please submit these as separate files as attachments in an email to me. The email should have the exact subject: [CS2510F11] AssignmentE2. Additionally, you must give me your exam on Thursday, Nov 17th in class. I will return it to you once I have graded your assignment.

You will receive no credit for a given problem unless it is tested and runs properly. You must work on this alone, and you can receive a maximum of half of the points you lost on the respective exam problem for each programming problem here.

I will consider giving more points if you add interesting additional features besides those described here; feel free to consult me regarding ideas you have before you implement them.




Programming Problem 1: (StockMarket.java)

You will write a working Stock Market class and a working Queue to go with it.

  1. Use the LinkedList Java class to create a Queue<X> class. It should implement the methods enqueue, which adds the given element to the Queue, dequeue, which removes the first element from the Queue and returns it, isEmpty, which returns true if the Queue is empty and false otherwise, and length, which returns the number of elements in the Queue. You may only use the boolean add(E e), E remove() and int size() methods from the LinkedList class.

  2. Create the StockMarket class from the test. Create the following methods: buy and sell, which take a number of shares and adds the request to the Queue (taking the negative of the value as necessary); processTransaction, which takes the first transation from the Queue and updates shares accordingly. Throw an Exception of your own creation (extend RuntimeException) if updating shares would result in a negative number of shares.

    Note: Don't forget to test! You must include a test which runs processTransaction on all elements in the transaction Queue (use a loop).

  3. Correctly implement and test any methods from the first problem on the test for which you lost points.




Programming Problem 2: (GameWorld.java)

Integrate the konami code into an existing game.

Add the Konami Code to an existing game you have created. You may use my Snake if you need a working starting point. The game should work exactly as it did before you added the onKey modifications, but if you type the exact sequence of keys, then the game should change in some interesting way (e.g. for Snake, the snake could start randomly changing colors, or you could add another key to automatically grow or shrink the state).

Note that for this, you will need to modify some other methods to check if the game is in Konami Mode and perform different actions under those conditions (which is why we used a boolean on the test to dictate whether or not we were in Konami Mode).

You may write a shorter code (list of keypresses) such that you can actually type it before you get a game over state.

Make sure to test your onKey method by simulating it on a series of keypresses. Again, onKey is called once per key pressed by the user, so you need to keep track of where you are in the code sequence, have a way to tell if you are at the end of the sequence, and have a way to reset the counter when you encounter keypress that does not match the current key in the code sequence.