Results 1 to 6 of 6

Thread: Tips needed

  1. #1
    adz06 is offline Member
    Join Date
    Oct 2009
    Posts
    8
    Rep Power
    0

    Default Tips needed

    I have to write a method called enterMarks() which creates a new array called classMarks, prompts the user to enter 10 marks, which will be entered into the array as they are read in and then a print statment to disply full array of marks.

    This is only the start of the code, i understand how to complete the rest of it fine which is finding max, min, average and mode and if they have passed.

    Java Code:
    public class marks
    {
    static int enterMarks;
    {
    int classMarks[];
    classMarks = new int[10];
    for (int i = 0; i <= classMarks.length; i++)	
    int marks = getScannerInput.anInt("Enter your 10 marks between 0 and 20");
    System.out.println(" The class exam marks are: " + classMarks);
    }
    }
    Currently compiler is telling me there is 4 errors all on line 8. I am new to java and my knowledge is mainly based around the two text books i purchased and have been searching for soloution with no luck, im sure its just somthing stupid and hope use can help me out or point me in right direction.
    Thanks

    p.s the getScannerInput is a seperate program which gets the user to input data
    i think the problem is to do with the way i have mention "int marks"

    When i remove "int" and just leave "marks" i have one error saying cannot find variable marks, should i be declaring it somewhere else or as somthing else?
    Last edited by adz06; 12-04-2009 at 06:44 PM.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    public class marks
    {
        static int enterMarks;
        {
            int[] classMarks = new int[10];
            for (int i = 0; i <= classMarks.length; i++)	
                int marks = getScannerInput.anInt("Enter your 10 marks " +
                                                  "between 0 and 20");
                System.out.println(" The class exam marks are: " + classMarks);
        }
    }
    classMarks is declared as an array.
    Is the scanner method getScannerInput.anInt returning a single int or an array of ints?
    If the method returns an array then you'll want to declare marks as an array: int[] marks.
    If it returns a single int then you will ask the user to input the ith int and set the returned value, ie, mark as the ith element in the classMarks array.

  3. #3
    adz06 is offline Member
    Join Date
    Oct 2009
    Posts
    8
    Rep Power
    0

    Default

    Its returning an array, thanks for advice ill have a play with it and see if i can get it sorted.

  4. #4
    adz06 is offline Member
    Join Date
    Oct 2009
    Posts
    8
    Rep Power
    0

    Default

    Java Code:
    public class marks
    {
        static int enterMarks;
        {
            int[] classMarks = new int[10];
            for (int i = 0; i <= classMarks.length; i++)	
                int[] marks = getScannerInput.anInt("Enter your 10 marks "  + "between 0 and 20");
                System.out.println(" The class exam marks are: " + classMarks);
        }
    }
    I have finsihed writing the rest of the code but its just this first partion showing errors, the errors are
    '.class' expected line 7
    not a statement line 7
    illegal start of expression line 7
    ';' expected line 7

    Line 7 is
    Java Code:
    int[] marks = getScannerInput.anInt("Enter your 10 marks "  + "between 0 and 20");
    I do not no what im doing wrong is there somthing wrong with how i have wrote line 7 or is it somthing before that line causing the problem or somthing to do with the bracket layout.

    Without the user input from this line there was no point me going ahead and writing the rest of the code.
    Thanks

  5. #5
    adz06 is offline Member
    Join Date
    Oct 2009
    Posts
    8
    Rep Power
    0

    Default

    Still playing with this and cant figure out what is wrong.

  6. #6
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Illegal method signature:
    Java Code:
    //    static int enterMarks[b];[/b]  // <- errant comma
        static int enterMarks()
        {
            int[] classMarks = new int[10];
            for (int i = 0; i <= classMarks.length; i++) {
                // If this method reall returns an int array then you
                // don't need the for loop, just call the method once.
                // You need the loop if the method returns a single int.
                int[] marks = getScannerInput.anInt("Enter your 10 marks "  +
                                                    "between 0 and 20");
            }
            System.out.println(" The class exam marks are: " + classMarks);
        }
    }

Similar Threads

  1. Tool tips - Netbeans 6.5
    By dbashby in forum New To Java
    Replies: 10
    Last Post: 04-25-2009, 03:10 AM
  2. need some derby tips:
    By kulangotski in forum Advanced Java
    Replies: 4
    Last Post: 03-09-2009, 06:09 PM
  3. Need some tips.
    By PVL268 in forum New To Java
    Replies: 4
    Last Post: 02-27-2009, 03:37 PM
  4. tips on crystal report
    By kishore in forum New To Java
    Replies: 1
    Last Post: 01-20-2009, 04:23 AM
  5. First project, need some tips..
    By Komala_aradhya in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 02:25 PM

Posting Permissions

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