COMP 110 Final Exam Review 5

COMP 110 Final Exam Review 5 - COMP110-001 Final Exam 1/11...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
COMP110-001 Final Exam 1/11 COMP 110-001 Spring 2007 Instructor: Christine Xu Final Exam Date: May 7, 2007 This final exam is worth 17% of your final grade. Pledge: I have neither given nor received unauthorized aid on this exam. Your Name:___________________________ PID: _______________________ 1. [1] Write a method header (the very first line of a method) for methods that do each of the following things. Do not write the body of the method, just the header. a. A method named doubleValue that takes in an argument of type int and returns twice the argument’s value. public int doubleValue(int value) Or: private int doubleValue(int value) b. A method named piCount that takes in an array of doubles and returns the number of elements that are greater than Pi. public int piCount(double[] array) Or: private int piCount(double[] array) 2. [1] Write the code that will declare an array of type int, and then use a loop structure to fill in the array. After your code executes, the array should look as follows: 0 2 4 6 8 10 12 14 16 18 int [] array = new int[10]; for(i = 0; i < array.length; i++) array[i] = 2 * i;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COMP110-001 Final Exam 2/11 3. [1] The following program fragment has almost identical code repeated three times. Re-structure the program so that the code is instead contained within a method which can be called three times. [ Hint: the method should probably take an array of type int as an input parameter ] /** This program prints out the test score grade average, the homework score grade average and the quiz score grade average */ public static void main(String [] args) { //create arrays that contain grades int [] testScores = {90, 79, 84}; int [] homeworkScores = {95, 90, 100, 80, 70} ; int [] quizScores = {87, 55, 100, 99}; int sum; double average; //find and print out the test score average sum = 0; for(int i = 0; i < testScores.length; i++) { sum = sum + testScores[i]; } average = sum / testScores.length; System.out.println( average ); //find and print out the homework score average sum = 0; for(int i = 0; i < homeworkScores.length; i++) { sum = sum + homeworkScores[i]; } average = sum / homeworkScores.length;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/31/2009 for the course COMP 110 taught by Professor Qi during the Spring '09 term at Linn Tech.

Page1 / 11

COMP 110 Final Exam Review 5 - COMP110-001 Final Exam 1/11...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online