Spaces:
Running
Running
File size: 1,698 Bytes
dc0be62 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
The program defines a class called LotteryRound.
Complete the class by typing
1. Attributes
week (integer)
numbers (integer-typed list)
jackpot (double)
2. Constructor, which takes as parameters the values of the attributes in the order given in step 1.
import java.util.Random;
import java.util.ArrayList;
public class Test{
public static void main(String[] args){
final Random r = new Random();
ArrayList<Integer> numbers = new ArrayList<>();
for (int i=0; i<7; i++) {
numbers.add(r.nextInt(39) + 1);
}
int round = r.nextInt(52) + 1;
double jackpot = r.nextInt(5000000) + 1000000;
System.out.println("Creating an object with parameters");
System.out.println("Week: " + round);
System.out.println("Numbers: " + round);
System.out.println("Jackpot: " + jackpot);
LotteryRound lk = new LotteryRound(round, numbers, jackpot);
System.out.println("Olio: " + lk);
}
}
class LotteryRound {
// ADD ATTRIBUTES
int week;
ArrayList<Integer> numbers;
double jackpot;
// ADD CONSTRUCTOR
public LotteryRound(int week, ArrayList<Integer> numbers, double jackpot) {
this.week = week;
this.numbers = numbers;
this.jackpot = jackpot;
}
@Override
public String toString() {
return "LotteryRound [week=" + week + ", numbers=" + numbers + ", jackpot=" + jackpot + "]";
}
}
Creating an object with parameters
Week: 17
Numbers: 17
Jackpot: 2222680.0
Olio: LotteryRound [week=17, numbers=[2, 2, 3, 6, 33, 39, 5], jackpot=2222680.0]
|