Results 1 to 6 of 6
  1. #1
    nevets93 is offline Member
    Join Date
    Oct 2010
    Posts
    9
    Rep Power
    0

    Post Easter Calculator

    I have to do this program for a class I am taking, but I keep getting an error that says "variable year might not have been initialized". Also I'm not completely finished with it yet, I just need help getting around this error.

    heres my code:

    PHP Code:
    import java.util.Scanner;
    public class EasterSunday
    {
    	public static void main(String[] args)
    	{
    		int year; // declarations
    		int a = year%19;
    		int b = year%4;
    		int c = year%7;
    		int d = (19 * a + 24) %30;
    		int e = (2 * b + 4 * c + 6 * d + 5) %7;
    		int eSunday = (22 + d + e);
    		Scanner in = new Scanner(System.in); //start Scanner
    		System.out.println("Enter in a year to find out the day and month of that Easter Sunday.");
    		year = in.nextInt();
    		if ((year >= 1900) && (year <= 2099) && (year != 1954) && (year != 1981) && (year != 2049) && (year != 2076))
    			if (eSunday <= 30)
    				System.out.println("Easter Sunday in " + year + "is March " + eSunday);
    			else
    				System.out.println("Easter Sunday in " + year + " is April, " + (eSunday - 30));
    		//else
    			//System.out.println("");
    	}
    }
    Last edited by nevets93; 10-12-2010 at 01:20 AM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    The compiler message means what it says: you say "a=year%19" before you assign year a value, and you can't do that.
    Last edited by pbrockway2; 10-12-2010 at 01:27 AM. Reason: corrected casual wording

  3. #3
    nevets93 is offline Member
    Join Date
    Oct 2010
    Posts
    9
    Rep Power
    0

    Default

    wow! sorry I was being dumb! Im a complete noob so bare with me. Thanks for the quick reply btw. Okay so I fixed and finished my program and it runs good, but I cant get it to run in eclipse. Everytime I try to run it says "Editor does not contain a main type."

    Heres my finished code:

    PHP Code:
    import java.util.Scanner;
    public class EasterSunday
    {
    	public static void main(String[] args)
    	{
    		int year; // declarations
    		Scanner in = new Scanner(System.in); //start Scanner
    		System.out.println("Enter in a year to find out the day and month of that Easter Sunday.");
    		year = in.nextInt();
    		int a = year%19;
    		int b = year%4;
    		int c = year%7;
    		int d = (19 * a + 24) %30;
    		int e = (2 * b + 4 * c + 6 * d + 5) %7;
    		int eSunday = (22 + d + e);
    		if ((year >= 1900) && (year <= 2099) && (year != 1954) && (year != 1981) && (year != 2049) && (year != 2076))
    		{
    			if (eSunday <= 30)
    				System.out.println("Easter Sunday in " + year + " is March, " + eSunday);
    			else
    				System.out.println("Easter Sunday in " + year + " is April, " + (eSunday - 30));
    		}
    		else
    		{
    			if (eSunday <= 30)
    				System.out.println("Easter Sunday in " + year + " is March, " + (eSunday - 7));
    			else
    				System.out.println("Easter Sunday in " + year + " is April, " + (eSunday - 37));
    		}
    	}
    }

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    "Editor does not contain a main type."

    Yes, but you trying to run EasterSunday, not Editor. Try right clicking on the icon for this class on the left hand side somewhere, right clicking and seeing if there is a Run command.

    (Sorry I don't have Eclipse to hand)

  5. #5
    nevets93 is offline Member
    Join Date
    Oct 2010
    Posts
    9
    Rep Power
    0

    Default

    yea that didnt really help and im trying to run the file, not the editor, so i dont know whats going on. anybody else have any ideas?

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by nevets93 View Post
    yea that didnt really help and im trying to run the file, not the editor, so i dont know whats going on. anybody else have any ideas?
    In Eclipse you can run a 'Launch Configuration'. Go to Run > Run Configurations ... create a 'Java Application' configuration; give it a name, select the project and the class that contains the main( ... ) method and run it.

    kind regards,

    Jos

Similar Threads

  1. Calculator Switching
    By dilpreet28 in forum New To Java
    Replies: 9
    Last Post: 06-08-2010, 02:05 AM
  2. need help with my calculator
    By semoche in forum AWT / Swing
    Replies: 6
    Last Post: 12-04-2009, 10:16 PM
  3. Calculator
    By water in forum AWT / Swing
    Replies: 4
    Last Post: 09-23-2009, 06:00 AM
  4. help with calculator
    By kalibballer in forum New To Java
    Replies: 8
    Last Post: 04-01-2009, 12:57 PM
  5. Calculator help.
    By madkidd02 in forum New To Java
    Replies: 2
    Last Post: 10-25-2008, 07:42 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
  •