First, the procedure requirements
How to determine a leap year:
1, the ordinary year can be divisible by 4 and not divisible by 100 for leap years. (such as 2004 years is a leap year, 1900 is not a leap year) 2, century can be divisible by 400 is leap years. (For example, 2000 is a leap year, 1900 is not a leap years) normally in a text box, enter an age, click the OK button, the program will determine whether the year to ask leap years, but if the input is a string or a negative number, the program will produce an exception, and this blog is to solve the problem. Second, the test analysis
| Number |
Input |
Output |
| 1 |
2000 |
It's a leap year. |
| 2 |
1900 |
1900 is isn't a leap year. |
| 3 |
Sdafsd |
Input Invalid. |
| 4 |
-100 |
Please input a positive number. |
Third, the code implementation
Importjavafx.application.Application;Importjavafx.event.ActionEvent;ImportJavafx.event.EventHandler;ImportJavafx.scene.Scene;ImportJavafx.scene.control.Button;ImportJavafx.scene.control.TextField;ImportJavafx.scene.layout.AnchorPane;ImportJavafx.scene.text.Text;ImportJavafx.stage.Stage; Public classCalculateextendsapplication{ Public Static voidMain (String arg0[]) {calculate.launch (arg0); } Public voidStart (Stage stage)throwsException {stage.settitle ("Calculate Year Program"); Anchorpane Root=NewAnchorpane (); Text text=NewText (); Text.settext ("Please input the number of the year:"); Root.getchildren (). Add (text); Anchorpane.settopanchor (text,30.0); Anchorpane.setleftanchor (text,90.0); FinalTextField input =NewTextField (); Root.getchildren (). Add (input); Anchorpane.settopanchor (Input,50.0); Anchorpane.setleftanchor (Input,90.0); Button Submit=NewButton (); Submit.settext ("Submit"); Root.getchildren (). Add (Submit); Anchorpane.settopanchor (Submit,50.0); Anchorpane.setleftanchor (Submit,240.0); Submit.setonaction (NewEventhandler<actionevent>() { Public voidhandle (ActionEvent arg0) {Final intYear =Integer.parseint (Input.gettext (). toString ()); Stage Newstage=NewStage (); Anchorpane Newroot=NewAnchorpane (); Text result=NewText (); Try{ if((year% 4 = = 0 && Year% 100! = 0) | | (Year% 400 = = 0) {Result.settext ( year+ "is a leap year."); } Else{Result.settext ( year+ "isn't a leap year."); } } Catch(Exception e) {Result.settext ("Input Invalid"); } if(Year < 0) {Result.settext ("Please input a positive number."); } newroot.getchildren (). Add (Result); Anchorpane.settopanchor (Result,20.0); Anchorpane.setleftanchor (Result,30.0); Newstage.setscene (NewScene (Newroot, 250, 50)); Newstage.show (); } }); Stage.setscene (NewScene (Root, 400, 100)); Stage.show (); }}
Iv. Results of the procedure
Software testing-Leap year testing