\Java
TestPlan2.java
//********************************************************************
//
// TestPlan2.java
// Program description: A program for learning about Test Plans
//
//********************************************************************
//
// Program Description:
// --------------------
// Program determines if a student is eligible for a scholarship
//
// Input Requirements:
// -------------------
// college: a String, either "CENG" or "COB"
// GPA: a float >= 0.0 and <= 4.0, cumulative Grade Point Avg.
//
// Output Requirements:
// --------------------
// Prompt message: "Enter your college, CENG or COB:"
// Prompt message: "Enter your GPA:"
// Error message: "Invalid college name,"
// Error message: "Invalid GPA value,"
// Answer message: "You are eligible for a CENG scholarship."
// Answer message: "You are eligible for a COB scholarship."
// Answer message: "You are not eligible for a scholarship."
//
// Program Preconditions:
// ----------------------
// None.
//
// Problem Solution Discussion:
// ----------------------------
// This program prompts the user to enter his or her college and GPA.
// It then checks if valid inputs have been entered. If college is not
// CENG or COB, that's invalid, and an error message is printed.
// If GPA is less than 0 or greater than 4, that's invalid, and an
// error message is printed. If the inputs are valid, the comparisons
// are made to determine scholarship eligibility.
// If student is in CENG and GPA is 3.2 or above, then eligible for
// CENG scholarship and message is printed.
// If student is in COB and GPA is 3.3 or above, then eligible for
// COB scholarship and message is printed.
// Otherwise "not eligible" message is printed.
//
//
// Problem Solution Design Steps:
// ------------------------------
//
// Data structures:
// ----------------
//
// colleg: String
// GPA: float
//
// Algorithm:
// ----------
//
// 1. Prompt for college
// 2. Input: college
// 3. Prompt for GPA
// 4. Input GPA
// 5. If not college CENG or COB
// Print error message
// 6. else if GPA outside 0.0-4.0 range
// Print error message
// 7. else
// A. if college is CENG and GPA >= 3.2
// Print "eligible for a CENG scholarship"
// B. else if college is COB and GPA >= 3.3
// Print "eligible for a CENG scholarship"
// C. else
// Print "not eligible for a scholarship"
// Test Plan
// ----------
//
// Note: This Test Plan is designed to test the whole program
//
//
// Test Case Description Input Data Expected Results
// --------------------- ---------- ----------------
// 1. If college=CENG and GPA=3.2 CENG & 3.2 " You are eligible for a CENG scholarship."
// 2. If college=CENG and GPA=3.0 CENG & 3.0 " You are NOT eligible for a scholarship."
// 3. If college=COB and GPA=3.2 COB & 3.2 " You are eligible for a COB scholarship."
// 4. If college=CENG and GPA=3.0 COB & 3.0 " You are NOT eligible for a scholarship."
//********************************************************************
import cs1.Keyboard;
public class TestPlan2
{
//-----------------------------------------------------------------
// Comment
//-----------------------------------------------------------------
public static void main (String[] args)
{
String college; // abbreviation for college
float GPA; // cumulative Grade Point Average'
// Prompt for and read input data
System.out.print( "Enter your college, CENG or COB: " );
college = Keyboard.readString();
System.out.print( "Enter your GPA: " );
GPA = Keyboard.readFloat();
// Check for valid input
if ( ! college.equals("CENG") && ! college.equals("COB") )//changed OR to AND operator
System.out.println( "Invalid college name, " + college );
else if ( GPA < 0.0f || GPA > 4.0f )
System.out.println( "Invalid GPA value, " + GPA );
// Input is all vaid. Determine if elegible for scholarship.
else
{
// Check if eligible for CENG scholarship
if ( college.equals("CENG") && GPA >= 3.2 )
System.out.println( "You are eligible for a CENG scholarship." );
// Check if eligible for COB scholarship
else if ( GPA >= 3.2 )
System.out.println( "You are eligible for a COB scholarship." );
// Not eligible for either
else
System.out.println( "You are not eligible for a scholarship." );
}
} // end main
} // end class TestPlan2