Text: Coded in Java
Thank you.
Question 20 (2 points)
Write the Java code to declare and instantiate an array that will hold the number of books that each child in a classroom read over the summer.
The array should have space for book counts for up to 30 children in one classroom.
Question 21 (4 points)
Assume the array has been filled with a book count for each child in one classroom, and the number of children in the classroom is stored in the variable kidCount.
Write the Java code to display the number of books read by any child who read between 10 and 100 books, including 10 and 100.
Question 22 (3 points)
Given the following class data field declarations:
public class Location {
private String state;
private int zipCode;
}
Write a constructor for this class that will initialize the state field to "Colorado" and will use a parameter value to initialize the zipCode field.
Question 23 (2 points)
Using the constructor you created in the previous question, instantiate an object with the zip code field set to 80221 (Regis University's zip code).
Question 24 (4 points)
Given the following method writeSomething0:
public static void writeSomething(double outVal) {
File outFile = new File("out.txt");
PrintWriter printFile = new PrintWriter(outFile);
// missing code (a) to prevent using bad parameter values
// missing code (b) to write to the file
}
The method should throw a RuntimeException when the parameter value is not between 5 and 500 (inclusive), meaning the values 5 and 500 are valid parameter values, and the Exception object message will be "Bad parameter value X" where X is the unformatted bad value.
Supply missing code (a) to recognize invalid parameter values and throw the exception.
Question 25 (4 points)
Using the method from the previous question, when an exception is NOT thrown, the parameter value will be written to the out.txt file.
Supply missing code (b) to write out the value of the parameter to the out.txt file formatted like this: xxxxx.xxx and followed by a newline immediately afterwards.