Click to See Complete Forum and Search --> : Help with an application


ebs
11-02-2005, 10:57 AM
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?


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;
}
}

dayanandasekar
11-02-2005, 10:59 PM
I don't what you are trying to do anyway I have cleared a few errors in a hurry since I am leaving . . .

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 t he user-defined methods
grade = getNumber();
System.out.println("\t\tEnter the letter grade:" );
}

public static int getNumber() throws IOException
{
//Declaring variables
DataInputStream dis = new DataInputStream(System.in);
String inputData;
char grade;

//Get a value from user
System.out.println("Enter the multiplication table you wish to practice:");
inputData = dis.readLine();
grade =inputData.charAt(0);

//Return a value to main
return grade;
}

public static void enterGrade(int answer) throws IOException
{
//Delcaring variablaes
DataInputStream dis = new DataInputStream(System.in);
String inputData;
// char grade=null;

{
//Display question and get answer
System.out.println( "Enter the letter grade: " );
inputData = dis.readLine();
answer = inputData.charAt(0);

switch(answer)
{
case 'A':
System.out.println("\tOutstanding!");
// return grade;
break;

case 'B':
System.out.println("\tGreat!");
// return grade;
break;

case 'C':
System.out.println("\tGood!");
// return grade;
break;

case 'D':
System.out.println("\tNeeds more work!");
// return grade;
break;

case 'F':
System.out.println("\tNeeds help!");
// return grade;
break;

default:
// return grade;
break;
}
}
}
}