Question

In: Computer Science

Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using...

Using Eclipse IDE

Create a Java Program/Class named MonthNames that will display the Month names using an array.

1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc.

2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the given input to align with the array index and then confirm that the variable is in the range of 0-11. If it is not, display "Invalid Entry". If it is in range, display the string the matches the given entry. Then prompt to continue.

Tip:For the String input for the Prompt to Continue - it is preferable to use .next() instead of .nextLine(). Otherwise you will run into the Scanner Bug described in Section 3.10.

3. Display "Done" after the loop processing has ended.

Enter the Month of the Year: 1

The month name is January

Try again (Y/N): Y

Enter the Month of the Year : 2

The Month name is February.

Try again (Y/N): Y

Enter the Month of the Year : 55

Invalid Entry

Try again (Y/N): N

You can copy the code below to seed your array.:

{"January","February","March","April","May","June","July","August","September","October","November","December"};

Solutions

Expert Solution

*******************Summary********************

The program for above question is given below with comments and output...

I have used do while loop for running the code repeatedly....

The explanation is in the comments....

I hope it works for you !!!!!!!!!!!!!!!

Ask for any help if needed....happy to help :)

*******************Program*********************

MonthNames.java

import java.util.Scanner;

public class MonthNames
{
        public static void main(String[] args) 
        {
             String[] months={"January","February","March","April","May","June","July","August","September","October","November","December"};       //storing months names in array
             String ch;          //string for storing a char if user wants to continue
             
             Scanner sc=new Scanner(System.in);      //Scanner object to take input from user
             
             do        //do while loop to run the code repeatedly
                {
                     System.out.print("\nEnter the Month of Year : ");        //asking for user to enter month number
                int month=sc.nextInt();       //taking input and storing in month
                month=month-1;                //decrementing value of month by1 to get a value between 0-11
                
                if(month>=0 && month<=11)          //if month number is correct
                System.out.println("The Month Name is "+months[month]);          //then print month name
                else                               //otherwise
                System.out.println("Invalid Entry");                             //print Invalid entry
                
                System.out.print("Try Again (Y/N) : ");      //asking if user wants to continue
                ch=sc.next();            //taking input
                
                }while(ch.equals("Y"));            //checking if ch equals to Y ...if user entered Y when asked for continue...then run the loop again
                
                System.out.println("Done");             //print done when user is done entering months
        }
}

*************************Output*****************************


Related Solutions

Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A....
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A. Two bags per person are free. B. The Excess Bag Charge is $75 per bag. The program needs to do the following: 1. In your main method(),    Create integers to store the number of Passengers and also the total number of bags    Prompt for the number of passengers on a ticket.    Prompt for the total number of bags for all passengers...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
Task #1 The if Statement, Comparing Strings, and Flags (JAVA using Eclipse IDE 14) Create the...
Task #1 The if Statement, Comparing Strings, and Flags (JAVA using Eclipse IDE 14) Create the file PizzaOrder.java. Prompt the user to input the type of pizza that they want to order. In the end, you should print out the final order and price. Here is a sample output. Welcome to May and Adam’s Pizzeria Enter your first name: Amy Pizza Size(inches)     Cost         10            $10.99         12            $12.99         14            $14.99         16            $16.99 What size pizza would you...
Using ECLIPSE IDE Write a Java Program to play your version of the Texas Pick 3...
Using ECLIPSE IDE Write a Java Program to play your version of the Texas Pick 3 Lottery. You will need to include the provided code given below in your program. Task:The program will prompt for a number between 0 and 999. Your program will display the number of attempts it took for the entered number to match a randomly generated number. In the main() method, declare an int named myPick3choice. Create a prompt for myPick3choice as "Enter your Pick 3...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
Java program Create a public method named saveData for a class named Signal that will hold...
Java program Create a public method named saveData for a class named Signal that will hold digitized acceleration data. Signal has the following field declarations private     double timeStep;               // time between each data point     int numberOfPoints;          // number of data samples in array     double [] acceleration = new double [1000];          // acceleration data     double [] velocity = new double [1000];        // calculated velocity data     double [] displacement = new double [1000];        // calculated disp...
Java Programming Create a class named Problem1, and create a main method, the program does the...
Java Programming Create a class named Problem1, and create a main method, the program does the following: - Prompt the user to enter a String named str. - Prompt the user to enter a character named ch. - The program finds the index of the first occurrence of the character ch in str and print it in the format shown below. - If the character ch is found in more than one index in the String str, the program prints...
In java: -Create a class named Animal
In java: -Create a class named Animal
Java program. Need to create a class names gradesgraph which will represent the GradesGraphtest program. Assignment...
Java program. Need to create a class names gradesgraph which will represent the GradesGraphtest program. Assignment Create a class GradesGraph that represents a grade distribution for a given course. Write methods to perform the following tasks: • Set the number of each of the letter grades A, B, C, D, and F. • Read the number of each of the letter grades A, B, C, D, and F. • Return the total number of grades. • Return the percentage of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT