ex15b - char c = gradeEarned.charAt(0); totalUnits +=...

Info iconThis preview shows page 1. 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;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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); } while ( numUnits > 0 ); } // end of main } // end of class Grades...
View Full 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.

Ask a homework question - tutors are online