-5

I have an assignment I am doing for my class. I have to write to ask for a year, and then the month by the input of the first three letters of the month. It will output the follows statement "February 2000 has 29 days" from what I am asked for the project. it is supposed to be case sensitive. not sure how to do that. can anyone point me in the right direction? also does this look good or am I being sloppy.

package test.project;

import java.util.Scanner;

/**
 *
 * @author XXXXXXX
 */
public class TESTPROJECT {

  /**
     * @param args the command line arguments
     */
     public static void main(String[] args) {
        // TODO code application logic here
        Scanner input = new Scanner(System.in);        
        System.out.print("Enter a year: ");
        int year = input.nextInt();
        System.out.print("Enter month (first three letters with the first letter in upper case): ");
        String month = input.next();

  //months
    if (month.equals("Jan")){
     System.out.print("Jan " + year);
     System.out.print(" has 31 days.");
     }
    if (month.equals("Feb")){
     System.out.print("Feb " + year);
     //LEAP YEAR FORMULA 
        if (year%4==0&&(year%100!=0||year%400==0))
    {System.out.print(" has 29 days.");
        if (year%4!=0&&(year%100==0||year%400!=0))
    {System.out.print(" has 28 days.");}}
    }
    if (month.equals("Mar")){
     System.out.print("Mar " + year);
     System.out.print(" has 31 days.");
    }
    if (month.equals("Apr")){
     System.out.print("Apr " + year);
     System.out.print(" has 30 days.");
    }
    if (month.equals("May")){
     System.out.print("May " + year);
     System.out.print(" has 31 days.");
    }
    if (month.equals("Jun")){
     System.out.print("Jun " + year);
     System.out.print(" has 30 days.");
    }
    if (month.equals("Jul")){
     System.out.print("Jul " + year);
     System.out.print(" has 31 days.");
    }
    if (month.equals("Aug")){
     System.out.print("August " + year);
     System.out.print(" has 31 days.");
    }
    if (month.equals("Sep")){
     System.out.print("Sep " + year);
     System.out.print(" has 30 days.");
    }
    if (month.equals("Oct")){
     System.out.print("Oct " + year);
     System.out.print(" has 31 days.");
    }
    if (month.equals("Nov")){
     System.out.print("Nov " + year);
     System.out.print(" has 30 days.");
    }
    if (month.equals("Dec")){
     System.out.print("Dec " + year);
     System.out.print(" has 31 days.");
    }

}

}

Grave203
  • 17
  • 4
  • 2
    Your post **is** case sensitive. Not sure what you're asking. – Elliott Frisch Mar 01 '17 at 23:35
  • 1
    To see if your code is correct, first test it yourself. If it works, great, but perhaps keep testing it. If your current output does not match your desired output, and you don't know why, then it's time to start debugging. If you're not sure how to go about doing this, then please have a look at: [How to Debug Small Programs](http://ericlippert.com/2014/03/05/how-to-debug-small-programs/). – Hovercraft Full Of Eels Mar 01 '17 at 23:37
  • when I test it. it still outputs even if I type jan instead of Jan. I am trying to see if I am missing something. **wait! it works. sorry!** – Grave203 Mar 01 '17 at 23:45

1 Answers1

0

Just assuming you only mean the first letter of the month is case sensitive, you could include this in each for loop

    if (month.equals("Feb") || month.equals("feb")){
       System.out.print("Feb " + year);

This would work assuming it is only the first letter that is case sensitive. The || mean if the input means this "Feb" or this "feb". You could keep using it on and on for each different example until their is no other possible options for feb i.e. FEB, FeB, fEb etc...

HelloWorld
  • 133
  • 1
  • 15
  • thank you. I ran the program again and put in Jan and jan(did the same with all months), and it did not print when it was a lower case. HUZZAH! – Grave203 Mar 02 '17 at 00:12
  • please dont forget to prefer the answer if it solved your issue. – HelloWorld Mar 02 '17 at 00:22