Results 1 to 11 of 11
  1. #1
    zacharyrod is offline Member
    Join Date
    Nov 2009
    Location
    Seoul, Korea
    Posts
    5
    Rep Power
    0

    Exclamation BufferedReader, need help!

    Hello, my name is Zachary and I am new to this forum. This is my first question so please help me! I am creating a program that is made to print out my class schedule and average my GPA from input that I give it via keyboard. I am using a BufferedReader class and have reached this so far:

    /**
    * gradePointAverage BufferedReader is used to read input data from the keyboard and use that data to calculate my GPA *
    * @author (Zachary Rodriguez)
    * @version (11.04.09)
    */

    import java.io.*;

    public class GradePointAverageBufferedReader
    {
    public static void main(String[] args)
    {

    BufferedReader dataReader = new BufferedReader(new InputStreamReader(System.in));

    System.out.print(“Please enter your GPA in period one: “);
    strInputNumber = dataReader.readLine();
    System.out.print(“Please enter your GPA in period two: “);
    strInputNumber = dataReader.readLine();
    System.out.print(“Please enter your GPA in period three: “);
    strInputNumber = dataReader.readLine();
    System.out.print(“Please enter your GPA in period four: “);
    strInputNumber = dataReader.readLine();
    System.out.print(“Please enter your GPA in period five: “);
    strInputNumber = dataReader.readLine();
    System.out.print(“Please enter your GPA in period six: “);
    strInputNumber = dataReader.readLine();
    System.out.print(“Please enter your GPA in period seven: “);
    strInputNumber = dataReader.readLine();

    System.out.println("\tZachary Rodriguez");
    System.out.println("\t-----------------\n");
    System.out.println("\tPeriod 1\tJava");
    System.out.println("\tPeriod 2\tString Ensemble");
    System.out.println("\tPeriod 3\tAp Language Arts");
    System.out.println("\tPeriod 4\tAp Us History");
    System.out.println("\tPeriod 5\tMktg & Entreprenurship");
    System.out.println("\tPeriod 6\tPhysics");
    System.out.println("\tPeriod 7\tPre-Calculus");
    System.out.println("\tPeriod 8\tSeminar");


    gradePointAverage = (double)(periodOne + periodTwo + periodThree + periodFour + periodFive + periodSix + periodSeven)/7;
    System.out.println(“Your grade point average is: “ + gradePointAverage);
    }
    }

    I would like to know is I am doing this right so far, and what I should do next. (I know I have to parse as well)

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Well what did the compiler say when you asked it to compile the code?

    Hints:
    You have to declare variables before you can use them. e.g the compiler is too stupid to guess what type strInputNumber , gradePointAverage, periodThree, periodFour e.t.c are. Are they doubles, ints, BigDecimals, Strings? So you have to tell it what type they are first.
    If you set strInputNumber to a value from the user and set another value to the same strInputNumber then the previous value is lost for the posterity. Either use many different variables or much better yet, use an array (just one variable) to store the values.

  3. #3
    zacharyrod is offline Member
    Join Date
    Nov 2009
    Location
    Seoul, Korea
    Posts
    5
    Rep Power
    0

    Default

    Ok, so basically what I am trying to do is set the values for all the period numbers so that they won't equal anything until inputed. Here are some changes I have just made, though I am most likely wrong...

    /**
    * gradePointAverage BufferedReader is used to read input data from the keyboard and use that data to calculate my GPA *
    * @author (Zachary Rodriguez)
    * @version (11.04.09)
    */

    import java.io.*;

    public class GradePointAverageBufferedReader
    {
    public static void main(String[] args)
    {

    BufferedReader dataReader = new BufferedReader(new InputStreamReader(System.in));

    String strInputPeriodNumber;
    String strInputGPA;
    int thePeriodNumber;
    double theGPA;

    System.out.print("Please enter your GPA in period one: " + periodOne);
    strInputNumber = dataReader.readLine();
    System.out.print("Please enter your GPA in period two: " + periodTwo);
    strInputNumber = dataReader.readLine();
    System.out.print("Please enter your GPA in period three: " + periodThree);
    strInputNumber = dataReader.readLine();
    System.out.print("Please enter your GPA in period four: " + periodFour);
    strInputNumber = dataReader.readLine();
    System.out.print("Please enter your GPA in period five: " + periodFive);
    strInputNumber = dataReader.readLine();
    System.out.print("Please enter your GPA in period six: " + periodSix);
    strInputNumber = dataReader.readLine();
    System.out.print("Please enter your GPA in period seven: " + periodSeven);
    strInputNumber = dataReader.readLine();

    System.out.println("\tZachary Rodriguez");
    System.out.println("\t-----------------\n");
    System.out.println("\tPeriod 1\tJava");
    System.out.println("\tPeriod 2\tString Ensemble");
    System.out.println("\tPeriod 3\tAp Language Arts");
    System.out.println("\tPeriod 4\tAp Us History");
    System.out.println("\tPeriod 5\tMktg & Entreprenurship");
    System.out.println("\tPeriod 6\tPhysics");
    System.out.println("\tPeriod 7\tPre-Calculus");
    System.out.println("\tPeriod 8\tSeminar");


    gradePointAverage = (double)(periodOne + periodTwo + periodThree + periodFour + periodFive + periodSix + periodSeven)/7;
    System.out.println("Your grade point average is: " + gradePointAverage);
    }
    }

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Are you trying to avoid arrays?

    I have used them before and I still have my hair. Not a single one of them gray too.

  5. #5
    zacharyrod is offline Member
    Join Date
    Nov 2009
    Location
    Seoul, Korea
    Posts
    5
    Rep Power
    0

    Default

    OOOOOps, sorry! It's this:

    /**
    * gradePointAverage BufferedReader is used to read input data from the keyboard and use that data to calculate my GPA *
    * @author (Zachary Rodriguez)
    * @version (11.04.09)
    */

    import java.io.*;

    public class GradePointAverageBufferedReader
    {
    public static void main(String[] args)
    {

    BufferedReader dataReader = new BufferedReader(new InputStreamReader(System.in));

    String strInputPeriodNumber;
    String strInputGPA;
    int thePeriodNumber;
    double theGPA;

    System.out.print("Please enter your GPA in period one: ");
    strPeriodNumber = dataReader.readLine();
    System.out.print("Please enter your GPA in period two: ");
    strPeriodNumber = dataReader.readLine();
    System.out.print("Please enter your GPA in period three: ");
    strPeriodNumber = dataReader.readLine();
    System.out.print("Please enter your GPA in period four: ");
    strPeriodNumber = dataReader.readLine();
    System.out.print("Please enter your GPA in period five: ");
    strPeriodNumber = dataReader.readLine();
    System.out.print("Please enter your GPA in period six: ");
    strPeriodNumber = dataReader.readLine();
    System.out.print("Please enter your GPA in period seven: ");
    strPeriodNumber = dataReader.readLine();

    System.out.println("\tZachary Rodriguez");
    System.out.println("\t-----------------\n");
    System.out.println("\tPeriod 1\tJava" + periodOne);
    System.out.println("\tPeriod 2\tString Ensemble" + periodTwo);
    System.out.println("\tPeriod 3\tAp Language Arts" + periodThree);
    System.out.println("\tPeriod 4\tAp Us History" + periodFour);
    System.out.println("\tPeriod 5\tMktg & Entreprenurship" + periodFive);
    System.out.println("\tPeriod 6\tPhysics" + periodSix);
    System.out.println("\tPeriod 7\tPre-Calculus" + periodSeven);

    gradePointAverage = (double)(periodOne + periodTwo + periodThree + periodFour + periodFive + periodSix + periodSeven)/7;
    System.out.println("Your grade point average is: " + gradePointAverage);
    }
    }

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    We are now going nowhere fast.

    Compare your code with the hints I gave you in the first reply.
    Also don't write too much before checking it against the compiler and testing out small parts.

  7. #7
    zacharyrod is offline Member
    Join Date
    Nov 2009
    Location
    Seoul, Korea
    Posts
    5
    Rep Power
    0

    Default

    Yes, the program I am making is for an assignment on an online class and they never mention arrays... Just concatenation, casting, parsing, BufferedReader and Scanner classes, and importing....

  8. #8
    zacharyrod is offline Member
    Join Date
    Nov 2009
    Location
    Seoul, Korea
    Posts
    5
    Rep Power
    0

    Default

    Sorry, I am really new to this :(

  9. #9
    JazKW347 is offline Member
    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    Default

    i faild this

  10. #10
    JazKW347 is offline Member
    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    Default

    am i doing this right
    Write an application that :
    1) Outputs the programmer’s name
    2) Outputs the objective of this program and the objects used in this program.
    3) Asks the user for their full name (each name capitalized)
    4) Outputs the user’s name.
    5) Outputs the user’s name as all uppercase letters.
    6) Outputs the user’s name as all lowercase letters.
    7) Outputs the length of the user’s name.
    8) Outputs the first character of the user’s name.
    9) Outputs the 4th character of the user’s name.
    10) Outputs the 3rd from the last character of the user’s name.
    11) Uses escape characters to align columns




    import java.io.*;
    /**
    * This application prompts the user for their full name and then
    * demonstrates String methods by manipulating the name
    *
    * @author Jaz Williams
    * @version Programming Assignment 3-2
    *
    */
    public class MyStringDemo
    {//begin class

    /**
    * The main method prompts for and accepts the name and
    * and then outputs various demonstrations of the
    * String methods
    */

    public static void main(String[] args) throws IOException
    {//begin main
    //declare variables
    BufferedReader dataReader= new BufferedReader(new InputStreamReader (System.in));
    userName = dataReader.readLine();
    System.out.println("This program was created by Jaz Williams");
    System.out.print("What is your first or last name \t\t userName");




    } // end main()
    } // end class

  11. #11
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You still haven't learnt the fact that you must declare variables before you can use them.
    Do yourself a favor and get an introduction to Java tutorial and read it for a while.

Similar Threads

  1. How to use BufferedReader?
    By ProgramBeginner in forum New To Java
    Replies: 4
    Last Post: 10-11-2011, 02:56 PM
  2. how can i make bufferedreader
    By chyeeqi in forum New To Java
    Replies: 4
    Last Post: 08-21-2009, 05:24 PM
  3. Problems with BufferedReader
    By testarosa in forum Advanced Java
    Replies: 2
    Last Post: 03-26-2009, 05:09 PM
  4. BufferedReader
    By vidhya.sk in forum New To Java
    Replies: 2
    Last Post: 09-18-2008, 01:57 PM
  5. BufferedReader empty
    By Peter in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 06:52 PM

Tags for this Thread

Posting Permissions

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