Results 1 to 2 of 2
- 02-16-2013, 10:42 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 1
- Rep Power
- 0
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.
Similar Threads
-
Programming Question - Equality
By Huntersgirl12 in forum New To JavaReplies: 7Last Post: 01-19-2012, 04:05 PM -
a java programming question
By akash211 in forum New To JavaReplies: 1Last Post: 10-06-2011, 05:04 PM -
Windows Programming Question
By whenigivein in forum New To JavaReplies: 3Last Post: 07-29-2011, 06:09 PM -
help with simple programming question
By eezilyBefuddled in forum New To JavaReplies: 9Last Post: 05-18-2011, 08:05 PM -
Programming Socket Question
By paul in forum NetworkingReplies: 1Last Post: 07-30-2007, 07:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks