Results 1 to 6 of 6
  1. #1
    BChow is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Default Anyone know what is wrong?

    I am trying to create a simple Java program to calculate the average and can't seem to figure out what is wrong with this method. I would appreciate any help :)

    Java Code:
    import java.util.*;
    import static java.lang.System.out;
    
    public class AverageCalculator {
    
    	static Scanner console = new Scanner(System.in);
    	static double first;
    	static double second;
    	static double third;
    	static double fourth;
    	
    	public static void main(String[] args) {
    		
    		
    		out.println("What are your 4 marks?");
    		
    		out.println("First Class Mark:");
    		first = Double.valueOf(console.nextLine());
    		
    		out.println("Second Class Mark:");
    		second = Double.valueOf(console.nextLine());
    		
    		out.println("Third Class Mark:");
    		third = Double.valueOf(console.nextLine());
    		
    		out.println("Fourth Class Mark:");
    		fourth = Double.valueOf(console.nextLine());
    		
    		double ans = calculate_avg(first,second,third,fourth);
    		
    		public double calculate_avg(double a, double b, double c, double d) {
    			double avg = ((a + b + c + d) / 4);
    			return avg;
    		}
    		
    	}	
    }

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

    Default Re: Anyone know what is wrong?

    You're not giving us all the information we need. What error messages are you seeing? Please post the whole error message.

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

    Default Re: Anyone know what is wrong?

    This exercise is for your benefit, since you need to know how to interpret these messages.

  4. #4
    Join Date
    Nov 2011
    Posts
    1
    Rep Power
    0

    Default Re: Anyone know what is wrong?

    Check the class methods

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default Re: Anyone know what is wrong?

    If you read the error message you ends with, it will helpful to you to find the solution yourself. Did you read it?

  6. #6
    Anveshan is offline Member
    Join Date
    May 2011
    Posts
    22
    Rep Power
    0

    Default Re: Anyone know what is wrong?

    YOu have written method inside a mehtod, seperate them. The method named "avg" should be "static" since you are calling it from static "main" method

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 01:37 AM
  2. What's wrong?!
    By huntersmommy030508 in forum Reviews / Advertising
    Replies: 2
    Last Post: 04-21-2011, 11:36 PM
  3. can't see where it went wrong..
    By Yakg in forum New To Java
    Replies: 5
    Last Post: 01-31-2011, 12:19 PM
  4. what's wrong?
    By rayda in forum New To Java
    Replies: 3
    Last Post: 04-14-2009, 09:07 PM
  5. Can someone tell me what I did wrong??
    By booter4429 in forum New To Java
    Replies: 7
    Last Post: 08-13-2008, 08:35 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
  •