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 16 of 16

Thread: PLEASE HELP ME, i am over thinking this and I am lost

  1. #1
    Junior Member
    Join Date
    Oct 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PLEASE HELP ME, i am over thinking this and I am lost

    Hey everyone so I made this basic code for assignment and I am just lost, the code is really more of any outline but im hoping someone can help me edit it and format it correctly

    so in this code he wants us to make code that will allow user to enter month and year and display how many days are in that month. In this chapter is the code for how to determine a leap year. Use that as part of your code to make this program work correctly Ex: user enters month 2 and year 2012. The program needs to display February 2012 had 29 days
    Input dialog boxes and output command window

    so can anyone look over this and tell me what I need to change or help me re format it please or even make it shorter or is there an easier way to make a code like this
    PLEASE HELP

    public static void main(String[] args)
     
            {
     
     
     
            Scanner input = new Scanner (System.in);
     
     
     
            int MonthNum; 
     
            int Year; 
     
            int numDays;
     
            String Month;
     
     
     
            System.out.print("Please enter the Month #");
     
            MonthNum = input.nextInt();
     
            System.out.print("Please enter the Year");
     
            Year = input.nextInt();
     
     
     
            if (MonthNum == 2)
     
                {
     
                 if ( (Year % 4 == 0) && (Year % 400 == 0)
     
                         && !(Year % 100 == 0) )
     
                       numDays = 29;
     
                     else
     
                        numDays = 28;
     
                }
     
            else if (MonthNum == 1 || MonthNum == 3 || MonthNum == 5 || MonthNum == 7 || MonthNum == 8 
     
                        || MonthNum == 10 || MonthNum == 12)
     
                numDays = 31;
     
            else
     
                numDays = 30;
     
     
     
            if (MonthNum == 1)
     
                Month = "January";
     
            else if (MonthNum == 2)
     
                Month = "Feburary";
     
            else if (MonthNum == 3)
     
                Month = "March";
     
            else if (MonthNum == 4)
     
                Month = "April";
     
            else if (MonthNum == 5)
     
                Month = "May";
     
            else if (MonthNum == 6)
     
                Month = "June";
     
            else if (MonthNum == 7)
     
                Month = "July";
     
            else if (MonthNum == 8)
     
                Month = "August";
     
            else if (MonthNum == 9)
     
                Month = "September";
     
            else if (MonthNum == 10)
     
                Month = "October";
     
            else if (MonthNum == 11)
     
                Month = "November";
     
            else if (MonthNum == 12)
     
                Month = "December";
     
     
     
     
     
            System.out.println(Month + " " + Year " has " + numDays "." );
     
            System.out.println(Month);
     
            System.out.println(numDays);
     
        }
     
    }
    Last edited by costello20; October 5th, 2014 at 04:36 PM.


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

    Default Re: PLEASE HELP ME, i am over thinking this and I am lost

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

  3. #3
    Junior Member
    Join Date
    Oct 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP ME, i am over thinking this and I am lost

    Thanks norm and can you please help me out.
    I cannot figure out what I am doing wrong. I am trying to write a program that prompts the user to enter a month and year and the program calculates the number of days for that month/ year and displays it in the format " August 2007 has 31 days". Any tips to point me in the right direction would be most appreciated.

    Is there a shorter way to write this code or what please feel free to edit it and format for improvement

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

    Default Re: PLEASE HELP ME, i am over thinking this and I am lost

    I cannot figure out what I am doing wrong.
    Please explain why you think you are doing it wrong. If the output shows the problem, copy the output here and add some comments describing the problem and show what the output should be.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Oct 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP ME, i am over thinking this and I am lost

    well how would I convert it so that the input is dialog boxes and the output is a command window

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

    Default Re: PLEASE HELP ME, i am over thinking this and I am lost

    input is dialog boxes
    Look at using the JOPtionPane class methods for getting user input.
    the output is a command window
    Use System.out.println() to display on the command prompt window
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Oct 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP ME, i am over thinking this and I am lost

    is it possible you could just show me please and re format it just to help me out and

    at the end it is underlining this line with a red line

    System.out.println(Month + " " + Year " has " + numDays ".");

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

    Default Re: PLEASE HELP ME, i am over thinking this and I am lost

    underlining this line with a red line
    Can you get the compiler's error message?

    Do a Search for examples of the JOptionPane class usage. There are several samples here on the forum for example.

    Strange, you are using code here to do that:
    http://www.javaprogrammingforums.com...tml#post159021
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Oct 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP ME, i am over thinking this and I am lost

    yes Ive looked at examples and they make no sense to me and Im trying hard and new at this

    could you please just show me and fix it so I can see

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: PLEASE HELP ME, i am over thinking this and I am lost

    Work on one item at a time. Which one do you want to work on first?

    We expect you to make some efforts and ask questions when you have problems. We don't write code for you to copy into your program.

    If there are errors in the code, you need to copy the full text of the error message and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Oct 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP ME, i am over thinking this and I am lost

    okay well one thing take the code and try running it and see if it works the way it is because mine does not

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: PLEASE HELP ME, i am over thinking this and I am lost

    What happens when you compile the code? Are there any errors?
    If there are no compiler errors, what happens when you execute the code?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Oct 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP ME, i am over thinking this and I am lost

    mine just doesnt run and if it means anything he is having us use netbeans for right now

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: PLEASE HELP ME, i am over thinking this and I am lost

    You need to get the full text of the error messages from netbeans so you can post them here.
    Without error messages, we don't know what the problem is and how to fix it.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Oct 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: PLEASE HELP ME, i am over thinking this and I am lost

    there is no error message I keep trying to run it and it wont run

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: PLEASE HELP ME, i am over thinking this and I am lost

    it wont run
    Sorry, I don't use netbeans and can't help you use it. You need to find someone that can help you use it.

    I use the javac.exe program from the JDK to compile my java files.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Please Can anyone help me, Im new at this and lost
    By costello20 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 4th, 2014, 10:04 AM
  2. Thinking like a programmer
    By keepStriving in forum Java Theory & Questions
    Replies: 1
    Last Post: June 14th, 2013, 07:55 PM
  3. [SOLVED] Have I lost it?
    By pooleman133 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 7th, 2012, 09:22 PM
  4. Help, please. I'm lost
    By Borb in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 17th, 2010, 08:50 PM