Question: JAVA + Redo the Day program as a GUI. Use a scroll bar for the month and a TextField for the year that must be

JAVA + Redo the Day program as a GUI. Use a scroll bar for the month and a TextField for the year that must be filled in if the month is February. Use a read only TextField for the line of the poem that you output.

Initial Day program is below.

public class Days {

public static void main(String[] args)throws IOException { //Creating a array of string with month names to validate the input month string String months[]={"January","February","March","April","May","June","July","August","September","October","November","December"}; //Creating a array of strings to hold the lines of poem,each line as one string element of array String poem[]=new String[5]; poem[0]="Thirty days hath September"; poem[1]="April, June, and November"; poem[2]="All the rest have thirty-one"; poem[3]="with February's 28 to make it fun"; poem[4]="Leap Year happening one in four, Gives February one day more."; InputStreamReader ir=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(ir); String month=""; //Prompting user for a valid month name,until a valid month is entered loop will go on while(true) { System.out.println("Enter a valid month name"); month=br.readLine(); //Validated month name if it is a valid month than only proceed else reprompt if(validateMonth(month,months)) { break; } } System.out.println("Enter the year"); int year=Integer.parseInt(br.readLine()); if(month.equalsIgnoreCase("January")) { System.out.println(poem[2]); } else if(month.equalsIgnoreCase("February")) { if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) { System.out.println(poem[4]); } else { System.out.println(poem[3]); } } else if(month.equalsIgnoreCase("March")) { System.out.println(poem[2]); } else if(month.equalsIgnoreCase("April")) { System.out.println(poem[1]); } else if(month.equalsIgnoreCase("May")) { System.out.println(poem[2]); } else if(month.equalsIgnoreCase("June")) { System.out.println(poem[1]); } else if(month.equalsIgnoreCase("July")) { System.out.println(poem[2]); } else if(month.equalsIgnoreCase("August")) { System.out.println(poem[2]); } else if(month.equalsIgnoreCase("September")) { System.out.println(poem[0]); } else if(month.equalsIgnoreCase("October")) { System.out.println(poem[2]); } else if(month.equalsIgnoreCase("November")) { System.out.println(poem[1]); } else if(month.equalsIgnoreCase("December")) { System.out.println(poem[2]); } }

/** * validateMonth validates the months * @param month * @param months * @return the value of result */ //For validating if month name is valid private static boolean validateMonth(String month,String months[]) { boolean result=false; for(int i=0;i<12;++i) { if(month.equalsIgnoreCase(months[i])) { result=true; break; } } return result; }

}

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!