www.webdeveloper.com
Results 1 to 2 of 2

Thread: Help with an application

  1. #1
    Join Date
    Nov 2005
    Posts
    2

    Help with an application

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


  2. #2
    Join Date
    Sep 2005
    Posts
    28

    Debugged

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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles