Details:
In this lab you will build a reasonably large program completely on your own. There are no starter files for this one.
Before you begin, create a folder called Lab5
mkdir Lab5
and do all of your work in that folder.
You will have three different toy activities in this lab. Each of the
activities will be a text based amusement. Each one must also be
implemented in its own class. (so you will have three - or perhaps four
classes). Each of the three programs is detailed in its own section
below.
The main method.
The main method should have a loop in it. The loop should do the following things
- prompt the user to either choose one of the three toy programs that you've implemented or quit the program.
- if the user chose to quit then quit (possibly by using System.exit()
- Otherwise create an object of the class the user chose and call any methods on it that you need to call.
- repeat the process.(go back to step 1)
The first class:
The first toy will sing that old childhood staple "the ants go marching". This toy will do the following:
- Ask the user how many verses he/she wants to see.
- in a loop print out the current verse. Programatically generate the lyrics that change each time through the loop.
- I need to be able to choose any number of versese up to 256 verses and your program should still work.
- after the program has printed out all of the verses, this toys run should end.
for those of you who do not remember the ants go marching - here is a
sample of the first two verses notice that I've simplified it. The
original had one line that differed for each verse. Now every verse is
identical except for the number of the verse which changes each time.
Your program should do the same.:
The ants go marching 1 by 1, hurrah, hurrah
The ants go marching 1 by 1, hurrah, hurrah
The ants go marching 1 by 1,
The little one stops to <fill in here>
And they all go marching down to the ground
To get out of the rain, BOOM! BOOM! BOOM!
The ants go marching 2 by 2, hurrah, hurrah
The ants go marching 2 by 2, hurrah, hurrah
The ants go marching 2 by 2,
The little one stops to <fill in here>
And they all go marching down to the ground
To get out of the rain, BOOM! BOOM! BOOM!
Your class for this problem needs to have at least the following features:
- A constructor
- An instance variable that stores the number of verses
- A method which will do the actual looping and printing of the song.
Hint: this one is screaming for a for loop. (the definite loop)
The second class:
In this class you will prompt the user to enter a series of
words. You're program will count the number of characters in each
word, and produce statistics on the the words passed in. You need to
let the user enter as many words as he/she wishes to. Design a sentinal
value that will indicate the end of the input. Remember to mention to
your users what the sentinal value is.
- You need to keep track of the total number of words entered.
- You need to calculate the average number of characters in the word
- You need to tell the user the smallest number of characters in any of the words
- You also need to tell the user the maximum number of characters in any word.
- Do not include the sentinal value in your counts.
I suggest you use the DataSet.java and DataAnalyzer.java classes as
your templates for this one. The application is different enough that
you will have to think about what you are doing, but close enough to
use the structure in those two classes.
the Third class:
This class will be a simulated dice game. It will be played with two
standard six-sided dice. It should have the following functionality:
- Prompt the user to enter two target values for the dice. (which are between 1 and 6)
- in a loop, generate two random numbers from 1 to 6 (inclusive)
- print out these two numbers
- continue generating the numbers until the two numbers generated match the two target numbers entered by the user.
This class must have the following structure - any additional instance variables or methods are up to you:
- You need to have a constructor
- You need to have two instance variables to represent the users two selected target numbers.
- You need to have a method to do the random number generation.
Extra credit: 5
points extra credit for error checking to make sure that the user only
enters target values from one to six in this third class.
Extra credit part 2: 5 more
points of extra credit available if you keep track of how many "dice
rolls" it takes to finally get the two target numbers.
Submitting
Remember to comment your code!
When you submit this time, add a readme.txt file to your Lab5 folder
that you are building. This time you are buiding an insteresting program which may be different from everyone elses so the
readme should contain:
- Your name.
- A very brief summary of what you did, including any new methods
you added and why you chose to implement things the way you did..
- what was your sentinal value for the second class.
- Directions
on how to run your program and anything unusual that I need to do to
get it working properly.
- do I type in numbers or text at the prompt
when you are prompting me to enter some input?
- what class has the main method in it.
- A list of any problems still in your code or anything that you didn't get done.
Once you have the readme done, cd into your parent folder, zip up the
entire lab4 folder using the -r flag as you have learned in the last
few labs, and use the online submission program to submit it to me.
Remember to include your last name in the title of your zip file.