Results 1 to 2 of 2
  1. #1
    DolphinsNum1 is offline Member
    Join Date
    Feb 2013
    Posts
    1
    Rep Power
    0

    Default Java programming question, please help

    Hello. I am taking an Intro to Java class and I'm stuck on a homework question. I was hoping a kind soul could offer some suggestions. Here is the assignment:


    Write a program that asks the user to enter a month (1 = January, 2 = February, and so on) and then prints the number of days of the month. For February, print "28 days".

    Enter a month (1-12):
    5
    31 days

    Implement a class Month with a method int getDays(). Do not use a separate if or else statement for each month. Use Boolean operators.


    I thought it would be cool to have a box pop up and ask the question so that's in my code. I
    'm using NetBeans IDE 7.2.1 (Build 201210100934) and Java: 1.7.0; Java HotSpot(TM) 64-Bit Server VM 21.0-b17.

    Here is my code:


    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package daysinamonth;

    import java.util.Scanner;
    import javax.swing.JOptionPane;
    public class DaysInAMonth {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String month =JOptionPane.showInputDialog("Please enter your month 1-12: ");
    double a = Double.valueOf(month);
    // int month = in.nextInt();

    }

    public static void getMonth(double a)
    {
    if (a == 1 || a == 3 || a == 5 || a ==7 || a ==8 ||a == 10 || a == 12)
    {
    System.out.println("31");
    }
    if (a == 4 || a == 6 || a == 9 || a == 11)
    {
    System.out.println("30");
    }
    if (a == 2)
    {
    System.out.println("28");
    }
    }
    }




    Any suggestions are much appreciated!

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

    Default Re: Java programming question, please help

    What is your question? You have posted requirements and some code, but have asked no specific answerable question nor have you told us what if anything is wrong with your current code.

Similar Threads

  1. Programming Question - Equality
    By Huntersgirl12 in forum New To Java
    Replies: 7
    Last Post: 01-19-2012, 04:05 PM
  2. a java programming question
    By akash211 in forum New To Java
    Replies: 1
    Last Post: 10-06-2011, 05:04 PM
  3. Windows Programming Question
    By whenigivein in forum New To Java
    Replies: 3
    Last Post: 07-29-2011, 06:09 PM
  4. help with simple programming question
    By eezilyBefuddled in forum New To Java
    Replies: 9
    Last Post: 05-18-2011, 08:05 PM
  5. Programming Socket Question
    By paul in forum Networking
    Replies: 1
    Last Post: 07-30-2007, 07:26 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
  •