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

What are the errors in the following: // Import statements import java.util.Scan

ID: 3804717 • Letter: W

Question

What are the errors in the following: // Import statements import java.util.Scanner; public class SelectionSwitchDemo { public static void main(String[] args) { // Display a Welcome note System.out.println("Welcome to the Switch Demo"); // Variables to hold values int month = 0; int numDays = 0; // Use the Scanner class to input data Scanner scannerIn = new Scanner(System.in); System.out.println("Enter the Month (1-12):"); // the nextInt() method scans the next int value month = scannerIn.nextInt(); // Verify the month was entered System.out.println("The following month was entered " + month); // Selection statement to determine number // of days in month if (month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12) ) { numbDays = 31; } else if (month == 2) { numDays = 28; } else if ((month == 4) || (month == 6) || (month == 9) || (month == 11) ) { numbDays = 30; } } // Selection statement to determine Birthday and Holiday Greetings switch (month) { case 1: // Print out January Events System.out.println("Happy New Year!"); System.out.println("Celebrate Martin Luther King's Birthday!"); System.out.println("Happy Birthday to my niece Erica!"); break; case 2: // Print out February Events System.out.println("Happy Valentine's Day!"); System.out.println("Happy President's Day!"); System.out.println("Huge Birthday wishes to my son Elijah and niece Jelissa!"); break; case 3: // Print out March Events System.out.println("Enjoy St. Patrick's Day!"); System.out.println("Let's celebrate my sister Rondi Birthday!"); System.out.println("HAPPY 4th BIRTHDAY TO MY GRANDSON MONTY!"); break; case 4: // Print out April Events System.out.println("Thomas Jefferson was born in April!");; break; case 5: // Print out May Events System.out.println("Enjoy Memorial Day!"); System.out.println("Don't forget to Celebrate with Mom!"); System.out.println("Singing Birthday praises to my oldest sister Chelle!"); break; case 6: // Print out June Events System.out.println("Happy Father's Day!"); break; case 7: // Print out July Events System.out.println("Happy 4th of July!"); System.out.println("It's Your Birthday, Happy Birthday to AMIRAH and to Eric! She's my daughter, he's my brother, and it's their birthday!"); break; case 8: // Print out August Events System.out.println("Barack Obama was born in August! Happy Birthday Pres"); break; case 9: // Print out September Events System.out.println("Celebrate Labor Day!"); System.out.println("Let's Drink to my sister Jewel's Birthday! Happy Birthday!"); break; case 10: // Print out October Events System.out.println("Happy Halloween!"); System.out.println("Have a scary Birthday October Boos!"); break; case 11: // Print out November Events System.out.println("Happy Thanksgiving Day!"); System.out.println("Remember to Thank a Vet!"); System.out.println("Happy Birthday to November Babies!"); break; case 12: // Print out December Events System.out.println("Enjoy those Holidays with Family!") System.out.println("Celebrate Martin Luther King's Birthday!"); break; default: System.out.println("Month is not a value between 1 and 12"); // Exit the application for invalid Months System.exit(0); } // Output the number of days in the selected month System.out.println("Number of Days in month " + month + " is " + numDays); }

Explanation / Answer

// Import statements
import java.util.Scanner;

public class SelectionSwitchDemo
{
    public static void main(String[] args)
    {
        // Display a Welcome note
        System.out.println("Welcome to the Switch Demo");
        // Variables to hold values
        int month = 0;
        int numDays = 0;
        // Use the Scanner class to input data
        Scanner scannerIn = new Scanner(System.in);
        System.out.println("Enter the Month (1-12):");
        // the nextInt() method scans the next int value
        month = scannerIn.nextInt();
        // Verify the month was entered
        System.out.println("The following month was entered " + month);
        // Selection statement to determine number // of days in month
        if( (month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12) )
        {
            numDays = 31;
          
        }
        else if (month == 2)
        {
            numDays = 28;
          
        }
        else if ((month == 4) || (month == 6) || (month == 9) || (month == 11) )
        {
            numDays = 30;
        }
        // Selection statement to determine Birthday and Holiday Greetings
        switch (month)
        {
        case 1:
            // Print out January Events
            System.out.println("Happy New Year!");
            System.out.println("Celebrate Martin Luther King's Birthday!");
            System.out.println("Happy Birthday to my niece Erica!");
            break;
        case 2: // Print out February Events
            System.out.println("Happy Valentine's Day!");
            System.out.println("Happy President's Day!");
            System.out.println("Huge Birthday wishes to my son Elijah and niece Jelissa!");
            break;
        case 3: // Print out March Events
            System.out.println("Enjoy St. Patrick's Day!");
            System.out.println("Let's celebrate my sister Rondi Birthday!");
            System.out.println("HAPPY 4th BIRTHDAY TO MY GRANDSON MONTY!");
            break;
        case 4: // Print out April Events
            System.out.println("Thomas Jefferson was born in April!");
            break;
        case 5: // Print out May Events
            System.out.println("Enjoy Memorial Day!");
            System.out.println("Don't forget to Celebrate with Mom!");
            System.out.println("Singing Birthday praises to my oldest sister Chelle!");
            break;
        case 6: // Print out June Events
            System.out.println("Happy Father's Day!");
            break;
        case 7: // Print out July Events
            System.out.println("Happy 4th of July!");
            System.out.println("It's Your Birthday, Happy Birthday to AMIRAH and to Eric! She's my daughter, he's my brother, and it's their birthday!");
            break;
        case 8: // Print out August Events
            System.out.println("Barack Obama was born in August! Happy Birthday Pres");
            break;
        case 9: // Print out September Events
            System.out.println("Celebrate Labor Day!");
            System.out.println("Let's Drink to my sister Jewel's Birthday! Happy Birthday!");
            break;
        case 10: // Print out October Events
            System.out.println("Happy Halloween!");
            System.out.println("Have a scary Birthday October Boos!");
            break;
        case 11: // Print out November Events
            System.out.println("Happy Thanksgiving Day!");
            System.out.println("Remember to Thank a Vet!");
            System.out.println("Happy Birthday to November Babies!");
            break;
        case 12: // Print out December Events
            System.out.println("Enjoy those Holidays with Family!");
            System.out.println("Celebrate Martin Luther King's Birthday!");
            break;
        default: System.out.println("Month is not a value between 1 and 12");
            // Exit the application for invalid Months
            System.exit(0);
         }
            // Output the number of days in the selected month
            System.out.println("Number of Days in month " + month + " is " + numDays);
        }
}

Output:

Welcome to the Switch Demo

Enter the Month (1-12): 12

The following month was entered 12

Enjoy those Holidays with Family!

Celebrate Martin Luther King's Birthday!

Number of Days in month 12 is 31