CASE STUDY^189
We need to declare variables to hold the name, the scores, the Studentobject, and the
message. We also need to import Student,Name, and java.io.*. Now that we have
designed the algorithm for our application, we are ready to implement it in Java.
//**
// This application determines whether a student is passing,
// marginally passing, or failing, based on three test scores.
//**
importjava.io.*; // For IOException, BufferedReader
importStudent; // Represents a student
importName; // A basic representation of a name
public classStudentStatus
{
public static voidmain(String[] args) throwsIOException
{
Name inputName; // Place to hold input name
intscore1; // First test score
intscore2; // Second test score
intscore3; // Third test score
Student theStudent; // Student record
String message; // Output message
BufferedReader in; // Input source
// Input name and three scores
in = newBufferedReader(newInputStreamReader(System.in));
inputName = newName();
System.out.print("Enter first score: ");
score1 = Integer.parseInt(in.readLine());
System.out.print("Enter second score: ");
score2 = Integer.parseInt(in.readLine());
System.out.print("Enter third score: ");
score3 = Integer.parseInt(in.readLine());
// Create a student record
theStudent = newStudent(inputName, score1, score2, score3);
// Create basic message with echo print of input
message = inputName.full() + " with scores of "+ score1 + ", "+
score2 + ", and "+ score3 + " is ";
// Determine status and finish building message
if(theStudent.equalStatus(Student.FAILING))
message = message + "failing.";
else if(theStudent.equalStatus(Student.MARGINAL))
message = message + "marginally passing.";
else
message = message + "passing.";
System.out.println(message); // Output final message
}
}