The document describes two tasks for writing classes that use do/while loops. The first task is to write a CounterThree class with a method that counts from 1 to a MAX_COUNT constant using a do/while loop. The second task is to write a SequenceThree class with a method that displays numbers in the Fibonacci sequence using a do/while loop, as long as the numbers are less than 100.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
8K views2 pages
WJ 1103A Module 2 Exercise3
The document describes two tasks for writing classes that use do/while loops. The first task is to write a CounterThree class with a method that counts from 1 to a MAX_COUNT constant using a do/while loop. The second task is to write a SequenceThree class with a method that displays numbers in the Fibonacci sequence using a do/while loop, as long as the numbers are less than 100.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
Exercise 3: Using the do/while Loop
The objective of this exercise is to write classes that use do/while loops.
Task 1 – Writing a Class Using the do/while Loop
In this task, you write a class that counts from 1 to some number. Follow these steps to write your class:
1. Go to the loops directory.
2. Write a class called CounterThree containing a method called
displayCount that:
• Counts from 1 to the value of the MAX_COUNT constant, where the
MAX_COUNT constant is a variable that you must declare and initilize to any number, using a do/while loop • Displays the count
3. Compile your program.
4. Use the CounterThreeTest.class file to test your program.
Task 2– Writing Another Class Using the do/while
Loop In this task, you write a class called Sequence that displays a sequence starting with the numbers 1 and 1. Successive numbers in the sequence are the sum of the previous two numbers. For example: 1 1 2 3 5 8 13 and so on. Follow these steps to write your class:
5. Write a class called SequenceThree that contains a method called
displaySequence. The displaySequence method should contain a do/while loop that:
• Performs an operation to calculate a number in the sequence.
• Displays the numbers in the sequence, as long as the numbers in the sequence are less than 100. The result should look like: 1 1 2 3 5 8 13 21 34 55 89
6. Compile your program.
7. Use the SequenceThreeTest.class file to test your program.