JMU JMU - Department of Computer Science
Help Tools
Computer-Based Programming Portion of Exam 2 - Sample


This is an "open book" examination but you must work entirely on your own.

The source code you submit must be entirely your work and must be written entirely during the exam period. The use of any pre-existing code (other than that provided as part of the exam) is prohibited.

Your code need not comply with the course style guidelines and need not include comments. You should not submit any tests.

No limit will be placed on the number of submissions but, obviously, you must complete the exam during the exam period and submissions waste time. Autolab will not provide hints. Your last submission is the one that will be graded.

For question 1, you must submit a .zip file named e2q1.zip that contains just the file TerminalUI.java.

For question 2, you must submit a .zip file named e2q2.zip that contains just the file ArrayProcessor.java.

For question 3, you must submit a .zip file named e2q3.zip that contains just the file GradeBook.java.

  1. (10 points) Complete the readOdd() method in the following TerminalUI class. Your solution must be consistent with the comments describing the method.
    public class TerminalUI
    {
        import java.util.Scanner;
    
        /**
         * Prompts for (repeatedly, if necessary) and reads
         * an odd number from standard input.
         *
         * @param  prompt    The String to use as the prompt
         * @param  keyboard  The Scanner to read from
         * @return           The odd number that was (ultimately) entered
         */
        public static int readOdd(String prompt, Scanner keyboard)
        {
    
        }
    }
      

    Your solution must write the prompt to System.out and must read from the Scanner named keyboard.

  2. (15 points) Write a class named ArrayProcessor that contains a static method that is passed a double named needle, a double[] named haystack, and a double named tolerance (in that order) and returns true if the array named haystack contain a value that is withing the given tolerance of the value needle.
  3. (25 points) Write a class named GradeBook that contains a static method named getGrade() that is passed an int[] named records that contains course numbers in the even-numbered elements and the corresponding course grades in the odd-numbered elements and an int named course, and returns the grade associated with course (or -1 if there is no such course).

    For example, if it is passed the array {149, 95, 159, 83, 240, 78} and the value 159 it must return 83, whereas if it is passed the same array and the value 261 it must return -1.

Copyright 2020