The first image is the spec. The second image is my code, what/where should I fix?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The first image is the spec.

The second image is my code, what/where should I fix?

02
+
CountEvens.java
1 import java.util. *;
2
345 61009
3 public class Count Evens {
7
8
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 }
***
}
UW
public static void main(String[] args) {
Random r = new Random();
***
X W Find X w Mac x Q UW xed CSE X ed CSE X
edstem.org/us/courses/23931/lessons/47657/slides/271540/submissions?s=6405611
Terminal
}
*
// Generate 10 values between 0 and 100
System.out.println (count Evens (10, 100, r));
// Generate 100 values between 0 and 10
System.out.println (count Evens (100, 10, r));
// write your count Evens method here
public static int count Evens (int times, int max, Random r) {
int number = r.nextInt (max - 0 + 1) + 0;
if (number % 2 == 0) {
// Generate 1 value between 0 and 5
System.out.println(count Evens (1, 5, r));
// Generate 8 values between 0 and 37
System.out.println(count Evens (8, 37, r));
System.out.print(number);
}
return number;
/home/CountEvens.java Spaces: 4 (Auto)
W PHY X
Flip × 0.0 34 ×
x
*** ×
Transcribed Image Text:02 + CountEvens.java 1 import java.util. *; 2 345 61009 3 public class Count Evens { 7 8 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 } *** } UW public static void main(String[] args) { Random r = new Random(); *** X W Find X w Mac x Q UW xed CSE X ed CSE X edstem.org/us/courses/23931/lessons/47657/slides/271540/submissions?s=6405611 Terminal } * // Generate 10 values between 0 and 100 System.out.println (count Evens (10, 100, r)); // Generate 100 values between 0 and 10 System.out.println (count Evens (100, 10, r)); // write your count Evens method here public static int count Evens (int times, int max, Random r) { int number = r.nextInt (max - 0 + 1) + 0; if (number % 2 == 0) { // Generate 1 value between 0 and 5 System.out.println(count Evens (1, 5, r)); // Generate 8 values between 0 and 37 System.out.println(count Evens (8, 37, r)); System.out.print(number); } return number; /home/CountEvens.java Spaces: 4 (Auto) W PHY X Flip × 0.0 34 × x *** ×
1 - BA
es and
S
ons
prehension
ce - version B
✓
L
L
ens - version A ✓
A This lesson has ended you will not be able to save edits or submit.
Description
Write a static method called count Evens () that generates a
series of random numbers and returns the count of
generated numbers that are even. The method should take
three parameters:
●
int times - the number of random numbers to
generate
int max - the maximum possible value to generate
Random r - the Random object to use
The method should generate times random integers
between 0 and max (inclusive) using the Random object r
and return the number of values generated that are even.
You may assume that both times and max are positive
(greater than 0).
HINT: the Java modulo (%) operator will be helpful in
determining which numbers are even!
A main method has been provided to help test your
method. Your method should be written such that the
provided main method does not generate any errors. (Note
that the tests provided are not all possible tests.)
Click Expand to see the grading criteria for this problem.
▸ Expand
HARREGAN
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
+
1024
}
Console
CountEvens.java
}
system.out.println(countevens (
// Generate 1 value between 0 a
System.out.println(count Evens (1
// Generate 8 values between 0
System.out.println(count Evens (8
// write your countEvens method here
public static int count Evens (int tim
int number = 0;
for (int i = 1; i <= times; i++) {
number r.nextInt (max+1);
if(number % 2 == 0) {
System.out.print(number +
/home/CountEvens.java 21:44 Spaces: 4 (Auto)
4 4
2 34 36 12 26 26
}
34 72 0 46 4 74 16 61
8 0 4 2 10 2 4 10 2 8 8 0 4 8 10 8 4 0 2 6 864
8 8 4 8 8 8 4 2 4 0 2 2 8 2 6 2 0 4 10 10 645
✓ Program exited with code 0
Transcribed Image Text:1 - BA es and S ons prehension ce - version B ✓ L L ens - version A ✓ A This lesson has ended you will not be able to save edits or submit. Description Write a static method called count Evens () that generates a series of random numbers and returns the count of generated numbers that are even. The method should take three parameters: ● int times - the number of random numbers to generate int max - the maximum possible value to generate Random r - the Random object to use The method should generate times random integers between 0 and max (inclusive) using the Random object r and return the number of values generated that are even. You may assume that both times and max are positive (greater than 0). HINT: the Java modulo (%) operator will be helpful in determining which numbers are even! A main method has been provided to help test your method. Your method should be written such that the provided main method does not generate any errors. (Note that the tests provided are not all possible tests.) Click Expand to see the grading criteria for this problem. ▸ Expand HARREGAN 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 + 1024 } Console CountEvens.java } system.out.println(countevens ( // Generate 1 value between 0 a System.out.println(count Evens (1 // Generate 8 values between 0 System.out.println(count Evens (8 // write your countEvens method here public static int count Evens (int tim int number = 0; for (int i = 1; i <= times; i++) { number r.nextInt (max+1); if(number % 2 == 0) { System.out.print(number + /home/CountEvens.java 21:44 Spaces: 4 (Auto) 4 4 2 34 36 12 26 26 } 34 72 0 46 4 74 16 61 8 0 4 2 10 2 4 10 2 8 8 0 4 8 10 8 4 0 2 6 864 8 8 4 8 8 8 4 2 4 0 2 2 8 2 6 2 0 4 10 10 645 ✓ Program exited with code 0
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
Processes of 3D Graphics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education