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

  • Assignment 1, Fraction Instructions For this assignment, you will create a class to store fractions. The...

    Assignment 1, Fraction Instructions For this assignment, you will create a class to store fractions. The class will hold two integer values: a numerator and a denominator. For your class we will stick to positive fractions, meaning the numerator and the denominator must both be greater than 0. In previous assignments, we had a requirement that your class be named Main. In this assignment, the class is required to be named Fraction. To get started, download the template file Fraction.java...

  • Objectives: Develop an object-oriented program Develop a test program that is separate from the class under...

    Objectives: Develop an object-oriented program Develop a test program that is separate from the class under development ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Define a class where one object of the class represents a playing card. If you are not familiar with a deck of playing cards, you will need to spend some time understanding the rank and suit that is on each playing card. You can look it up in wikipedia and see an image of the whole deck of 52 playing cards here:...

  • Write the example code to describe overloading and submit here. You need to put comments for...

    Write the example code to describe overloading and submit here. You need to put comments for your code. You need to add at least one more overloaded method to the example code. public class OverloadingExample { public static void main(String[] args) { OverloadingExample t = new OverloadingExample(); t.methodX(5,9,2.2); t.methodX(5,9,"Hi"); t.methodX(5,9,2); t.methodX(5,9); } public void methodX(int a){ System.out.println("This is the method X with 1 parameters!"); } public void methodX(int a,int b){ System.out.println("This is the method X with 2 parameters!"); } public...

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

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