|
I'm working on a project for a test. When the person enters a letter grade (A, B, C, and so on...), it should return with one of the phrases written in the code. I can't seem to get it to work. Any suggestions?
/*
Project 3
Date: November 1, 2005
Program Name: multiply2.java
*/
import java.io.*;
public class Multiply2
{
public static void main (String[] args ) throws IOException
{
//Declaring variables
int grade;
boolean done = false;
//Opening messages
System.out.println("\t\tChapter 4 Test");
System.out.println("");
//Calling the user-defined methods
grade = getNumber();
System.out.println("\t\tEnter the letter grade:" );
}
public static int getNumber() throws IOException
{
//Declaring variables
BufferedReader dataIn = new BufferedReader (new InputStreamReader(System.in));
String inputData;
char grade;
//Get a value from user
System.out.println("Enter the multiplication table you wish to practice:");
inputData = dataIn.readLine();
grade = Character.parseChar( inputData );
//Return a value to main
return grade;
}
public static int enterGrade(int answer) throws IOException
{
//Delcaring variablaes
BufferedReader dataIn = new BufferedReader (new InputStreamReader(System.in));
String inputData;
char grade;
{
//Display question and get answer
System.out.println( "Enter the letter grade: " );
inputData = dataIn.readLine();
answer = Character.parseChar( inputData );
if (answer == A)
{
System.out.println("\tOutstanding!");
}
if (answer == B)
{
System.out.println("\tGreat!");
}
if (answer == C)
{
System.out.println("\tGood!");
}
if (answer == D)
{
System.out.println("\tNeeds more work!");
}
if (answer == F)
{
System.out.println("\tNeeds help!");
}
else
{
System.out.println("\tError");
}
}
return grade;
}
}
|
|
|
|
|
import java.io.*;
public class M2
{
static BufferedReader dataIn;
public static void main (String[] args ) throws IOException
{
dataIn = new BufferedReader(
new InputStreamReader(System.in));
//Opening messages
System.out.println("\t\tChapter 4 Test");
System.out.println();
//Calling the user-defined methods
int number = getNumber();
System.out.println("number = " + number);
String grade = getGrade(number);
System.out.println("grade = " + grade);
String comment = getGradeComment();
System.out.println("comment = " + comment);
// close reader
dataIn.close();
}
public static int getNumber() throws IOException
{
//Declaring variables
String inputData;
int grade;
//Get a value from user
System.out.println("Enter the number grade:");
inputData = dataIn.readLine();
grade = Integer.parseInt(inputData);
//Return a value to main
return grade;
}
public static String getGrade(int rawScore)
{
// System.out.println("rawScore = " + rawScore);
//Delcaring variables
String answer = "unknown";
if (rawScore >= 90)
{
answer = "A";
}
if (rawScore >= 80 && rawScore < 90)
{
answer = "B";
}
if (rawScore >= 70 && rawScore < 80)
{
answer = "C";
}
if (rawScore >= 60 && rawScore < 70)
{
answer = "D";
}
if (rawScore < 60)
{
answer = "F";
}
return answer;
}
private static String getGradeComment() throws IOException
{
System.out.println("\t\tEnter the letter grade:" );
String letterGrade = dataIn.readLine();
String comment = "unknown";
if(letterGrade.equals("A"))
{
comment = "Outstanding!";
}
if(letterGrade.equals("B"))
{
comment = "Great!";
}
if(letterGrade.equals("C"))
{
comment = "Good!";
}
if(letterGrade.equals("D"))
{
comment = "Needs more work!";
}
if(letterGrade.equals("F"))
{
comment = "Needs help!";
}
return comment;
}
}
|
|
|
|
|
Thanks so much! But I only need for it to do the second step. How can I get it to do just that?
|
|
|
import java.io.*;
public class M2
{
public static void main (String[] args )
{
BufferedReader dataIn = null;
try
{
dataIn = new BufferedReader(
new InputStreamReader(System.in));
//Opening messages
System.out.println("\t\tChapter 4 Test");
System.out.println();
System.out.println("Enter the letter grade:" );
String letterGrade = dataIn.readLine();
//Calling the user-defined methods
String comment = getGradeComment(letterGrade);
System.out.println("comment = " + comment);
// close reader
dataIn.close();
}
catch(IOException ioe)
{
System.out.println("read exception: " + ioe.getMessage());
}
}
private static String getGradeComment(String grade)
{
String comment = "unknown";
if(grade.equals("A"))
{
comment = "Outstanding!";
}
if(grade.equals("B"))
{
comment = "Great!";
}
if(grade.equals("C"))
{
comment = "Good!";
}
if(grade.equals("D"))
{
comment = "Needs more work!";
}
if(grade.equals("F"))
{
comment = "Needs help!";
}
return comment;
}
}
|
|
|
|
|
|
|
|
|
|