Java
UNIT 4 CHALLENGES

separator-blank.png

UNIT 4 CHALLENGE 1


separator-blank.png

MY UTILITY CLASS

You will create the class called MyUtil.  If you prefer, you can use a shorter name such as Utils or even UT.

 

It will be used to simply store different functions that are useful for other programs. 

Because these functions will be called from other classes, you will call them by using MyUtil.functionName().  So having a shorter class name is helpful here.

 

PART A – RANDOM NUMBERS

Create the following functions:

 

            public static int random1(int high)

 

                        Returns a random number between 1 and high inclusively.

 

            public static int random0(int high)

 

                        Returns a random number between 0 and high inclusively.

 

            public static int random(int low, int high)

 

                        Returns a random number between low and high inclusively.


PART B – TESTING

Create a class called MyUtilTester.  Place a main function in it.  Test all the functions that you have from above.



Note: If you wish, you will be able to keep on adding to this class and then simply copy and paste that class into different projects that you use.

 

separator-campeau.png