CSSE 220 – Object-Oriented Software Development

Homework 10

Objectives

Practice with arrays and ArrayLists in Java. More practice with loops and debugging in Java. More practice implementing classes based on a given specification.

Tasks

  1. Before 7 a.m. Tuesday morning , complete the very short survey on Angel:
    Lessons ~ Assignments ~ Survey for assigning partners for the Game of Life exercise
  2. Complete the assigned reading for the next session: Big Java §7.6–7.8.
  3. Complete the assessment exercise over this reading on ANGEL (under Lessons → Assignments).
  4. Programming:
    1. In Eclipse, checkout the ArraysAndLists project.

    2. With your instructor, observe a sample run of your instructor's solution for Main and then review the specification of the project, perhaps by examining its UML class diagram. Note especially that:

      • You implement the methods specified in StateList.
        • In doing so, you use the readStateFromScanner and toString methods given to you in the State class.
      • The methods in StateList come in two flavors: one that uses arrays, another that uses ArrayList's.
      • After you implement the methods specified in StateList, you implement the methods specified in ElectionSimulator.
        • In doing so, you use the simulate method given to you in the State class.
      • We supplied unit tests for StateList and ElectionSimulator in StateListTest and ElectionSimulatorTest, respectively.
      • The StateListTest class, in addition to providing tests, also provides examples of the use of arrays and ArrayList's.
      • You complete the project by doing the TODO's in Main, integrating your work from StateList and ElectionSimulator.

    3. Implement and test the methods stubbed in StateList, in the order in which they appear in that class.

      • The StateListTest class contains JUnit tests for these methods.

    4. Implement and test the methods stubbed in ElectionSimulator, in the order in which they appear in that class.

      • The ElectionSimulatorTest class contains JUnit tests for these methods.

    5. Implement and test the TODO items in Main, in the order in which they appear in that class.

      Here’s an example of the output from my solution for your reference.

    6. Bonus (optional, for extra credit): Add code so that main displays a graphical bar chart of the results in addition to the textual one. Use three different colors for the bars: one for bars representing fewer than half the electoral votes, one for bars representing more than half, and one for a tie.
    7. ArrayList practice:
      1. We have created documented stubs of a constructor and several methods in the QuizScores class. Implement these documented stubs, using the JUnit 4 tests supplied in QuizScoresTest.

        Note the implementation requirements for the QuizScores exercise:

        • Use an ArrayList<Integer> to store the scores.
        • Use the enhanced for loop where practical.
        • Do NOT use methods from Arrays or Collections in the QuizScores class.

        Big Java, §7.5, may be a helpful reference if you get stuck, as might the summary on arrays and ArrayList's.

        You should complete the methods through highestScore by Tuesday, with the rest of the methods due Thursday.

Turn-in Instructions

Turn in your programming work by committing it to your SVN repository.