Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import java.util.Random; public class Main { public static void main(String[] ar

ID: 672908 • Letter: I

Question

import java.util.Random;


public class Main {
   public static void main(String[] args) {
   Random rand = new Random();
   int Low = 1;
   int High = 20;
   int n = rand.nextInt(High-Low) + Low;
   System.out.println(n);
   int low = 1;
   int high = 100;
   int list = rand.nextInt(high-low) + low;
   System.out.print(list);
   PositionalList<Integer> a = new LinkedPositionalList<Integer>();

I am having trouble with creating a new LinkedPositionalList of size n (from above) of numbers of list (from above). Can anyone help me with this problem?

Explanation / Answer

import java.util.Random;

public class Main {
   public static void main(String[] args) {
       Random rand = new Random();
       PositionalList<Integer> a = new LinkedPositionalList<Integer>();
       int Low = 1;
       int High = 20;
       int n = rand.nextInt(High - Low) + Low;
       System.out.println(n);
       // iterate through for loop n times, to add n elements into the list
       // to add an element, use insert method
       for (int i = 0; i < n; ++i) {
           int low = 1;
           int high = 100;
           int list = rand.nextInt(high - low) + low;
           System.out.print(list);
           a.insert(list); // inserting integer 'list' into the PositionalList 'a'
       }
       System.out.println(a); // prints the list
   }
}