Erin S.

asked • 11/27/17

Write Java code to Create Month and Show Month

I do not have errors, but I am unsure I have everything I need for my "show month" file. Code is below, thanks for the help!
 
Month
 
import java.util.Scanner;

public class Month
{
//variables that declare the monthName String and int monthNum
static String monthName;
static int monthNum = 0;

public void monthInput()// asking for user input then becomes an assigned value
{
Scanner input = new Scanner(System.in);
System.out.println("Hello! Please enter a month number:");
monthNum = input.nextInt();
}

public static void monthName()// assigns month numbers to their names
{
switch(monthNum)
{
case 1:
monthName = "January";
break;
case 2:
monthName = "February";
break;
case 3:
monthName = "March";
break;
case 4:
monthName = "April";
break;
case 5:
monthName = "May";
break;
case 6:
monthName = "June";
break;
case 7:
monthName = "July";
break;
case 8:
monthName = "August";
break;
case 9:
monthName = "September";
break;
case 10:
monthName = "October";
break;
case 11:
monthName = "November";
break;
case 12:
monthName = "December";
break;

}
}
public static void DisplayMonth()// to display a message to the user that includes their input
{
System.out.println("The month number keyed by you is" + monthNum + "\nwhich is the motnh of " + monthName);
}

}
 
Show Month
 
public class ShowMonth // declared class
{
public static void main(String[]args)// main method of class
{
new Month().monthInput();// enter a new month object
Month.monthName();

}
}

1 Expert Answer

By:

David W. answered • 11/27/17

Tutor
4.7 (90)

Experienced Prof

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.