I need all of this below to be transformed into a GUI where a scroll bar is used
ID: 3722601 • Letter: I
Question
I need all of this below to be transformed into a GUI where a scroll bar is used for the month and a TextField for the year that must be filled in if the month is February. Then a read only TextField for the line of the poem that you output.
import java.util.Scanner;
public class Days
{
static Scanner set=new Scanner(System.in);
public static void main(String[] args)
{
String months[]={"January","February","March","April","May","June","July","August","September","October","November","December"};
String line[]=new String[5];
line[0]="Thirty days hath September";
line[1]="April, June, and November";
line[2]="All the rest have thirty-one";
line[3]="with February's 28 to make it fun";
line[4]="Leap Year happening one in four, Gives February one day more.";
//Creates Scanner object for keyboard input
String month="";
while(true)
{
//Prompt user for month and input data
System.out.println("Enter a valid month name");
month=set.nextLine();
if(validateMonth(month,months))
{
break;
}
}
//Prompt user for year and input data
System.out.println("Enter the year");
int year=Integer.parseInt(set.nextLine());
//Determine whether the user inputted January
if(month.equalsIgnoreCase("January"))
{
System.out.println(line[2]);
}
//Determine whether user inputted Feburary
else if(month.equalsIgnoreCase("February"))
{
if ((year % 4 == 0) && (year % 100 == 0) && (year % 400 == 0))
{
System.out.println(line[4]);
}
else
{
System.out.println(line[3]);
}
}
//Determine which month the user inputted and retrieve correlating line
else if(month.equalsIgnoreCase("March"))
{
System.out.println(line[2]);
}
else if(month.equalsIgnoreCase("April"))
{
System.out.println(line[1]);
}
else if(month.equalsIgnoreCase("May"))
{
System.out.println(line[2]);
}
else if(month.equalsIgnoreCase("June"))
{
System.out.println(line[1]);
}
else if(month.equalsIgnoreCase("July"))
{
System.out.println(line[2]);
}
else if(month.equalsIgnoreCase("August"))
{
System.out.println(line[2]);
}
else if(month.equalsIgnoreCase("September"))
{
System.out.println(line[0]);
}
else if(month.equalsIgnoreCase("October"))
{
System.out.println(line[2]);
}
else if(month.equalsIgnoreCase("November"))
{
System.out.println(line[1]);
}
else if(month.equalsIgnoreCase("December"))
{
System.out.println(line[2]);
}
}
//Validate the months entered
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;
}
}
Explanation / Answer
program:-
import javax.swing.JOptionPane;
public class Days {
public static void main(String[] args)
{
String months[]={"January","February","March","April","May","June","July","August","September","October","November","December"};
String line[]=new String[5];
line[0]="Thirty days hath September";
line[1]="April, June, and November";
line[2]="All the rest have thirty-one";
line[3]="with February's 28 to make it fun";
line[4]="Leap Year happening one in four, Gives February one day more.";
//Creates Scanner object for keyboard input
Scanner s=new Scanner(System.in);
Scanner set=new Scanner(System.in);
String month="";
while(true)
{
//Prompt user for month and input data
//System.out.println("Enter a valid month name");
month = (String) JOptionPane.showInputDialog(null, "Choose now...",
"month Poem", JOptionPane.QUESTION_MESSAGE, null, months,
months[1]);
if(validateMonth(month,months))
{
break;
}
}
//Prompt user for year and input data
//System.out.println("Enter the year");
int year=Integer.parseInt(JOptionPane.showInputDialog("Year"));
//Determine whether the user inputted January
if(month.equalsIgnoreCase("January"))
{
System.out.println(line[2]);
}
//Determine whether user inputted Feburary
else if(month.equalsIgnoreCase("February"))
{
if ((year % 4 == 0) && (year % 100 == 0) && (year % 400 == 0))
{
JOptionPane.showMessageDialog(null, line[4]);
//System.out.println(line[4]);
}
else
{JOptionPane.showMessageDialog(null, line[3]);
//System.out.println(line[3]);
}
}
//Determine which month the user inputted and retrieve correlating line
else if(month.equalsIgnoreCase("March"))
{
JOptionPane.showMessageDialog(null, line[2]);
//System.out.println(line[2]);
}
else if(month.equalsIgnoreCase("April"))
{
JOptionPane.showMessageDialog(null, line[1]);
//System.out.println(line[1]);
}
else if(month.equalsIgnoreCase("May"))
{
System.out.println(line[2]);
}
else if(month.equalsIgnoreCase("June"))
{
System.out.println(line[1]);
}
else if(month.equalsIgnoreCase("July"))
{
System.out.println(line[2]);
}
else if(month.equalsIgnoreCase("August"))
{
System.out.println(line[2]);
}
else if(month.equalsIgnoreCase("September"))
{
System.out.println(line[0]);
}
else if(month.equalsIgnoreCase("October"))
{
System.out.println(line[2]);
}
else if(month.equalsIgnoreCase("November"))
{
System.out.println(line[1]);
}
else if(month.equalsIgnoreCase("December"))
{
System.out.println(line[2]);
}
}
//Validate the months entered
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;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.