Question
In JAVA PLEASE CODE

Problem 2 (71 points) Create methods Create the following two methods for playing a lottery. /This method returns an ArrayList of Integers. The totalNums parameter tells us how many numbers will fill the ArrayList and the highestNum parameter tells us the max value of the numbers to be held in the ArrayList* ArrayList<Integer> generateNums(int totalNums, int highestNum)
media%2F8a8%2F8a8ec9ad-58a7-4794-81fc-9c
0 0
Add a comment Improve this question Transcribed image text
Answer #1
ArrayList<Integer> generateNums(int totalNums, int highestNum) {
    ArrayList<Integer> list = new ArrayList<>();
    Random random = new Random();
    for(int i = 0; i < totalNums; ++i) {
        list.add(random.nextInt(highestNum+1));
    }
    return list;
}

public static boolean checkNum(int n, ArrayList<Integer> a) {
    for(int i = 0; i < a.size(); ++i) {
        if(a.get(i) == n) {
            return true;
        }
    }
    return false;
}
Add a comment
Answer #2
ArrayList<Integer> generateNums(int totalNums, int highestNum) {
    ArrayList<Integer> list = new ArrayList<>();
    Random random = new Random();
    for(int i = 0; i < totalNums; ++i) {
        list.add(random.nextInt(highestNum+1));
    }
    return list;
}

public static boolean checkNum(int n, ArrayList<Integer> a) {
    for(int i = 0; i < a.size(); ++i) {
        if(a.get(i) == n) {
            return true;
        }
    }
    return false;
}


answered by: ANURANJAN SARSAM
Add a comment
Know the answer?
Add Answer to:
In JAVA PLEASE CODE Problem 2 (71 points) Create methods Create the following two methods for...
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
  • 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...

  • *Java* Hi. I need some help with creating generic methods in Java. Write a program GenMethods...

    *Java* Hi. I need some help with creating generic methods in Java. Write a program GenMethods that has the following generic methods: (1) Write the following method that returns a new ArrayList. The new list contains the nonduplicate (i.e., distinct) elements from the original list. public static ArrayList removeDuplicates(ArrayList list) (2) Write the following method that shuffles an ArrayList. It should do this specifically by swapping two indexes determined by the use of the random class (use Random rand =...

  • (Java Programmin): Sum() and max() in ArrayList a. Write a method that returns the maximum value...

    (Java Programmin): Sum() and max() in ArrayList a. Write a method that returns the maximum value in an ArrayList of integers. The method returns null if the list is null or the list size is 0.          public static Integer max(ArrayList<Integer> list) b. Write a method that returns the sum of all numbers in an ArrayList: public static Integer sum(ArrayList<Integer> list) c. Write a test program that prompts the user to enter a sequence of numbers ending with 0, and invokes...

  • On java create the following: please solve it complete or don't since it considered as part...

    On java create the following: please solve it complete or don't since it considered as part of problem 1 not even the whole question. The main method that does: Create 2 stacks s1 and s2 Insert 23 integers between 20 and 60 (do not insert duplicates) into s1 Insert 35 integers between 10 and 80 (do not insert duplicates) into s2. Give the user the choice which methods (2-7) to call and option to exit LinkedList<Integer> LL = new LinkedList<Integer>)...

  • Write a JAVA code to do the following: create a class and add methods to count...

    Write a JAVA code to do the following: create a class and add methods to count the number of primitive fields, number of methods with primitive return types, a method that will also return the number of primitive in a given parameter. they are: public int getNumberOfPrimitiveMethods(Class host) public int getNumberOfPrimitiveFields(Class host) public int getNumberOfPrimitiveParameters(Method host) also public int getNumberOfPrivateMethods (Class host) public int getNumberOfPublicMethods (Class host)

  • In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are...

    In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...

  • A java exercise please! Write a static method named swapHavles that takes an ArrayList of integers...

    A java exercise please! Write a static method named swapHavles that takes an ArrayList of integers as a a parameter and returns a new ArrayList that has every element in the second half of the original ArrayList swapped with every element in the first half of the original ArrayList. Note: • You can assume that the ArrayList passed to this method as a parameter always contains an even number of elements and will always contain at least two elements. For...

  • Java programming The purpose of this problem is to practice using a generic Urn class. NOTE:...

    Java programming The purpose of this problem is to practice using a generic Urn class. NOTE: Refer to the code for the ArrayStack class from Chapter 12. Use that code as a starting point to create the Urn class, modifying it to remove the methods in the ArrayStack class (push, pop, etc) then add the methods described below. Also change the variable names to reflect the new class. For example the array name should NOT be stack, instead it should...

  • Methods: Net beans IDE Java two methods. Identifier: calculateScore(String word) Parameters: word – the word for...

    Methods: Net beans IDE Java two methods. Identifier: calculateScore(String word) Parameters: word – the word for which you should calculate the points in Scrabble Return Value: int – the number of points for the parameter word Other: This method should be static. This method should use the following system for scoring: 0 – blank 1 – e, a, i, o, n, r, t, l, s, u 2 – d, g 3 – b, c, m, p 4 – f, h,...

  • Please help JAVA Create the following in Stack.java: An array of ints set to size 10...

    Please help JAVA Create the following in Stack.java: An array of ints set to size 10 to represent the Stack, an int variable for the index A constructor that sets the index to -1 A method called isEmpty (returns a boolean) that has no parameters. This method returns true if the Stack is empty and false if the Stack is not empty. true A method called push(returns a Boolean) that takes an int as a parameter. This method pushes, or...

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