Ex11GradeBookObject

Ex11GradeBookObject - import java.util.Scanner public class...

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

View Full Document Right Arrow Icon
import java.util.Scanner; public class Grades { public static void main(String args[]) { // declare variables CumGPA gpa; Scanner readInput; String gradeEarned; int numUnits; int totalPoints, totalUnits; // create and initialize variables readInput = new Scanner( System.in ); totalPoints = 0; totalUnits = 0; // read in information from the user do { // read input System.out.print(.Enter your grade.); gradeEarned = readInput.nextLine(); System.out.print(.Enter units.); numUnits = readInput.nextInt(); readInput.nextLine(); // skip past enter key if (numUnits < 0) break; char c = gradeEarned.charAt(0); totalUnits += numUnits; switch (c) { case ('A'): case ('a'): totalPoints += (4*numUnits); break; case ('B'): case ('b'): totalPoints += (3*numUnits); break; case ('C'): case ('c'): totalPoints += (2*numUnits); break; case ('D'): case ('d'): totalPoints += numUnits; break; default: break; } // end of switch (c) nextGPA = ((double)totalUnits) / ((double)totalPoints); System.out.printf(.Cumulative GPA so far:%f\n.,nextGPA);
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 12/27/2011 for the course CMPSC 5 taught by Professor Franklin during the Fall '09 term at UCSB.

Page1 / 3

Ex11GradeBookObject - import java.util.Scanner public class...

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