Question: Complete the implementation of the static methods described below in a single class, Assignment1.java. Create a second class, Assignment1Tests.java, to test your methods with a
Complete the implementation of the static methods described below in a single class, Assignment1.java. Create a second class, Assignment1Tests.java, to test your methods with a main method that calls each of the methods you wrote. For each method, print a line for the name of the method being tested and at least two examples of sample input and output, similar to the labs. Add documentation at the class level and at the method level using JavaDoc style to both classes. Submit either the individual java files or a zip file of the BlueJ project.
- comment()
- String return type
- one int parameter representing an age
- returns one of six comments depending upon the age
- < 0: You have not been born yet
- 0 ... 15: You are too young to drive
- 16 ... 17: You are old enough to drive
- 18 ... 20: You are old enough to vote
- 21 ... 116: You are old enough to drink responsibly
- 117: You set the record as the oldest person
- print()
- void return type (i.e., does not return a value)
- three parameters: a String and two ints.
- action: the method prints its String parameter repeatedly. Its first int parameter specifies the number of lines to be printed; the second int parameter specifies the number of copies of the string to be printed per line.
- For example, if the String was "golly", the first int parameter was 3 and the second int parameter was 2, this would be the output: gollygolly gollygolly gollygolly
- nextColor()
- Color return type
- no parameters
- returns a Color with random RGB (red, green, blue) values
- approach: generate three random numbers representing valid RGB levels (0 to 255), produce a color using the random RGB levels
- You may need to review the Java API documentation on the class Color.
- You will need to include an import statement at the beginning of your class in order to use the Color class (import java.awt.Color;)
- Color objects can be printed with System.out.println and will give output similar to the following: java.awt.Color[r=110,g=243,b=101]
- In the comments section of Blackboard, answer the following questions about the methods you wrote:
- Give an example from your code of the formal parameter and the actual parameter for comment()
- Which method above, if any, includes a parameter passed by reference? Why is it passed by reference or why isn't there one?
- If you were asked to write an overloaded version of the print() method that assumed the number of lines and number of copies were each 10, what would this version of print()'s method heading (method signature) look like?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
