Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13

Thread: Marks.java

  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Marks.java

    i am being told that "class" or "interface" expected for lines 8,11,42,42. i have no idea why. any help is accepted, here is the code i have written:

    Code:
    public class Marks
    {
    	public static void main(String args[]);
    	{
    		int[] marks = enterMarks();
    	}
    }
    static int counter=20;
    	
    	
    	public static int[] enterMarks()
    	{
    			int classMarks[]= new int[counter];
    			
    			for (int i=0; i<counter; i++)
    				{
    					classMarks[i] = getScannerInput.anInt("Please enter an integer value between 0 and 20 for each mark :");
    				}	
    					
    					System.out.println();
    					System.out.print("The marks entered were ");
    					
    					for (int j=0; j><counter; j++)
    						{
    							System.out.print(classMarks[j]+", ");
    						}	
    						return classMarks;	
    		}
    	
    	
    	public static int max(int arr[])
    		{
    			int[] marks = classMarks;
    			int tempStore=0;
    			for (int k=0;k<counter;k++)
    			{
    				if(marks[k]>marks[k+1])
    				tempStore=marks[k];
    			}
    			return tempStore;
    		}
    }

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Looks like you have several issues here with your code. The first one being you have an extra parenthesis at the beginning that is closing your class early.

    Code:
    }
    static int counter=20;
    Also what is this?

    getScannerInput.anInt

    Is that method part of another class that you are using? How are you attempting to implement this other class? I say that because you cannot just call the method without implementing the other class.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    New Coder
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    marks

    a yes, dont know how i missed the clsing bracket!! feel like an idiot now lol. in line 23 (i pasteded it below) it asks for a ">"?? i cant see where to put it , i thought i already had enough?? cheers
    Code:
    for (int j=0; j><counter; j++)

  • #4
    New Coder
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    getScannerInput.anInt is what i use for user inputing a value. is it wrong? should i be using something else??

  • #5
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by gingergib View Post
    a yes, dont know how i missed the clsing bracket!! feel like an idiot now lol. in line 23 (i pasteded it below) it asks for a ">"?? i cant see where to put it , i thought i already had enough?? cheers
    Code:
    for (int j=0; j><counter; j++)
    You can't use a greater than and less than operation at the same time. Typically in the second parameter of a for loop you are going to use one of three operations... > (greater than), >= (greater than or equal), < (less than), <= (less than or equal).
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #6
    New Coder
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    this is really startin to get to me. i need to write a program which will allow a user to input 20 peoples marks from a test. then it will give me the average the minimum mark the maximum mark and all the marks above 8(which will be the pass mark). im using a method called "enterMarks() to create a new array called classMarks which will ask the user to input the 20 marks between 0-20. my output was supposed to show all the above information but i just cant get it right!! please, any help is more than appreciated. this is my code so far, but i think the "getScannerInput" is wrong:
    Code:
    public class Marks
    {
    	public static void main(String args[]);
    	{
    		int[] marks = enterMarks();
    }
    static int counter=20;
    	
    	
    	public static int[] enterMarks()
    	{
    			int classMarks[]= new int[counter];
    			
    			for (int i=0; i<counter; i++)
    				{
    					classMarks[i] = getScannerInput.anInt("Please enter an integer value between 0 and 20 for each mark :");
    				}	
    					
    					System.out.println();
    					System.out.print("The marks entered were ");
    					
    					for (int j=0; j>=counter; j++)
    						{
    							System.out.print(classMarks[j]+", ");
    						}	
    						return classMarks;	
    		}
    	
    	
    	public static int max(int arr[])
    		{
    			int[] marks = classMarks;
    			int tempStore=0;
    			for (int k=0;k<counter;k++)
    			{
    				if(marks[k]>marks[k+1])
    				tempStore=marks[k];
    			}
    			return tempStore;
    		}
    }

  • #7
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Where is this getScannerInput defined? Are you importing anything? Are you extending another class? We don't know where that is coming from or what is does. You are using it as if it is a class but I do not see the class definition or declaration for it.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #8
    Regular Coder
    Join Date
    Mar 2006
    Posts
    258
    Thanks
    1
    Thanked 2 Times in 2 Posts
    From first sigth, it looks like your trying to do the whole thing at once. Start step by step, for instance, the very first thing I do when creating a class is:
    Code:
    public class Marks{
           public static void main(String[] args);
          {
          }
       }
    Then I complile to see if there are no mistakes. When compiled, I get the error:
    Marks.java:3: missing method body, or declare abstract
    public static void main(String[] args);
    That means there's something wrong with "public static void main(String[] args);"
    I reason that java is telling me that I'm calling main() but it has no method. Why? Because of the semicolon. So the next step is to remove the semicolon.

    Once you fix that, continue with your work. At this point, your code should look like:
    Code:
    public class Marks
       {
           public static void main(String[] args)
          {
             int[] marks = enterMarks();
    
          }
          static int counter=20;
       
       
           public static int[] enterMarks()
          {
             int classMarks[]= new int[counter];
          
             for (int i=0; i<counter; i++)
             {
                classMarks[i] = getScannerInput.anInt("Please enter an integer value between 0 and 20 for each mark :");
             }
          
             System.out.println();
             System.out.print("The marks entered were ");
          
             for (int j=0; j>=counter; j++)
             {
                System.out.print(classMarks[j]+", ");
             }
             return classMarks;
          }
    }
    with this error:
    Marks.java:17: cannot find symbol
    symbol : variable getScannerInput
    location: class Marks
    classMarks[i] = getScannerInput.anInt("Please enter an integer value between 0 and 20 for each mark :");
    This leads back to the question Spook asked you.
    Usually, if you want to define a scanner, you do it this way:
    Code:
    import java.util.Scanner;
    your class{
        Scanner yourVariable = new Scanner(System.in);
        your method(){
              System.out.println("Ask user to do something here");
              int something = yourVariable.nextInt();
        }
    }
    I guess you can still use getScannerInput(), but then make sure you know where it's coming from, and how to import it.
    Last edited by daniel_g; 12-05-2006 at 09:42 PM.

  • #9
    New Coder
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    still workin hard at it :(

    ok, i have sat all night with what you guys have said an come up with the following:
    Code:
    public class Marks
    {
    public static int enterMarks()
    {
    int classMarks[];
    classMarks = new int[20];
    int marks = getScannerInput.adouble("Enter the 30 marks");
    {
    System.out.println("The class exam marks are: " + classMarks + );
    }
    {
    public static void main(String args[])
    {
    int[] marks = enterMarks();
    
    public static int Max()
    {
    
    System.out.println("The maximum mark in the class was: " + Max + );
    }
    public static int Min()
    {
    
    System.out.println("The minimum mark in the class was: " + Min + );
    }
    
    public static double Average()
    {
    System.out.printf("The class average correct to 1 decimal place is: " + Average + );
    }
    
    public static int Passed()
    {
    if(Marks =>8)
    Count;
    System.out.println("The number of students who passed the exam is " + Passed + );
    }
    }
    }
    }
    }
    it tells me that for line 9: ")" expected and illegal start of expression,
    and for line 12: illegal start of expression,
    and for line 39: ";" expected.
    this is as far as my mind can physically go now so cheers for all your help guys and if u can solve this for me please feel free to respond

  • #10
    Gox
    Gox is offline
    Regular Coder Gox's Avatar
    Join Date
    May 2006
    Location
    Ontario, Canada
    Posts
    392
    Thanks
    2
    Thanked 20 Times in 20 Posts
    You appear to have some bracket issues in the you code.
    I'm not sure what you're trying to do with this section of code.
    Code:
    {
    System.out.println("The class exam marks are: " + classMarks + );
    }
    {
    Also, you can't declare methods inside the body of "main"
    Code:
    ...
    public static void main(String args[])
    {
    int[] marks = enterMarks();
    
    public static int Max()
    {
    
    System.out.println("The maximum mark in the class was: " + Max + );
    }
    ...
    I've rearranged your code to something that has the proper structure, but it still has issues, and probably won't compile. But work starting from here as it's closer in terms of correctness.
    Code:
    public class Marks
    {
    public static int enterMarks()
    {
    int classMarks[];
    classMarks = new int[20];
    int marks = getScannerInput.adouble("Enter the 30 marks");
    System.out.println("The class exam marks are: " + classMarks + );
    }
    
    public static int Max()
    {
    System.out.println("The maximum mark in the class was: " + Max + );
    }
    public static int Min()
    {
    System.out.println("The minimum mark in the class was: " + Min + );
    }
    
    public static double Average()
    {
    System.out.printf("The class average correct to 1 decimal place is: " + Average + );
    }
    
    public static int Passed()
    {
    if(Marks =>8)
    Count;
    System.out.println("The number of students who passed the exam is " + Passed + );
    }
    
    public static void main(String args[])
    {
    int[] marks = enterMarks();
    }
    
    }
    I'll come back and give you some more pointers later tonight when I have more time.
    But quickly I'll mention that all your methods declare return types, but then never return any value
    Code:
    public static double Average()
    {
    System.out.printf("The class average correct to 1 decimal place is: " + Average + );
    }
    You should either declare the method as void (i.e that it won't return anything) or you'll need to return a value. The Java compiler won't let you compile your program until you do one of these things.
    Code:
    public static void Average()
    {
    System.out.printf("The class average correct to 1 decimal place is: " + Average + );
    }
    
    OR
    
    public static double Average()
    {
      double avg;
    
      ...   //Some code to calculate the Average, then
    
      return avg
    }
    Last edited by Gox; 12-06-2006 at 03:15 PM.

  • #11
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Honestly there is so much wrong with the code you just posted I don't know where to begin. Obviously this is a homework assignment so we are not going to just write it for you. I think you are trying to do too much at one time. The first step to writing a program like this is to figure out how to accomplish what it is you need to do. You should not be worrying about how to write the code at this point. Write algorithms and pseudocode to layout the design of your program and figure out the logic.

    Then when you get to writing the code take it one step at a time. Write the skeleton for the main class with it's main method. Compile and make sure you don't have errors at that point. Then one by one write each additional method you will need to use and compile each time to make sure you don't have errors. Once you have all the necessary methods written use those methods in your main method using the logic you came up with in the algorithms and pseudocode that you wrote.

    In your code right now you have too many syntax errors to list. You should properly format your code with proper tabbing. Use a text editor that highlights code. This helps to see potential typos. Your biggest problem right now is your use of braces {}. You are not closing methods, your are enclosing methods inside other methods, other braces are just out of place or unecessary.

    A structure of a class should be something like this:

    Code:
    public class ClassName() {
    
        public static void main (String args[]) {
    
    
        }//End main
    
        int method1() {
    
        }//End method1
    
        int method2() {
    
        }//End method2
    } // End ClassName
    It is sometimes helpful to put comments after your closing braces to indicate which method/class the brace belongs to.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #12
    Gox
    Gox is offline
    Regular Coder Gox's Avatar
    Join Date
    May 2006
    Location
    Ontario, Canada
    Posts
    392
    Thanks
    2
    Thanked 20 Times in 20 Posts
    Quote Originally Posted by Spookster View Post
    ...I think you are trying to do too much at one time...write each additional method you will need to use and compile each time to make sure you don't have errors...
    I've quoted this because I think that it is a very helpful tip when writing code. Whether you're a beginner or a pro I think using this methodology is very helpful. It helps eliminate the problem of "not being able to see the trees for the forest".

    Even if you were able to write a complete program without any syntax errors and compile at the end, you'll find that you'll most likely have to still deal with some logic issues. If you compile once at the end, you'll have no idea where to start looking. Compiling incrementally will help cut down some wasted time as you'll already have a good indication of which parts/methods of the program work properly.

    gingergib: Continue working on your code using the tips provided and let us know how you progress. We're here to help.

  • #13
    New Coder
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    cheers all

    well the deadline was yesterday and i didnt get the program done. i got 28%(40% is the pass mark) for my program. which although dosnt sound like much is much more than what i cuda got without your help guys(and girls if any girls helped me out). i got my marks for havin the basics of the code, even tho they wer in the wrong places and the program didnt execute. i got 100% in my other 3 programs so that gives me a pass over all for my first semester. other 3 programs wer much easier. 1) a program that wen a year is entered states wether its a leap yr or not, 2) a program that wen 3 angles are entered states wether its a right angled, isosceles or equalateral triangle, and 4) gives the prime numbers up to the limit entered by the user(200 was the limit i had to work with). i failed the 3rd one. one final question: any good E-books or free software or anything that you would recommend so as i can get 100% next time?
    cheers again, and i hope i never to have to write that program again in my life!!
    (p.s. you guys must be geniouses at programin to have the time to volunteer your services!!)


  •  

    Posting Permissions

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