viewing paste DaysInMonth | Java

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
//for dialog box to work
import javax.swing.JOptionPane;
 
public   class DaysInMonth{
   
    public   static   void  main(String[] args){
        
        //Ask user to input data
        String stringmonth = JOptionPane.showInputDialog(null, "Please input a month in numbers 1-12", "CPSC 1150 Lab 4", JOptionPane.QUESTION_MESSAGE);
        String stringyear = JOptionPane.showInputDialog(null, "Please input a year", "CPSC 1150 Lab 4", JOptionPane.QUESTION_MESSAGE);
      
        //Turn String into integers
        int month = Integer.parseInt(stringmonth);
        int year = Integer.parseInt(stringyear);
 
        //Display information according to month
        switch(month){
            case 1:      
            JOptionPane.showMessageDialog(null, "January of "+year+" has 31 days");
            break;
            
            //Display information according to year
            case 2:
            if(year%4==0){
                if(year%100 != 0){
                    JOptionPane.showMessageDialog(null, "Februrary  of "+year+" is a leap year and has 29 days");
                    break;
                } else if(year%400==0) {
                    JOptionPane.showMessageDialog(null, "Februrary of "+year+" is a leap year and has 29 days");
                    break;
                } else {
                    JOptionPane.showMessageDialog(null, "Februrary of "+year+" is NOT a leap year and has 28 days");
                    break;
                }
            } else {
                JOptionPane.showMessageDialog(null, "Februrary of "+year+" is NOT a leap year and has 28 days");
                break;
            }
            case 3:
                JOptionPane.showMessageDialog(null, "March of "+year+" has 31 days");
                break;
      
            case 4:
                JOptionPane.showMessageDialog(null, "April of "+year+" has 30 days");
                break;
 
            case 5:
                JOptionPane.showMessageDialog(null, "May of "+year+" has 31 days");
                break;
 
            case 6:
                JOptionPane.showMessageDialog(null, "June of "+year+" has 30 days");
                break;
 
            case 7:
                JOptionPane.showMessageDialog(null, "July of "+year+" has 30 days");
                break;
                
            case 8:
                JOptionPane.showMessageDialog(null, "August of "+year+" has 31 days");
                break;
 
            case 9:
                JOptionPane.showMessageDialog(null, "September of "+year+" has 30 days");
                break;
 
            case 10:
                JOptionPane.showMessageDialog(null, "October of "+year+" has 31 days");
                break;
 
            case 11:
                JOptionPane.showMessageDialog(null, "November of "+year+" has 30 days");
                break;
 
            case 12:
                JOptionPane.showMessageDialog(null, "December of "+year+" has 31 days");
                break;
         
        }
 
    }
  
}
Viewed 1428 times, submitted by Streusel.