Question
In JAVA, I am using eclipse. Use the Month Class from Lab 1 Create a UI that has two sections. Use CSS to visually separate
In JAVA, I am using eclipse.
Use the Month Class from Lab 1
Create a UI that has two sections. Use CSS to visually separate the sections.
Section 1:
Section 1 has a field in which to enter text, a field to display read only text and a button.
When the button is pressed, take the value of the text box and try to create a month object. If a number was entered, use the constructor that accepts an integer. If alphabetic characters were entered, use the constructor that accepts a string. If nothing is entered, use the no argument constructor.
If a valid month object is created, use the toString function on the month object to display info about the month. Otherwise, display an appropriate error message.
Section 2
Section 2 has two drop down lists, a button and a field to display read only text. One drop down has the values 1-12. The other has the names of the months. When the button is pressed, create two month objects using the appropriate constructors, then display if the months are equal, if month 1 > month 2 or if month 2 > month 1.
Month Class:
public class Month {
int monthNumber;
String monthName;
public Month() {
monthNumber = 1;
}
public Month(int month) {
monthNumber = month;
if (month > 12 || month < 1) {
month = 1;
}
}
public Month(String month) {
this.monthName = month;
if (this.monthName.equalsIgnoreCase("January")) {
monthNumber = 1;
}
else if (this.monthName.equalsIgnoreCase("February")) {
monthNumber = 2;
}
else if (this.monthName.equalsIgnoreCase("March")) {
monthNumber = 3;
}
else if (this.monthName.equalsIgnoreCase("April")) {
monthNumber = 4;
}
else if (this.monthName.equalsIgnoreCase("May")) {
monthNumber = 5;
}
else if (this.monthName.equalsIgnoreCase("June")) {
monthNumber = 6;
}
else if (this.monthName.equalsIgnoreCase("July")) {
monthNumber = 7;
}
else if (this.monthName.equalsIgnoreCase("August")) {
monthNumber = 8;
}
else if (this.monthName.equalsIgnoreCase("September")) {
monthNumber = 9;
}
else if (this.monthName.equalsIgnoreCase("October")) {
monthNumber = 10;
}
else if (this.monthName.equalsIgnoreCase("November")) {
monthNumber = 11;
}
else if (this.monthName.equalsIgnoreCase("December")) {
monthNumber = 12;
}
}
public void setMonthNumber(int monthNumber) {
if (monthNumber >= 1 && monthNumber <= 12) {
this.monthNumber = monthNumber;
}
else {
monthNumber = 1;
}
}
public int getMonthNumber() {
return monthNumber;
}
public String getMonthName() {
switch (monthNumber) {
case 1:
return "January";
case 2:
return "February";
case 3:
return "March";
case 4:
return "April";
case 5:
return "May";
case 6:
return "June";
case 7:
return "July";
case 8:
return "August";
case 9:
return "September";
case 10:
return "October";
case 11:
return "November";
case 12:
return "December";
default:
return "January";
}
}
public String toString() {
return getMonthName();
}
public boolean equals(Month month) {
return month.getMonthNumber() == this.monthNumber;
}
public boolean greaterThan(Month month) {
return month.monthNumber > this.monthNumber;
}
public boolean lessThan(Month month) {
return month.monthNumber < this.monthNumber;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
QUESTION In JAVA I am using eclipse Use the Month Class from Lab 1 Create a UI that has two sections Use CSS to visually separate the sections Section 1 Section 1 has a field in which to enter text a ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started