{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

09-03 Class Notes CS 107

# 09-03 Class Notes CS 107 - score = keyboard.nextInt...

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

Announcements: http://scratch.mit.edu/galleries/view/93081 Take a look at some of your classmates' solutions to program 1 online at: See the copy of what I write in class, as a pdf a. See the video of the class session b. Don't forget, there are 2 places to look for class notes: 09-03 Class Notes CS 107 Friday, September 03, 2010 3:24 PM 107 Fall 2010 Page 1

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

View Full Document
Questions? Last Time: Types, Arithmetic operators, precedence, Strings for output Today: if statements, writing a simple program For the if statement notes, see other page under today's notes. Problem: write code to assign a letter grade ('A','B'…'F') based on score. Grade Score int score = 0; char grade = ' '; // determine what the correct grade is depending on the score System.out.print("Enter the score: ");
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: score = keyboard.nextInt(); if( (score>=90) && (score <=100) ) { grade = 'A'; } if( (score>=80) && (score <90) ) { grade = 'B'; } if( (score>=70) && (score <80) ) { grade = 'C'; } if( (score>=60) && (score <70) ) { grade = 'D'; } if( (score< 60) ) { 107 Fall 2010 Page 2 } if( (score< 60) ) { grade = 'F'; } // It makes more sense to do the following instead of the above: if( score>=90) { grade = 'A'; } else if( score >=80) { grade = 'B'; } else if( score >=70) { grade = 'C'; } else if( score >=60) { grade = 'D'; } else { grade = 'F'; } See description of Program #2, the Toothpick puzzle. In particular see the sample program that is included with it. 107 Fall 2010 Page 3...
View Full Document

{[ snackBarMessage ]}