Question: I was presented with this problem: Create a Java class MonthNames with a single static method getMonthName which Takes a single integer corresponding to a

I was presented with this problem:

Create a Java class MonthNames with a single static method getMonthName which Takes a single integer corresponding to a month of the year, 1 representing January through 12 representing December, and Returns a string for the name of the month.

This is what I have so far

public class MonthNames {

public static String getMonthName (int numMonth) {

return "month"; }

public static void main (String [] args) {

System.out.println ("begin tests");

System.out.println ("Enter Month 1");

System.out.println ("Expect: January");

System.out.println ("Actual: " + getMonthName (1));

System.out.println ("Enter Month 6");

System.out.println ("Expect: June");

System.out.println ("Actual: " + getMonthName (6));

System.out.println ("Enter Month 12");

System.out.println ("Expect: December");

System.out.println ("Actual: " + getMonthName (12));

System.out.println ("End tests");

if(numMonth = 1) { System.out.println("January"); }

else(numMonth = 2) { System.out.println("February"); }

else(numMonth = 3) { System.out.println("March"); }

else(numMonth = 4) { System.out.println("April"); }

else(numMonth = 5) { System.out.println("May"); }

else(numMonth = 6) { System.out.println("June"); }

else(numMonth = 7) { System.out.println("July"); }

else(numMonth = 8) { System.out.println("August"); }

else(numMonth = 9) { System.out.println("September"); }

else(numMonth = 10) { System.out.println("October"); }

else(numMonth = 11) { System.out.println("November"); }

else(numMonth = 12) { System.out.println("December"); }

else {System.out.println("Not a month"); }

What else do i need to do to this code in order to make it work? (JAVA)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!