Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2009
    Posts
    19
    Rep Power
    0

    Default Errors with simple program... PLEASE HELP ME!!!

    I am supposed to be writing this program and this is what I have so far...

    import java.io.*;
    import java.util.*;

    public class assignment
    {
    public static void main(String[] args) throws FileNotFoundException
    {
    double quiz1, quiz2, quiz3, quiz4;
    double average;
    String firstName;
    String lastName;

    Scanner inFile =
    new Scanner(system.n);

    PrintWriter outFile = new
    PrintWriter("testavg.out");

    firstName = inFile.next();
    lastName = inFile.next();

    outFile.println("Student Name: "
    + firstName + " " + lastName);

    quiz1 = inFile.nextDouble();
    quiz2 = inFile.nextDouble();
    quiz3 = inFile.nextDouble();
    quiz4 = inFile.nextDouble();

    average = (quiz1 + quiz2 + quiz3 + quiz4) / 4.0;
    outFile.printf("Average quiz score: %5.2f %n",
    average);

    if (average>=90)System.out.println("A");
    else if (average>=80)System.out.print("B");
    else if (average>=70)System.out.print("C");
    else if (average>=60)System.out.print("D");
    else if (average<=50)System.out.print("F");
    inFile.close();
    outFile.close();
    }
    }

    WHAT I NEED TO DO IS WRITE IT SO THAT THE USER INPUTS A NUMBER OF QUIZES AND IT FINDS THE AVERAGE. AND I CAN NOT FIX THE ERRORS. IE. THE SCANNER ERROR

    PLEASE HELP ME!!!!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Hello. You will likely find that the more relevant information you tell us, the more we'll be able to help you. For instance, if you have a compile error(s), should post the error message(s) here with your question to better let us know just exactly what is going wrong.

    Also, you have to be extremely careful with spelling and capitalization when coding in Java.

    for instance, here:
    Java Code:
    Scanner inFile =
    new Scanner(system.n);
    System.in is not the same as system.n

    Best of luck.

  3. #3
    Join Date
    Feb 2009
    Posts
    19
    Rep Power
    0

    Default help... again

    I am wondering if you know how to input an amount of quizzes instead of it having a default amount of quizzes set?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You can always get the number of quizzes from the user via your Scanner object, and then use that int to initiate your int array, when you call
    int[] intArray = new int[the number goes here]

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    edit: this is not an Applet question. I'm going to move this to the New to Java section

  6. #6
    Join Date
    Feb 2009
    Posts
    19
    Rep Power
    0

    Default Alright so I tried this... but

    Alright so I tried what you said and no way I can think of does it work... if you would not mind helping me...

    .....
    int Scnanner (System.in) intArray = new int[];

    //Step 6 - retrieve the five test scores
    quiz1 = inFile.nextDouble();
    quiz2 = inFile.nextDouble();
    quiz3 = inFile.nextDouble();
    quiz4 = inFile.nextDouble();

    outFile.printf("Quiz scores: %5.2f %5.2f %5.2f "
    + "%5.2f %n", quiz1, quiz2,
    quiz3, quiz4);

    average = (quiz1 + quiz2 + quiz3 + quiz4) / new int[]; //Step 8
    outFile.printf("Average quiz score: %5.2f %n",
    average);
    if (average>=90)System.out.println("A");
    .....

    Here are the errors:

    /export/home/students/jgiannin/exampleStudentGrade.java:30: ';' expected
    int Scnanner System.in intArray = new int[];
    ^
    /export/home/students/jgiannin/exampleStudentGrade.java:42: array dimension missing
    average = (quiz1 + quiz2 + quiz3 + quiz4) / new int[];
    ^
    2 errors

    ----jGRASP wedge: exit code for process is 1.
    ----jGRASP: operation complete.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    This is wrong:
    Java Code:
    int Scnanner (System.in) intArray = new int[];
    Don't try to combine your Scanner object and your int array as they are two completely different animals. Create your scanner with a correctly spelled System.in object as I mentioned above,
    Java Code:
    Scanner scanner = new Scanner(System.in);
    then use that Scanner object to get a number from the user, just as you're currently using it to get your quiz scores. Then you use that int obtained to initialize the array, just as you'd initialize any array. Correction though, if your quiz scores are doubles (are you sure that they're doubles? int would make more sense), then you'll want an array of double.
    Last edited by Fubarable; 05-04-2009 at 01:45 AM.

Similar Threads

  1. [SOLVED] hello, java program with 2 errors, help
    By einstein1234 in forum New To Java
    Replies: 24
    Last Post: 04-10-2009, 08:50 AM
  2. Errors in Program (Right Triangle)
    By SupaStudy in forum New To Java
    Replies: 3
    Last Post: 03-26-2009, 10:42 AM
  3. Replies: 5
    Last Post: 02-04-2009, 01:20 AM
  4. Help with Errors in Inventory Program
    By ljk8950 in forum AWT / Swing
    Replies: 3
    Last Post: 08-08-2008, 11:49 PM
  5. 3 errors and then terminate program
    By hezfast2 in forum New To Java
    Replies: 2
    Last Post: 05-20-2008, 01:57 AM

Posting Permissions

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