Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9231187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:00:39+00:00 2026-06-18T06:00:39+00:00

I did the code, make a random number between 1 and 100 as task

  • 0

I did the code, make a random number between 1 and 100 as task A), then how I understood if the first value if more than 50 generate second random number between 1 and 50 as said ( how I think) task B)

PLEASE can any one explain what the task C and D is, not understand how to do it at all ..(((pls help with advice or explanation task C and D.

Thanks….

TASK:

Write a program that generates random numbers:

a) +Write a method that returns a random integer in the range of 1 to 100.

b) Then add another method that takes a parameter specifying the top number – i.e. if you pass it 50 it returns a random number between 1 and 50. Test your random method and make sure it works.

c) Write another method so that you pass it two values – the top and bottom of the range you want the highest value from – i.e. if you pass it 10 and 20 it returns a random number between 10 and 20.

d) Then write another method so that if repeatedly called it doesn’t return two numbers the same? So once a random number has been generated and returned, the method doesn’t return that number again. To do this you will have to store every number generated.

import java.util.Random;

public class ranGen {

    public Integer random (Integer integer){
        Random rand = new Random();;
        int min=0, max=100;
        int randomNum = rand.nextInt(max - min + 1) + min;

        System.out.println(randomNum);
        return randomNum;
        }


    public void random50 (Integer integer){


        Random rand = new Random();;
        int min=0, max=50;
        int randomNum = rand.nextInt(max - min +1) + min;

        System.out.println(randomNum);
        }


    public static void main(String[] args) {
        ranGen process = new ranGen();

        if(process.random(null) > 50){
            process.random50(null);
        }

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:00:40+00:00Added an answer on June 18, 2026 at 6:00 am

    The goal of the homework, it seems, is to make you learn what method parameters are. The first step is to write a method that returns a random integer in the range of 1 to 100. So this method doesn’t have any parameter. Its signature should be

    public int generateRandomNumberBetween0And100()
    

    The second step is to write a method which takes a parameter specifying the top number. Its signature should thus be:

    public int generateRandomNumberBetween0And(int topValue)
    

    The third step is to write a method taking two values as parameter: the bottom and the top value. Its signature should thus be:

    public int generateRandomNumberBetween(int bottomValue, int topValue)
    

    The last step is a bit more tricky. It asks you to remember the values a method has already generated, and to avoid generating them again. There is no parameter. Its signature should be

    public int generateUniqueRandomNumber()
    

    and its implementation should basically do the following:

    1. generate random number
    2. if random number is in the set of already generated numbers, go to 1
    3. store the generated number in the set of already generated numbers
    4. return the generated number.
    

    Of course, the set of already generated numbers is empty at the beginning.

    Note that you should use int rather than Integer. There’s no reason to accept null as argument, and the methods should never return null. So the primitive int type should be preferred.

    Also note that the methods should not print the generated number, but return it. So they should have int as their return type, and not void.

    And classes, by convention, start with an upper-case letter and don’t abbriviate words. So your class should be named RandomGenerator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is more of a theoretical question than code: What i did till now
This snippet of code was supposed to generate a random number which represents a
I did not make any changes on the code. I dont receive any errors
I'm trying to make a click at desktop through code, so I did that:
Somehow my code doesn't work any more (it did work before with the exact
Did I not get enough sleep or what? This following code var frame=document.getElementById(viewer); frame.width=100;
Looking for an easy way to make a random number, i came across a
just did my first test with MASM and FASM with the same code (almos)
I am using this code to generate a random permutation of a vector using
I was running some code that did a printout in a swingworker. I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.