Java Reference
In-Depth Information
concept or technique completely, don't use it until your understanding is complete. The
problem of using partially understood concepts and techniques can be illustrated by the
following program.
Suppose that we want to write a program that analyzes a student's GPA. If the GPA is
greater than or equal to 3.9, the student makes the dean's honor list. If the GPA is less
than 2.00, the student is sent a warning letter indicating that the GPA is below the
graduation requirement. So consider the following program:
//GPA program with bugs.
4
import java.util.*;
//Line 1
public class GPABugProg
//Line 2
{
//Line 3
static Scanner console = new Scanner(System.in);
//Line 4
public static void main(String[] args)
//Line 5
{
//Line 6
double gpa;
//Line 7
System.out.print("Enter the GPA: ");
//Line 8
gpa = console.nextDouble();
//Line 9
System.out.println();
//Line 10
if (gpa >= 2.0) //Line 11
if (gpa >= 3.9) //Line 12
System.out.println("Dean\'s Honor List."); //Line 13
else
//Line 14
System.out.println("The GPA is below the "
+ " graduation requirement. \nSee your
"
+ "academic advisor.");
//Line 15
}
//Line 16
}
//Line 17
Sample Runs: (In these sample runs, the user input is shaded.)
Sample Run 1:
Enter the GPA: 3.91
Dean's Honor List.
Sample Run 2:
Enter the GPA: 3.8
The GPA is below the graduation requirement.
See your academic advisor.
Sample Run 3:
Enter the GPA: 1.95
Search WWH ::




Custom Search