Question

For the following activity, you will submit your entire program to the code runner, from your...

For the following activity, you will submit your entire program to the code runner, from your first import statement to your last curly bracket.

Please download the Lesson 35 Activity template (Links to an external site.) and use it to write your code. Additionally, you can download the Lesson 35 Coding Activity (PDF) (Links to an external site.) to print or use as an offline reference.

If you need a refresher on how to use this Code Runner, watch the video in the Submitting Code and Formatting FAQs page in the Course Introduction.

NOTICE: Code runner requires a complete program. Please download the template and pdf (Links to an external site.) and use the template to write your program in DrJava. When you have finished your program, copy its entire contents, from the first import to the last curly bracket, into the code runner below.

Discussion Questions

With your class, answer the following discussion questions:

What overloaded methods have we seen in this class? Think about methods on Strings, methods in the Math class, System.out methods.

Read the String documentation (Links to an external site.) and see if you can find any more overloaded methods. Can you find any overloaded methods that have not been mentioned in class?

Write four overloaded methods called randomize. Each method will return a random number based on the parameters that it receives:

  • randomize() - Returns a random int between min and max inclusive. Must have two int parameters.
  • randomize() - Returns a random int between 0 and max inclusive. Must have one int parameter.
  • randomize() - Returns a random double between min and max. Must have two double parameters.
  • randomize() - Returns a random double between 0 and max. Must have one double parameter.

Because these methods are overloaded, they should be declared in the same class, so there is only one code-runner to test all four methods.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for the question, here are the 4 overloaded methods() declared inside a class. I named in Randomize.java you can update the class name to any name you like.

Here is the complete code.

=======================================================================

import java.util.Random;

public class Randomize {

    private static Random random = new Random();

    public static int randomize(int min, int max) {

        return min + random.nextInt(max - min + 1);

    }

    public static int randomize(int max) {

        return randomize(0, max);

    }

    public static double randomize(double min, double max) {

        return min + random.nextDouble() * (max - min);

    }

    public static double randomize(double max) {

        return randomize(0,max);
    }


}

=======================================================================

Add a comment
Know the answer?
Add Answer to:
For the following activity, you will submit your entire program to the code runner, from your...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write four overloaded methods called randomize. Each method will return a random number based on the...

    Write four overloaded methods called randomize. Each method will return a random number based on the parameters that it receives: randomize() - Returns a random int between min and max inclusive. Must have two int parameters. randomize() - Returns a random int between 0 and max inclusive. Must have one int parameter. randomize() - Returns a random double between min and max. Must have two double parameters. randomize() - Returns a random double between 0 and max. Must have one...

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

  • Using Python. You will create two classes and then use the provided test program to make sure your program works This m...

    Using Python. You will create two classes and then use the provided test program to make sure your program works This means that your class and methods must match the names used in the test program You should break your class implementation into multiple files. You should have a car.py that defines the car class and a list.py that defines a link class and the linked list class. When all is working, you should zip up your complete project and...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • EX 1) Determine the outcome of the following code fragment without writing and running the program....

    EX 1) Determine the outcome of the following code fragment without writing and running the program. int num = 0, max = 20; while (num <= max) {     System.out.println(num);     num += 4; } EX 2) Write a code fragment that reads and prints integer values entered by user until a particular sentinel value (stored in constant SENTINEL) is entered. Do not print the sentinel value.                 Ex 3)  Write a method called averageLargestTwo  that accepts three int parameters  and returns the average...

  • Design a stack class by importing the available java.util.Stack to have the following features: push(x) --...

    Design a stack class by importing the available java.util.Stack to have the following features: push(x) -- push element x onto stack, where x is anywhere between Integer.MIN_VALUE and Integer.MAX_VALUE. pop() -- remove the element on top of the stack. top() -- get the top element. getMax() -- retrieve the max element in the stack in constant time (i.e., O(1)). Your code should have the following shape and form, all in one .java file. Note the styling and documentation API already...

  • Assignment 3: Ultimate Frisbee For this assignment, you will create a hierarchy of five classes to...

    Assignment 3: Ultimate Frisbee For this assignment, you will create a hierarchy of five classes to describe various elements of a an ultimate frisbee (Links to an external site.)Links to an external site. team. Ultimate frisbee is a non-contact sport with players at a position of “cutter” or “handler”. A team usually also has a head coach and possibly one or more assistant coaches. An ultimate team has seven players on the field, with four players at the position of...

  • Comment your code. At the top of the program include your name, a brief description of...

    Comment your code. At the top of the program include your name, a brief description of the program and what it does and the due date. The program must be written in Java and submitted via D2L. The code matches the class diagram given above. The code uses Inheritance. In the following, you are given code for two classes: Coin and TestCoin. You study these classes first and try to understand the meaning of every line. You can cut and...

  • You will write a two-class Java program that implements the Game of 21. This is a...

    You will write a two-class Java program that implements the Game of 21. This is a fairly simple game where a player plays against a “dealer”. The player will receive two and optionally three numbers. Each number is randomly generated in the range 1 to 11 inclusive (in notation: [1,11]). The player’s score is the sum of these numbers. The dealer will receive two random numbers, also in [1,11]. The player wins if its score is greater than the dealer’s...

  • Write a program that instantiates an array of integers named scores. Let the size of the...

    Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT