Questions about the leap year test:
Condition: 1. 4 Years a leap, 100 years do not leap, 400 years and leap.
2. Enter the year greater than 0.
3. Enter the number only.
Source:
public class Leapyear extends application {
public static void Main (string[] args) {
Leapyear.launch (args);
}
Private TextField TextField = new TextField ();
@Override
public void Start (Stage arg0) throws Exception {
Arg0.settitle ("Leapyear");
HBox HBox = new HBox (8);
Textfield.setprefcolumncount (25);
Hbox.setalignment (Pos.center_left);
Button btn = New button ();
Btn.settext ("OK");
Btn.setonaction (New Listener ());
Hbox.getchildren (). AddAll (New Label ("Please enter Year:"), TextField, BTN);
Arg0.setscene (New Scene (Hbox, 450, 80));
Arg0.show ();
}
public class Listener implements eventhandler<actionevent> {
@Override
public void handle (ActionEvent arg0) {
String str = Textfield.gettext ();
String inf = "";
if (isleapyear (Integer.parseint (str))) {
inf = "Leap year";
}
Else {
inf = "Non-leap Year";
}
Joptionpane.showmessagedialog (NULL, INF, "Information",
Joptionpane.information_message);
}
}
Private boolean isleapyear (int year) {
if (year% 4! = 0) {
return false;
}
Else if (year%!! = 0) {
return true;
}
Else if (year%!! = 0) {
return false;
}
Else {
return true;
}
}
}
Number |
Test Cases |
Results |
1 |
1995 |
Non-leap year |
2 |
2000 |
Leap |
3 |
2012 |
Leap |
4 |
0000 |
Leap |
5 |
1900 |
Non-leap year |
Test results:
1.
2.
3.
4.
5.
But there is a problem with the error when the input is empty. There are also errors when you enter a flight number.
Leap Year detection issues