starting foreach
Practice with:
In this exercise, you will learn how to use different types of loops in your code, based on the needs of that program. You are given the starter code, and your goal is to fill in the body of the empty methods with logic based on the descriptions below.
Part1: The parrot
Complete the method parrot()
in the starter code provided for you. This method will keep prompting the user to enter a number that is greater than 0. Each time the user enters a number that is greater than 0, the method will print it out, and prompt the user to enter another number. This mimicking will stop only if the user enters the number 0.
Part2: The toddler
Complete the method toddler()
in the starter code provided for you. This method will be given a number as parameter and it will list out all numbers from 1 to that number.
Part3: The dreamer
Complete the method dreamer()
in the starter code provided for you. This method will be given a number as parameter and then it will draw a right-angled triangle of stars. The height and base of that triangle will consist of a number of stars equal to the input number.
Please note:
Think carefully about the set of inputs (testing cases) you will provide to your program to assert its correctness. Your inputs should be such that every method you wrote is tested (invoked) as your program runs.
In BlueJ, save the results of your testing produced in the "BlueJ: Terminal Window" into a file called loopsTest.txt. (Options > Save to File...)
It is a standard policy of this course that submissions that have not been signed (@author
) and dated (@version
) will not be graded.
Your Gradescope submission should contain the following:
Funloops.java
source fileloopsTest.txt
text file that contains your testing results