CSC216fall05exam1v1key

CSC216fall05exam1v1key - 1 CSC216 Fall 05 Exam 1 Student...

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

View Full Document Right Arrow Icon
CSC216 Fall 05 Exam 1 Student Name ____________________________________________________ This exam is closed book and closed notes. There are 105 points (5 points extra credit). You are not required to provide documentation for the code you write. Good luck! Part 1 Java Basics (35 points) (25 points) 1. Complete/fill in the Student class below (and continued on next page) . Each Student has a name, an array with room for up to 3 integer test scores, as well as the current number of scores as private instance variables. Do not document the code you write but do use good style and programming conventions . public class Student { 3 pts //put instance variable here. // 3 points private String name; private int [ ] scores; // ok if = new int[3]; private int count; ___ public ___ String (String theName){ 3 pts scores = new int [ 3]; // 2 points count = 0; //ok if omitted, defaults to 0 name = theName; // 1 point } /** *add the score to the array if there is room. If there is no room, ignore the score * and return * @param score integer value greater than or equal to zero */ public void addScore (int score ) { 5 pts if ( count >= scores.length) { return; } //2 pts scores[count] = score; //2 pts count++;//1 pt } 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
/** Calculates and returns the average of the current test scores for this student. * 0,1,2, or 3 scores may be averaged depending on the current number for this student * * The average is calculated using floating point arithmetic. * @return average of up to three scores */ public double average ( ) { 5 pts double total = 0; for (int I = 0; I < count; i++) { total = total + score[i]; } // deduct 2 points if code could have resulted in division by zero (count is zero)
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 10/13/2008 for the course CSC 216 taught by Professor Miller during the Spring '08 term at N.C. State.

Page1 / 7

CSC216fall05exam1v1key - 1 CSC216 Fall 05 Exam 1 Student...

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