Assignment 2

Be sure to type up your answers so you can submit them electronically on the BlackBoard Connect system. You may complete this assignment individually or with another student in the class. Make sure all your files have your full name and student number on it.

If you worked in a pair, be sure to have both your full names and student numbers on everything. Both of you will need to submit (the same copy) on Blackboard Connect, even though one copy will be graded and you will both get the same mark.

Type up your answers using a text editor as instructed in the labs, or use Eclipse if you are already comfortable with it. The file format of the Java program you are to submit must be .java.

This assignment is marked out of 29 points. If you get 29/29, you will get 5% towards the course grade. There is a max possible of 33/29 if you complete the bonus successfully.

Due Date

October 24, 2013, 11:00PM.

24 Hour Silence Policy

Due to the large class size and the potential volume of questions, we are implementing a 24-hour silence policy. This means that any questions posted on the discussion forum in the 24 hours immediately preceding the assignment deadline may not get answered in time. This does not mean that we will stop answering questions the moment the day before the deadline arrives, it just means that we cannot promise all the questions will be answered in time, due to our prior engagements, such as other classes and meetings we have.

For this reason, please be sure to attempt the assignment early, and try to complete it as if it were due two days prior to the real deadline.

In any case, we will try to answer all the questions that show up on the discussion forum. Note that questions sent to emails will not be answered, as we want all course related material to be viewed for everyone's benefit.

What You Are Given

You are given a partial program that lets kids practice arithmetic. The following files are provided for you: Note: You cannot change what is provided in these files (unless otherwise indicated). Unacceptable changes will result in a lower mark even if your program works.

Question 1 [6 points]

Complete the constructor method in the Activity class. Currently, the files you are given expects this method to not take any input parameter. But as you have seen in the past, this is part of the programmer's design choice. Here are two options for completing the constructor method: Whichever option you choose, you will need to make sure the code in the TestActivity class works with your solution.

When you are done, run Activity with TestActivity to make sure it works before you move on. Nothing is displayed when you run it, but your objects are still created. The grading criteria for this question is:

Question 2 [6 points]

In the Activity class, add a method called play() that does the following: Once you think the method works, do the following in the TestActivity class:

When you are done, run Activity with TestActivity to make sure it works before you move on. You know it works if you get to play two games and you get output as follows:

What is the next number after this one?
451
452
Horray! That's correct! Good job!
How many minutes are there if the following number is in seconds?
834
13
Horray! That's correct! Good job!
Note that the numbers 451 and 834 are randomly generated, so you may not have the same numbers in your output. Note also that the numbers 452 and 13 are typed in by the user.

Question 3 [11 points]

In this question, we turn to the Game class. To give you more practice on designing your own class, translating it to Java code, and getting it to work the way you want to, the instructions in this question will be more open-ended. While this gives you more flexibility and control, it will also be harder because it requires you to have a good understanding of the Activity and TestActivity classes, as well as other programming concepts you've been learning in class.

First of all, this Game class will act like the TestActivity class in the sense that it will create Activity objects and let user enter answers. However, it will additionally let the user choose which activity the user wants to play, and at the end of playing one activity, let the user choose whether s/he wants to play another one. That's all the Game class is responsible for.

To complete this class, we recommend the following steps:

Test your Game class with the TestGameDesign class provided.

Question 4 [6 points]

Once you get the above playActivity() part working and tested, you can add more statements to the method that lets the user play another game. In particular, after playing an activity once, your method will additionally do the following: Test your Game class with the TestGameDesign class provided.

When you get your program working, you will see output similar to the following:

Which activity would you like to play?
Activity 1: One, two, thre, ...
Activity 2: How many minutes is it?
1
You entered: 1
What is the next number after this one?
213
214
Horray! That's correct! Good job!

Do you want to play again? (Type: y/n)
y
You entered: y
Which activity would you like to play?
Activity 1: One, two, thre, ...
Activity 2: How many minutes is it?
2
You entered: 2
How many minutes are there if the following number is in seconds?
3397
512
That doesn't sound right. It should be 56 Better luck next time!

Do you want to play again? (Type: y/n)
y
You entered: y
Which activity would you like to play?
Activity 1: One, two, thre, ...
Activity 2: How many minutes is it?
2
You entered: 2
How many minutes are there if the following number is in seconds?
1721
28
Horray! That's correct! Good job!

Do you want to play again? (Type: y/n)
n
You entered: n
See you next time!

Question 5 [Bonus: 4 points]

Create a new number activity that has the same activity structure and add it to the game. Show that it works In particular: Make sure your Game class still works with the TestGameDesign class provided.

What to Submit

For this assignment, submit the following: