Outlab 4: Froot Loops
Due: Friday 11 March at 6 pm
Purpose
Gain experience with for and while loops. Also think about Froot Loops.
Partners
This is an individual assignment, though collaboration (not
solution sharing) is allowed.
Problem Statement
The goal of this assignment is fairly simple: I describe 5 methods
that you need to implement and you implement and test them.
This is designed to not take too much time, so get it done
quickly.
Assignment
- Create an Outlab4 project and make a class called FrootLoops.
- The FrootLoops class with not have any instance variables and the
constructor will be empty (no parameters, nothing in the body). I've provided an empty copy you can start with here.
- In FrootLoops you will make the following 5 methods:
- red(int lowerBound, int upperBound, int step) where lowerBound is the lower
bound, upperBound is the upper bound, and step is the increment
amount. In this method you will make a for loop that prints
out the integer values from lowerBound up to (and possibly including)
the upperBound with an increment of step. See output for more details
about how red(...) works.
- green(int lowerBound, int upperBound, int step). In this method you
will accomplish the same thing as red(...) by using a while loop.
The output should be the same as red(...) for the same input.
- purple(). This method takes no parameters and prints
out the alphabet as shown in the output.
- blue(int val). This method uses a loop (for or
while?) to do the following. Generate a random number between
1 and 10 (including 1 and 10) 10 times and count how many
times val is generated, then print that number out.
- orange(int val). this method uses a loop (for or
while?) to do the following. Generate a random number between
1 and 10 (including 1 and 10) as many times as it takes to
generate val 5 times. Print the number of times it took.
- Create a Driver and test each loop method thoroughly. Here is an example Driver used for the output example.
- You must have the class name and method declarations as I
describe above. Your TA may choose to use their own Driver to
test your Loop class, so you need to use these names, or else it
will not compile for them.
Hints
- Work through one method at a time. They get progressively
harder, so start with the first before moving onto the second. Test, test, test,
- Ask questions if a method's operation does not make sense. Here is sample output.
- Consult the java String class online documentation to make purple(...) fairly
simple (Google: "Java String"). Find methods in the String class
that will help you do what you want to do. Consider using String
alph = "abcdefghijklmnopqrstuvwxyz" for something.
- Think first about what type of loop you want to do for blue(...)
and orange(...). There is a correct answer.
- Be careful what parameters you pass the loops. It is not hard
to get stuck in infinite loops. To kill program execution, right
click the candycane icon in the lower left hand BlueJ screen.
Select "Reset Java Virtual Machine".
Submission
By Friday 11 March at 6 pm, submit the files Driver.java
and FrootLoops.java into the appropriate D2L dropbox folder. DO NOT
SUBMIT .class files!
Grading - 20 points
- 4 points for each method including solution works, efficient,
correct loop chosen, clean output, comments.
- 5 points lost automatically if FrootLoops.java does not compile with the a different Driver.