• Embed Doc
  • Readcast
  • Collections
  • 1
    CommentGo Back
Download
 
Exercise 1: Using the
while
Loop
The objective of this exercise is to write classes that use
while
loops.
Task 1 – Writing a Class That Uses the
while
Loop
In this task, you write a class that counts from 1 to any number. Follow these steps towrite your class:1. Go to the
loops
directory.2. Write a class called
Counter
that contains a method called
displayCount
that:
Counts from one (1) to
MAX_COUNT
, where
MAX_COUNT
is a variablethat you must declare and initialize to any number, by using a
while
loop
Displays the count3. Compile your program.4. Use the
CounterTest.class
file to test your program.
Task 2 – Writing Another Class That Uses the
while
Loop
In this task, you write a class called
Sequence
that displays a sequence starting withthe numbers 1 and 1. Successive numbers in the sequence are the sum of the previous twonumbers. For example: 1 1 2 3 5 8 13 and so on. Follow these steps to create your class:5. Write a class called
Sequence
that contains a method called
displaySequence
. The display method should contain a
while
loop that:
Performs an operation to calculate a number in the sequence.
Displays the first 10 numbers in the sequence. The result should look like:
11235813213455
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...