Doing Business 5.2 TDD

Source: Internet
Author: User

Package Runok;
Import java.util.*;
Import java.awt.*;
Import java.awt.event.ActionEvent;
Import Java.awt.event.ActionListener;

Import javax.swing.*;
public class VV extends JFrame implements actionlistener{

/**
* Fan Mingxiang
* Function: A simple arithmetic automatic generation system for elementary school students
*/
JPanel jp1,jp2,jp3;
JLabel jlb1,jlb2;
JButton jb1;
JTextField JTF1,JTF2;
JTextArea ee;
public double W1;
public double M1;
String FH;
public static void Main (string[] args)
{
VV start=new vv ();
}
Public VV ()
{
Jp1=new JPanel ();
Jp2=new JPanel ();
Jp3=new JPanel ();

Jlb1=new JLabel ("title");
Jlb2=new JLabel ("Your Answer:");

Jb1=new JButton ("Judgment Answer");
Jb1.addactionlistener (this);
Jb1.setactioncommand ("AA");
JTextArea txtarea = new JTextArea (1,15);
Jtf2=new JTextField (20);
EE = new JTextArea (1,10);
//Set Layout management
This.setlayout (new GridLayout (3,1));
//Join each component
Jp1.add (JLB1);
Jp1.add (Txtarea);

Jp2.add (JLB2);
Jp2.add (JTF2);
Jp3.add (JB1);
Jp3.add (EE);
//Join to JFrame
This.add (JP1);
This.add (JP2);
This.add (JP3);
Here with yy method to get the title W symbol m
yy tt=new yy ();


W1=tt.ret1 ();
M1=tt.ret2 ();
Fh=tt.ret3 ();
Txtarea.append (W1+FH+M1);
This.setsize (400, 250);
This.setdefaultcloseoperation (Jframe.exit_on_close);
This.setvisible (TRUE);
}
public void Yes ()
{ee.append ("Correct! "); }
public void No ()
{ee.append ("Error! ");}
public void cc ()
{
int answer= (int) (Double.parsedouble (Jtf2.gettext ()));;
if (fh.equals ("+"))
{
if (ANSWER==W1+M1) {
Yes ();
}else{
No ();
}
}
if (Fh.equals ("-"))
{
if (ANSWER==W1-M1) {
Yes ();
}else{
No ();
}
}
if (Fh.equals ("*"))
{
if (ANSWER==W1*M1) {
Yes ();
}else{
No ();
}
}
if (Fh.equals ("/"))
{
if (ANSWER==W1/M1) {
Yes ();
}else{
No ();
}
}
}
@Override
public void actionperformed (ActionEvent e)
{
// !!!!
if (e.getactioncommand () = = "AA")
{
CC ();
}
}

}


Class yy
{
private int max=4;
private int min=1;
Private double w2,m2;
Private String FF;
Random random = new random ();

System.out.println (s);
Public yy ()
{
int s = random.nextint (max)% (max-min+1) + min;

Double x=random.nextint (max-2)% (max-2-min+1) + min;

Double y=random.nextint (max-1)% (max-1-min+1) + min;
int y1up= (int) Math.pow (10,x);
int y1dn= (int) Math.pow (10,x-1);
int y2up= (int) Math.pow (10,y);
int y2dn= (int) Math.pow (10,y-1);
int x_y1=random.nextint (Y1UP)% (y1up-y1dn+1) + y1dn;
int x_y2=random.nextint (y2up)% (y2up-y2dn+1) + Y2dn;
Double w= (double) x_y1;
Double m= (double) x_y2;
This.w2=w;
This.m2=m;
Switch (s)
{
Case 1:
{
this.ff= "+";
System.out.println (w+ "+" +m+ "=");
break;
}
Case 2:
{
this.ff= "-";
System.out.println (w+ "-" +m+ "=");
break;
}
Case 3:
{
this.ff= "*";
SYSTEM.OUT.PRINTLN (w+ "*" +m+ "=");
break;
}
Case 4:
{
this.ff= "/";
System.out.println (w+ "/" +m+ "=");
break;
}

}
}
Public double Ret1 ()
{
return W2;
}
Public double Ret2 ()
{
return m2;
}
Public String Ret3 ()
{
return FF;
}
}

In my elementary school system, this is my TDD.

Class yy
{
private int max=4;
private int min=1;
Private double w2,m2;
Private String FF;
Random random = new random ();

System.out.println (s);
Public yy ()
{
int s = random.nextint (max)% (max-min+1) + min;

Double x=random.nextint (max-2)% (max-2-min+1) + min;
Double y=random.nextint (max-1)% (max-1-min+1) + min;
int y1up= (int) Math.pow (10,x);
int y1dn= (int) Math.pow (10,x-1);
int y2up= (int) Math.pow (10,y);
int y2dn= (int) Math.pow (10,y-1);
int x_y1=random.nextint (Y1UP)% (y1up-y1dn+1) + y1dn;
int x_y2=random.nextint (y2up)% (y2up-y2dn+1) + Y2dn;
Double w= (double) x_y1;
Double m= (double) x_y2;
This.w2=w;
This.m2=m;
Switch (s)
{
Case 1:
{
this.ff= "+";
System.out.println (w+ "+" +m+ "=");
break;
}
Case 2:
{
this.ff= "-";
System.out.println (w+ "-" +m+ "=");
break;
}
Case 3:
{
this.ff= "*";
SYSTEM.OUT.PRINTLN (w+ "*" +m+ "=");
break;
}
Case 4:
{
this.ff= "/";
System.out.println (w+ "/" +m+ "=");
break;
}

}
}
Public double Ret1 ()
{
return W2;
}
Public double Ret2 ()
{
return m2;
}
Public String Ret3 ()
{
return FF;
}
}

You can get two numbers and an arithmetic operator as long as you apply this class to the main program.

Teammate Huang http://www.cnblogs.com/zzhuzi/

Doing Business 5.2 TDD

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.