Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: 1st year java student needs some help..

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 1st year java student needs some help..

    I writing a program that gives the user their Egyptian zodiac sign after they input their birthday, it is supposed to run continually until the user enters stop or their sign is found.. i am very new to programming and am getting a lot of errors in the portion with all of my if statements in the program. If anyone could correct me on my mistakes and give a brief explanation on everything i did wrong/ anything i am using wrong it will be greatly appreciated. Thanks!



    import java.lang.*;
    import java.util.*;
    import java.io.*;
    public class Program
    {
        /**
         * This is the main entry point for the application
         */
        static Scanner console = new Scanner(System.in);
        public static void main(String args[]) 
     
    {
        boolean x = false;
    	do
    	{
    		 x = false;
     
    System.out.println("This program will tell you your Egyptian Zodiac sign! Please enter the month and day of your birthday..");
    System.out.println("Enter month:>");
    String month1 = console.nextLine();
    month1 = month1.toLowerCase();
    System.out.println("Enter day:> ");
    int day = console.nextInt();
    switch(month1)
    {
    case "january" :
    month1 = month1.substring(0, 2);
    break;
    case "february" :
    month1 = month1.substring(0, 2);
    break;
    case "march" :
    month1 = month1.substring(0, 2);
    break;
    case "april" :
    month1 = month1.substring(0, 2);
    break;
    case "may" :
    month1 = month1.substring(0, 2);
    break;
    case "june" :
    month1 = month1.substring(0, 2);
    break;
    case "july" :
    month1 = month1.substring(0, 2);
    break;
    case "august" :
    month1 = month1.substring(0, 2);
    break;
    case "september" :
    month1 = month1.substring(0, 2);
    break;
    case "october" :
    month1 = month1.substring(0, 2);
    break;
    case "november" :
    month1 = month1.substring(0, 2);
    break;
    case "december" :
    month1 = month1.substring(0, 2);
    break;
    default:
    month1 = month1.substring(0, 3);
    break;
    }
     
     
    if(month1 == "jan")
    {
    if(day>= 0 && day <= 25 )
    {
    System.out.println("Sign of Zodiac : Sphinx");
    x = true;
    }
    else if(day > 25 && day <= 31)
    {
    System.out.println("Sign of Zodiac: Shu");
    x = true;
    }
    else
    {
    System.out.println("Sign of Zodiac: Error in date");
    }
    }//ends
     
    if(month1 == "feb")
    {
    if(day>= 0 && day <= 24 )
    {
    System.out.println("Sign of Zodiac : Shu");
    x = true;
    }
    else if(day > 24 && day <= 28)
    {
    System.out.println("Sign of Zodiac: Isis");
    x = true;
    }
    else
    {
    System.out.println("Sign of Zodiac: Error in date");
    }
    }//ends
     
    if(month1 == "mar" )
    {
    if(day>= 0 && day <= 26 )
    {
    System.out.println("Sign of Zodiac : Isis");
    x = true;
    }
    else if(day > 26 && day <= 31)
    {
    System.out.println("Sign of Zodiac: Osiris");
    x = true;
    }
    else
    {
    System.out.println("Sign of Zodiac: Error in date");
    }
    }//ends
     
    if(month1 == "apr")
    {
    if(day>= 0 && day <= 25 )
    {
    System.out.println("Sign of Zodiac : Osiris");
    x = true;
    }
    else if(day > 25 && day <= 30)
    {
    System.out.println("Sign of Zodiac: Amun");
    x = true;
    }
    else
    {
    System.out.println("Sign of Zodiac: Error in date");
    }
    }//ends
     
    if(month1 == "may")
    {
    if(day>= 0 && day <= 25 )
    {
    System.out.println("Sign of Zodiac : Amun");
    x = true;
    }
    else if(day > 25 && day <= 31)
    {
    System.out.println("Sign of Zodiac: Hathur");
    x = true;
    }
    else
    {
    System.out.println("Sign of Zodiac: Error in date");
    }
    }//ends
     
    if(month1 == "jun")
    {
    if(day>= 0 && day <= 24 )
    {
    System.out.println("Sign of Zodiac : Hathur");
    x = true;
    }
    else if(day > 24 && day <= 31)
    {
    System.out.println("Sign of Zodiac: Phoenix");
    x = true;
    }
    else
    {
    System.out.println("Sign of Zodiac: Error in date");
    }
    }//ends
     
    if(month1 == "jul")
    {
    if(day>= 0 && day <= 24 )
    {
    System.out.println("Sign of Zodiac : Phoenix");
    x = true;
    }
    else if(day > 24 && day <= 31)
    {
    System.out.println("Sign of Zodiac: Anubis");
    x = true;
    }
    else
    {
    System.out.println("Sign of Zodiac: Error in date");
    }
    }//ends
     
    if(month1 == "aug")
    {
    if(day>= 0 && day <= 28 )
    {
    System.out.println("Sign of Zodiac : Anubis");
    x = true;
    }
    else if(day > 28 && day <= 31)
    {
    System.out.println("Sign of Zodiac: Thoth");
    x = true;
    }
    else
    {
    System.out.println("Sign of Zodiac: Error in date");
    }
    }//ends
     
    if(month1 == "sep")
    {
    if(day>= 0 && day <= 27 )
    {
    System.out.println("Sign of Zodiac : Thoth");
    x = true;
    }
    else if(day > 27 && day <= 30)
    {
    System.out.println("Sign of Zodiac: Horus");
    x = true;
    }
    else
    {
    System.out.println("Sign of Zodiac: Error in date");
    }
    }//ends
     
    if(month1 == "oct")
    {
    if(day>= 0 && day <= 27 )
    {
    System.out.println("Sign of Zodiac : Horus");
    x = true;
    }
    else if(day > 27 && day <= 31)
    {
    System.out.println("Sign of Zodiac: Wadget");
    x = true;
    }
    else
    {
    System.out.println("Sign of Zodiac: Error in date");
    }
    }//ends
     
    if(month1 == "nov")
    {
    if(day>= 0 && day <= 26 )
    {
    System.out.println("Sign of Zodiac : Wadget");
    x = true;
    }
    else if(day > 26 && day <= 30)
    {
    System.out.println("Sign of Zodiac: Sekhmet");
    x = true;
    }
    else
    {
    System.out.println("Sign of Zodiac: Error in date");
    }
    }//ends
     
    if(month1 == "dec")
    {
    if(day>= 0 && day <= 26 )
    {
    System.out.println("Sign of Zodiac : Sekhmet");
    x = true;
    }
    else if(day > 26 && day <= 31)
    {
    System.out.println("Sign of Zodiac: Sphinx");
    x = true;
    }
    else
    {
    System.out.println("Sign of Zodiac: Error in date");
    }
    }//ends
     
    if(month1 == "quit")
    {
    x = true;
    }//ends
     
    }while(x == true);
     
        }
    }


    Checking Libraries...
    Copying files...
    Processing Files...
    Compiling...
    Build Success
    ------------------------------

    This program will tell you your Egyptian Zodiac sign! Please enter the month and day of your birthday..
    Enter month
    September
    Enter day
    29

    Application Exited.
    Last edited by mmagyar14; January 7th, 2013 at 10:59 PM. Reason: added code tags


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: 1st year java student needs some help..

    am getting a lot of errors
    Please copy the full text of the error messages and post them here.

    Please edit your code and format the code so that nested statements are properly indented.

    Use the equals() method to compare Strings not the == operator.

    --- Update ---

    What happened to the code tags I added?

    Program.java 64 null error: not a statement
    Which statement is #64?

    Are those error messages from the compiler? They are different from those I've seen before.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: 1st year java student needs some help..

    yes i was using compilr.com are these the right errors then? there were two options for errors..

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: 1st year java student needs some help..

    The line numbers in the error message doesn't match the locations of the line in the posted code.
    Program.java:13: error: illegal start of expression
    import java.util.*;
    The error message says line 13 but the posted code looks like that statement is at line 1?

    Please edit your code and format the code so that nested statements are properly indented.

    Also Please wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: 1st year java student needs some help..

    ok i compiled it again and there are the errors. how do i wrap the code like that?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: 1st year java student needs some help..

    how do i wrap the code like that?
    Put this before the code
    [code=java]

    <PUT YOUR CODE HERE>

    [/code]
    the above goes at the end of the code

    Program.java:13: error: illegal start of expression
    import java.util.*;
    ^
    Why does error message say line 13 but the posted code shows line 2?

    continue is a java keyword and can NOT be used for a variable name. Change it to something else.

    The newly posted unformatted code is now hiding the problem:
    The posted code now has two classes that are not properly separated.
    Make sure the {}s are properly paired.

    All import statements MUST be before any other statements (except comments and the package statement);
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Jan 2013
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: 1st year java student needs some help..

    ok that helped a lot! i did not know it was a reserved word either..

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: 1st year java student needs some help..

    The formatting still needs to be fixed. The indentation is missing. It should look something like this:
        public static void main(String args[]) 
        {
            do
            {
                boolean x = false;

    cannot find symbol

    variable x
    Where is the variable x defined? The compiler can not find it's definition in scope (within the same pair of {}s) with where it is being used.

    I'm done for tonight. Back tomorrow.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Jan 2013
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: 1st year java student needs some help..

    ok thanks a ton! I got the program to run too.

  10. #10
    Junior Member
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: 1st year java student needs some help..

    i am also a beginner but i help you ...
    First thing you should do with this code is
    1- Create Scanner Object to read input like Scanner input=input.(member function which you need in ur case)
    2-remove the "x=false" appear before the do While loop.
    3-when Comaparing Expression in Switch Body ,user if statement there like
    Switch(month1)
    {
    Case "january":
    month=month.substring(0,2)
    now right the if code here ....
    if(month1.isequal("jan")&&day>0 && day<25)
    {
    System.out.println("your zoidic sighn is ")
    }

Similar Threads

  1. Hey 16 year old only started Java this morning, what is wrong with my code?
    By JavaProg in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 1st, 2013, 11:00 AM
  2. today is 1st day with java and i am screwed...
    By sumit043020701 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 20th, 2011, 09:59 AM
  3. Final year java project
    By aj4u in forum The Cafe
    Replies: 3
    Last Post: October 13th, 2011, 12:47 AM
  4. 1st Java class assignment, and having some difficulties. Little help please.
    By flpanthers1 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: May 27th, 2011, 04:09 AM
  5. Help with 1st Java applet game!
    By Sneak in forum Java Applets
    Replies: 0
    Last Post: November 28th, 2009, 11:20 AM