Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. Add documentation at the class level and at the method level using JavaDoc style to both classes.

1. 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

2. 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

3. 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 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]

4. Answer the following questions about the methods you wrote:

Give an example from your code in Assignment1Tests.java 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions

Question

Mutye CNner

Answered: 1 week ago