Lab exercise Complete the following exercise in your labsess

Lab exercise Complete the following exercise in your labsession Do not forget to ask your TA for any help you need. 1. Control statements: Lab5.java Go ahead and download the file Lab5.java from blackboard to your working folder on your computer. Complete this program to determine if two inputs from a user (a keyboard) are matching. The input to the program includes a month expressed using an integer (between 1 and 12) and a month using their name such as January. Using the first entered integer, write a switch statement and their cases for each digit (12 cases), and in each case, set up an if statement to check if each digit corresponds to their month name. Output sample: the user input is in bold Enter a month using an integer (between 1 and 12): Enter a month using its name: February They match! Another output sample: the user input is in bold Enter a month using an integer (between 1 and 12): Enter a month using its name: July They don\'t match! Name your program for theRuestion 1as follows Lab5.java. And this file needs to be submitted using the submit Labs/Assignments button in the blackboard site. (In the submission site, you need to login using the account that you have created before,

Solution

Lab5Soin.java

import java.util.Scanner;


public class Lab5Soin {

  
   public static void main(String[] args) {
       int monthInt;
       String monthName;
       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();
       String outputString = \"\";
       switch(monthInt){
       case 1: outputString = monthName.equalsIgnoreCase(\"January\")? \"They match!\": \"They don\'t match!\"; break;
       case 2: outputString = monthName.equalsIgnoreCase(\"February\")? \"They match!\": \"They don\'t match!\"; break;
       case 3: outputString = monthName.equalsIgnoreCase(\"March\")? \"They match!\": \"They don\'t match!\"; break;
       case 4: outputString = monthName.equalsIgnoreCase(\"April\")? \"They match!\": \"They don\'t match!\"; break;
       case 5: outputString = monthName.equalsIgnoreCase(\"May\")? \"They match!\": \"They don\'t match!\"; break;
       case 6: outputString = monthName.equalsIgnoreCase(\"June\")? \"They match!\": \"They don\'t match!\"; break;
       case 7: outputString = monthName.equalsIgnoreCase(\"July\")? \"They match!\": \"They don\'t match!\"; break;
       case 8: outputString = monthName.equalsIgnoreCase(\"August\")? \"They match!\": \"They don\'t match!\"; break;
       case 9: outputString = monthName.equalsIgnoreCase(\"September\")? \"They match!\": \"They don\'t match!\"; break;
       case 10: outputString = monthName.equalsIgnoreCase(\"October\")? \"They match!\": \"They don\'t match!\"; break;
       case 11: outputString = monthName.equalsIgnoreCase(\"November\")? \"They match!\": \"They don\'t match!\"; break;
       case 12: outputString = monthName.equalsIgnoreCase(\"December\")? \"They match!\": \"They don\'t match!\"; break;
       default: outputString = \"Invalid month\";
       }
       System.out.println(outputString);

   }

}

Output:

Enter a month using an integer between (1 and 12):
2
Enter a month using its name:
February
They match!

Enter a month using an integer between (1 and 12):
6
Enter a month using its name:
July
They don\'t match!

 Lab exercise Complete the following exercise in your labsession Do not forget to ask your TA for any help you need. 1. Control statements: Lab5.java Go ahead a
 Lab exercise Complete the following exercise in your labsession Do not forget to ask your TA for any help you need. 1. Control statements: Lab5.java Go ahead a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site