30S-Section-Solution

30S-Section-Solution - CS106A Handout 30S th th 2011 Spring...

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

View Full Document Right Arrow Icon
CS106A Handout 30S Spring 2011 May 11 th – 13 th , 2011 Section Solution Lab Problem 1 Solution: Exam Statistics public class ExamStatistics extends ConsoleProgram { public void run() { setFont("Courier-Bold-18"); int [] histogram = new int [11]; double runningScoreSum = 0.0; for ( int i = 0; i < NUM_STUDENTS ; i++) { String space = (i < 9 ? " " : ""); double score = readDouble("exam " + (i + 1) + ": " + space, 0.0, 100.0); runningScoreSum += score; int bucket = ( int ) (score / 10); histogram[bucket]++; } println(); printMean(runningScoreSum/ NUM_STUDENTS ); printHistogram(histogram); } private void printMean( double mean) { println("mean:"); println(mean); println(); } private void printHistogram( int [] histogram) { println("histogram:"); for ( int bucket = 0; bucket < histogram.length; bucket++) { printLabel(bucket); for ( int i = 0; i < histogram[bucket]; i++) { print("*"); } println(); } } private void printLabel( int bucket) { if (bucket == 0) { print("00-09: "); } else if (bucket == 10) {
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/28/2011 for the course CS 106A taught by Professor Sahami,m during the Spring '08 term at Stanford.

Page1 / 3

30S-Section-Solution - CS106A Handout 30S th th 2011 Spring...

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

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