Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import java.util.Scanner; {public class Lab5Soln {public static void main (Strin

ID: 3792451 • Letter: I

Question

import java.util.Scanner; {public class Lab5Soln {public static void main (String[] args) {int monthlnt; String monthName; Scanner scan = new Scanner(System.in);//Get a month in integer and a month name System.out.print ("Enter a month using an integer (between 1 and 12): "); monthlnt = scan.nextlnt(); System.out.print ("Enter a month using its name: "); monthName = scan.next();//set up switch statement for the numbers 1 through 12//in each case, use an if statement to check if the variable monthName contains//their month name, and print either "They match!" or "They don't match!" switch(monthlnt) {case 1:///COMPLETE THE REST}}}

Explanation / Answer

import java.util.Scanner;

public class Lab5soln
{
   public static void main(String[] args)
   {
       int monthInt;
       String monthName,lowerMonth;
      
       Scanner scan = new Scanner(System.in);
      
       System.out.println("Enter a month using an integer (between 1 and 12): ");
       monthInt = scan.nextInt();
      
       System.out.println("Enter a month using its name: ");
       monthName = scan.next();
       lowerMonth = monthName.toLowerCase();
      
       switch(monthInt)
       {
           case 1:
           if(lowerMonth.equals("jan") || lowerMonth.equals("january"))
                   System.out.println("They Match!");
               else
                   System.out.println("They don't Match");
           break;

       case 2:
           if(lowerMonth.equals("feb") || lowerMonth.equals("february"))
                   System.out.println("They Match!");
               else
                   System.out.println("They don't Match");
           break;          
       case 3:
           if(lowerMonth.equals("mar") || lowerMonth.equals("march"))
                   System.out.println("They Match!");
               else
                   System.out.println("They don't Match");
           break;          
       case 4:
           if(lowerMonth.equals("apr") || lowerMonth.equals("april"))
                   System.out.println("They Match!");
               else
                   System.out.println("They don't Match");
           break;          
       case 5:
           if(lowerMonth.equals("may") || lowerMonth.equals("may"))
                   System.out.println("They Match!");
               else
                   System.out.println("They don't Match");
           break;          
       case 6:
           if(lowerMonth.equals("jun") || lowerMonth.equals("june"))
                   System.out.println("They Match!");
               else
                   System.out.println("They don't Match");
           break;          
       case 7:
           if(lowerMonth.equals("jul") || lowerMonth.equals("july"))
                   System.out.println("They Match!");
               else
                   System.out.println("They don't Match");
           break;          
       case 8:
           if(lowerMonth.equals("aug") || lowerMonth.equals("august"))
                   System.out.println("They Match!");
               else
                   System.out.println("They don't Match");
           break;          
       case 9:
           if(lowerMonth.equals("sep") || lowerMonth.equals("september"))
                   System.out.println("They Match!");
               else
                   System.out.println("They don't Match");
           break;          
       case 10:
           if(lowerMonth.equals("oct") || lowerMonth.equals("october"))
                   System.out.println("They Match!");
               else
                   System.out.println("They don't Match");
           break;          
      
       case 11:

           if(lowerMonth.equals("nov") || lowerMonth.equals("november"))
                   System.out.println("They Match!");
               else
                   System.out.println("They don't Match");
           break;              

           case 12:
           if(lowerMonth.equals("dec") || lowerMonth.equals("december"))
                   System.out.println("They Match!");
               else
                   System.out.println("They don't Match");
           break;          
       }
      
   }
}