Use the Lottery class to the left as the superclass. Create the PowerBall class as a subclass of Lottery. Override the shuffle method so that it returns an ArrayList of six random integers up to but not including 100. CODE: import java.util.ArrayList; import java.util.Random; class Lottery { public ArrayList shuffle() { Random r = new Random(); ArrayList nums = new ArrayList(); for (int i = 0; i < 5; i++) { int num = r.nextInt(20); nums.add(num); } return nums; } } //add class definitions below this line class PowerBall extends Lottery { public ArrayList shuffle() { Random r = new Random(); ArrayList nums = new ArrayList(); for (int i = 0; i < 6; i++) { int num = r.nextInt(100); nums.add(num); } return nums; } } //add class definitions above this line public class Exercise1 { public static void main(String[] args) { //add code below this line PowerBall p = new PowerBall(); System.out.println(p.shuffle()); //add code above this line } }
Use the Lottery class to the left as the superclass. Create the PowerBall class as a subclass of Lottery. Override the shuffle method so that it returns an ArrayList of six random integers up to but not including 100.
CODE:
import java.util.ArrayList;
import java.util.Random;
class Lottery {
public ArrayList<Integer> shuffle() {
Random r = new Random();
ArrayList<Integer> nums = new ArrayList<Integer>();
for (int i = 0; i < 5; i++) {
int num = r.nextInt(20);
nums.add(num);
}
return nums;
}
}
//add class definitions below this line
class PowerBall extends Lottery {
public ArrayList<Integer> shuffle() {
Random r = new Random();
ArrayList<Integer> nums = new ArrayList<Integer>();
for (int i = 0; i < 6; i++) {
int num = r.nextInt(100);
nums.add(num);
}
return nums;
}
}
//add class definitions above this line
public class Exercise1 {
public static void main(String[] args) {
//add code below this line
PowerBall p = new PowerBall();
System.out.println(p.shuffle());
//add code above this line
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images