- Problem description
- Enter year, whether the input year is leap years (regardless of illegal input)
- The conditions for a year that are leap years are:
- The year can be divisible by 4 but not divisible by 100 or
- The year can be divisible by 400.
- Code implementation
ImportJavax.swing.JOptionPane;Importjavafx.application.Application;Importjavafx.event.ActionEvent;ImportJavafx.event.EventHandler;ImportJavafx.geometry.Pos;ImportJavafx.scene.Scene;ImportJavafx.scene.control.Button;ImportJavafx.scene.control.Label;ImportJavafx.scene.control.TextField;ImportJavafx.scene.layout.HBox;ImportJavafx.stage.Stage; Public classTaskextendsApplication { Public Static voidMain (string[] args) {//TODO auto-generated Method Stubtask.launch (args); } PrivateTextField TextField =NewTextField (); @Override Public voidStart (Stage arg0)throwsException {//TODO auto-generated Method StubArg0.settitle ("Testing" ); HBox HBox=NewHBox (8 ); Textfield.setprefcolumncount (25 ); Hbox.setalignment (Pos.center_left); Button btn=NewButton (); Btn.settext (Submitted ); Btn.setonaction (NewListener ()); Hbox.getchildren (). AddAll (NewLabel ("Please enter year:"), TextField, BTN); Arg0.setscene (NewScene (Hbox, 460, 50 )); Arg0.show (); } Public classListenerImplementsEventhandler<actionevent>{@Override Public voidhandle (ActionEvent arg0) {//TODO auto-generated Method StubString str =Textfield.gettext (); String inf= ""; if(Isleap (Integer.parseint (str))) {inf= "Enter year for leap years"; } Else{inf= "Enter year non-leap years"; } joptionpane.showmessagedialog (NULL, INF, "Information", Joptionpane.information_message); } } Private BooleanIsleap (intYear ) { if(year% 4! = 0 ) { return false; } Else if(year% 100! = 0 ) { return true; } Else if(Year% 400! = 0 ) { return false; } Else { return true; } }}
| Number |
Input |
|
Predictive output |
| 1 |
1963 |
Not divisible by 4. |
Enter year non-leap years |
| 2 |
1964 |
Can be divisible by 4 but not divisible by 100. |
Enter years as leap year |
| 3 |
1900 |
Divisible by 4 can be divisible by 100, but not divisible by 400. |
Enter year non-leap years |
| 4 |
2000 |
Can be divisible by 400. |
Enter years as leap year |
"Software Testing" leap year issues (regardless of illegal input)