Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

jump to level 1 integers seedval, lowbound and upbound are read from in…

Question

jump to level 1
integers seedval, lowbound and upbound are read from input. lowbound and upbound represent the minimum and maximum numbers of trinkets in each basket, respectively. complete the following tasks:

  • call randgens setseed() with seedval as the argument.
  • assign variables basket1 and basket2 each with a random number of trinkets between lowbound and upbound, both inclusive.
  • assign variable totaltrinkets with the sum of basket1 and basket2.

click here for example
12 int basket1;
13 int basket2;
14
15 seedval = scnr.nextint();
16 lowbound = scnr.nextint();
17 upbound = scnr.nextint();
18
19 / your code goes here /
20
21 system.out.println(basket1);
22 system.out.println(basket2);
23 system.out.println(\sum: \ + totaltrinkets);
24 }
25 }

Explanation:

Step1: Set the seed for the random number generator

randGen.setSeed(seedVal);

Step2: Generate a random number for basket1

basket1 = lowBound + randGen.nextInt(upBound - lowBound + 1);

Step3: Generate a random number for basket2

basket2 = lowBound + randGen.nextInt(upBound - lowBound + 1);

Step4: Calculate the total number of trinkets

totalTrinkets = basket1 + basket2;

Answer:

The code to complete the tasks is:

randGen.setSeed(seedVal);
basket1 = lowBound + randGen.nextInt(upBound - lowBound + 1);
basket2 = lowBound + randGen.nextInt(upBound - lowBound + 1);
totalTrinkets = basket1 + basket2;