Third Job Calculator

Source: Internet
Author: User

Requirements Analysis: The user chooses the calculation type, then the software randomly generates the data, then the user gives the result of the operation, the calculation software to determine whether the correct, and the software at the end of the display of statistical results.

(1): Make a calculator window, add all the controls and operators to facilitate user input and calculation;

public static void Main (string[] args)
{
Frame frame = new Frame ("calculator");
Frame.setsize (300, 200);
Frame.setlocation (300, 200);
Frame.addwindowlistener (New Listener1 ());
Final TextField TF1 = new TextField (8);
Final Choice Choice = new Choice ();
Choice.additem ("+");
Choice.additem ("-");
Choice.additem ("*");
Choice.additem ("/");
Final TextField TF2 = new TextField (8);
Label label = new label ("=");
Final TextField tf3 = new TextField (8);
Button button = New button ("calculation");
Frame.add (TF1);
Frame.add (choice);
Frame.add (TF2);
Frame.add (label);
Frame.add (TF3);
Frame.add (button);
Frame.setlayout (New FlowLayout ());
Button.addactionlistener (New ActionListener ()

(2): Write an arithmetic formula

public void actionperformed (ActionEvent arg0)

{

String S1 = Tf1.gettext ();

String s2 = Tf2.gettext ();

String ch = choice.getselecteditem ();

Double D1 = double.parsedouble (S1);

Double D2 = double.parsedouble (S2);

Double d = 0; if (ch.equals ("+"))

{

d = d1 + d2;

} else if (Ch.equals ("-"))

{

D = d1-d2;

} else if (Ch.equals ("*"))

{

d = d1 * D2;

} else {

D = d1/d2;

}

Tf3.settext (D + "");

}

});

Frame.setvisible (TRUE);

}

}

(3): Finally added a timer, but did not run out;

Import java.io.IOException;

public class Timer {

public static void Main (String[]args)

{

Timer timer = new timer ();

Timer.schedule (New MyTask (), 1000,2000);

while (true)

{

try {

int ch = System.in.read ();

if (ch-' C ' ==0)

{

Timer.cancel ();

}

} catch (IOException e)

{

E.printstacktrace ();

}

}

}

private void Cancel () {

}

private void Schedule (MyTask mytask, int i, int j) {

}

}

Summary: Pair programming, different from a person programming, here to have two people's thinking, at first we are very confused, slow analysis, some ideas after the exchange of each other, so repeated,
Finally together the program to make, feel good labored ah, after all, limited capacity, can only do so ... This assignment took two mornings, but there was no good result, the heart had

Surplus and insufficient strength, the belly of the ink is too little.

Cooperation PICTURES:

Study No.: 1010

Name: Guobing Qian

Blog Name: Guobingqian

Blog Links: http://www.cnblogs.com/gbq0205

Pair PARTNER: Liu Yunjie

Third Job Calculator

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.