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!
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.