codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Help!  Brooke at 14:35 on Wednesday, November 02, 2005
 

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




  Re: Help!  crwood at 18:56 on Wednesday, November 02, 2005
 


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


  Re: Help!  Brooke at 13:36 on Monday, November 07, 2005
 

Thanks so much! But I only need for it to do the second step. How can I get it to do just that?

  Re: Help!  crwood at 17:51 on Monday, November 07, 2005
 


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









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Need some help with javascript code in Unity!
•  Re: Perl - Read and Write output file
•  Re: Math.ceil depending on the number of decimal places
•  Re: drag from panel to panel..
•  Re: date of birth validation using java script-very urgent
•  Re: help me how to execute a linux shell script file(.sh file ) in perl
•  Save up to 80% on SSL Certificates, RapidSSL Certificate @ $ 11.00/yr.
•  help me
•  Re: substitute of goto in java???


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010