Create a Java program that takes a month number as an input

Create a Java program that takes a month number as an input and outputs the proper month name. Your program should have two classes. The first class, Month, should include the method MonthInput, which takes a user input and stores it in a class level variable. The second method MonthName of data type String, will accept one argument, a month number, and return the proper month name (use any decision structure type in this method body). The third method, DisplayMonth, will accept a string with the name of the month found and generate a user-friendly display screen with the user input entered and the name the month found. The second class, ShowMonth, will have the main method. It will create an object from the Month class and call each of three instance methods defined in the Month class.

Solution

import java.util.*;
public class month {

   int monthinput()
   {
       Scanner s=new Scanner(System.in);
       return(s.nextInt());
   }
   String monthname(int n)
  
   {
       String a;
       if(n==1)
       {
      
   return (\"january\");
       }
       if(n==2)
       {
           return(\"febrauary\");
       }
  
       if(n==3)
       {
           return(\"march\");
       }
       if(n==4)
       {
           return(\"april\");
       }
       if(n==5)
       {
           return(\"may\");
       }
       if(n==6)
       {
           return(\"june\");
       }
       if(n==7)
       {
           return(\"july\");
       }
       if(n==8)
       {
           return(\"august\");
       }
       if(n==9)
       {
           return(\"september\");
       }
       if(n==10)
       {
           return(\"october\");
       }
       if(n==11)
       {
           return(\"november\");
       }
       if(n==12)
       {
           return(\"december\");
       }
       return null;
      
      
      
   }
   void displaymonth(String ss)
   {
       System.out.println(\"the given month is\"+\" \"+ss);
   }
}

driver programme is


public class driver {

   public static void main(String args[])
   {
       month m=new month();
       int x=m.monthinput();
       String s=m.monthname(x);
       m.displaymonth(s);
   }
}

--------------------------------------------------------------------------------------------------------------------------------------------------

output

5
the given month is may


  
  
  

Create a Java program that takes a month number as an input and outputs the proper month name. Your program should have two classes. The first class, Month, sho
Create a Java program that takes a month number as an input and outputs the proper month name. Your program should have two classes. The first class, Month, sho

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site