• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can you help me figure this out?????

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need help!!!

This is the assignment and here is the code I have already??? Can someone help me please?

Create a program that prompts the user to enter the month and year. The program will then display the number of days in the month. For example, if the user enters month 8 and year 2007, the program will display "August 2007 has 31 days". Use input dialog boxes and message dialog boxes.

Don't forget that leap year must be part of your calculation. The formula for determining whether a year is leap year is found in your textbook and also on the internet (using a simple Google search). Once you've determined whether you have a leap year, then you can determine how many days are in February.


import javax.swing.JOptionPane;

public class LeapYear {
public static void main(String[] args) {
// Prompt the user to enter a year
String yearString = JOptionPane.showInputDialog("Enter a year");

//Convert the string into an int value
int year = Integer.parseInt(yearString);

// Check if the year is a leap year
boolean isLeapYear =
(year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);

// Display the result in a message dialog box
JOptionPane.showMessageDialog(null,
year + " is a leap year? " + isLeapYear);
}
}




I dont understand how to add the month portion to the assignment Can someone help me please???

Thanks,

Chitwood
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

How is entering a month different from entering a year?
 
Dinner will be steamed monkey heads with a side of tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic