Software testing-Leap year testing

Source: Internet
Author: User
Tags addall

Leap year detection is an important step for a program that needs to record years. The leap year rules for the Gregorian calendar are as follows:

1, the ordinary year can be divisible by 4 and not divisible by 100 for leap years. (For example, 2004 is a leap year, 1900 is not a leap)

2, Century can be divisible by 400 is a leap year. (as 2000 is a leap year, 1900 is not a leap year)however, for incorrect input, the program must respond to the hold, not to prevent the abnormal situation to hinder the operation of the program, the following is a leap year test program example:  
Enter year Results
2000 Leap
1900 Non-leap year
-1600 Illegal input
1864 Leap
Saddsa Illegal input

  

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 classTest2extendsApplication { Public Static voidMain (string[] args) {test2.launch (args); }     Public voidStart (Stage primarystage) {primarystage.settitle ("Input Testing" ); Anchorpane Root=NewAnchorpane (); Text text=NewText ("Please enter Test year"); FinalText textans1 =NewText (""); FinalTextField Intext1 =NewTextField (""); Intext1.setmaxsize (140, 20); Anchorpane.settopanchor (text,40.0); Anchorpane.setleftanchor (text,100.0); Anchorpane.settopanchor (textans1,120.0); Anchorpane.setleftanchor (textans1,70.0); Anchorpane.settopanchor (Intext1,60.0); Anchorpane.setleftanchor (Intext1,70.0);          Root.getchildren (). AddAll (TEXT,INTEXT1);                Root.getchildren (). AddAll (TEXTANS1); Button btn=NewButton ("Submit");        Root.getchildren (). AddAll (BTN); Anchorpane.settopanchor (BTN,90.0); Anchorpane.setleftanchor (BTN,120.0); Btn.setonaction (NewEventhandler<actionevent>() {             Public voidhandle (ActionEvent arg0) {textans1.settext (check (Intext1.gettext (). toString ()));              }        }); Primarystage.setscene (NewScene (root,300,200));        Primarystage.show (); }             Publicstring Check (String str) {Try{            intYear =integer.parseint (str); if(Year <0)                return"Please enter the correct year"; if(Year% 100 ==0){                if(Year% 400 = = 0)                    returnStr+ "is a leap year"; }            Else{                if(year% 4 = = 0)                    returnStr+ "is a leap year"; }            }Catch(Exception e) {return"Illegal input"; }            returnstr+ "Not a leap year"; } }

Software testing-Leap year testing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.