"Software Testing" leap year issues (regardless of illegal input)

Source: Internet
Author: User

    • 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; }    }}

    • Test Cases
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
    • Test results

"Software Testing" leap year issues (regardless of illegal input)

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.