当前位置: 代码迷 >> Java相关 >> APPLET小程序
  详细解决方案

APPLET小程序

热度:195   发布时间:2006-09-13 15:52:22.0
APPLET小程序
编写一个APPlet程序测试用户是否掌握了基本的四则运算,每次用户点击按钮“问题”,都会生成一道两位的四则运算题(提示:从1到100中随机生成两个随机数作为两个操作数,从加减乘除四个运算中随机生成一个作为操作符)。并请用户回答,判断是否正确并通知用户。
搜索更多相关的解决方案: APPLET  

----------------解决方案--------------------------------------------------------

请教!


----------------解决方案--------------------------------------------------------

我以前写过一个不是Applet的四则运算 的。给你参考下,希望 对你有帮助,你只要把他改成Applet的就可以了
//主文件,保存为ceshi.java
//产生随机的四则运算题目,输入答案,判断正误
import java.util.*;
import java.io.*;
class suanshi{
//产生随机数//
Random rand=new Random();
//int a=(int)Math.random()*50;
//int b=(int)Math.random()*20;//这样的数每次运行时都是一样的.
//int c=(int)Math.random()*10+1;
//rand.setSeed(long d);
int a=(int)rand.nextInt()/1000000;
int b=(int)rand.nextInt()/1000000;
int c=(int)(rand.nextFloat()*10+1);
public static double sum=0;//一定要声明为static的,否则后面的SUM就会为0
public suanshi(){}
char d;
public suanshi(int k){ //产生运算符号//
if(1<=c&&c<=3){
d='+';
sum=a+b;
}
else
if(4<=c&&c<=6){
d='-';
sum=a-b;
}
else
if(7<=c&&c<=8){
d='×';
sum=a*b;
}
else {
d='÷';
sum=a/b;
}
System.out.print("("+a+")"+" "+d+" "+"("+b+")"+"=");

}
}

class panduan extends suanshi {
public static double count=0;
int result;
public static int fens=0;
panduan(){super(0);}
public int flag=0;
panduan(int i){
if(i==sum) {
//if(i==(a+b)) {
System.out.println("你答对了");
flag=1;
fens=fens+1;
count=count+1;
}
else {
System.out.println("你答错了"+"\n"+"不要放弃"+"\t");
System.out.println("正确答案应该是:"+sum);
flag=0;
// fens=fens-1;
count=count+1;
}
}
int f0(){
flag=0;
return flag;
}
int f1(){
flag=1;
return flag;
}
}
//主类开始//
public class ceshi extends panduan{
public int i=0;
String s="";
ceshi(){
try{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
s=in.readLine();
i=Integer.parseInt(s);
}catch(NumberFormatException e){System.out.println("您输入的数字有误");}
catch(IOException w){}
panduan p=new panduan(i);
}
//int fc(){return i;}
public static void main(String [] args) {
int j=0;
int tt=0;
String ss="";
System.out.println("这是四则运算题!");
System.out.println("***************");
System.out.println("第 "+(int)(count+1)+" 题");
do{
ceshi t=new ceshi();
//int pp=t.fc();
// t.panduan(pp);
try{ System.out.println("输入非1的数继续.输入1推出");

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
ss=in.readLine();
j=Integer.parseInt(ss);
}catch(NumberFormatException e){System.out.println("您输入的数字有误");}
catch(IOException w){}

switch(j){
case 0:
tt=t.f0();
System.out.println("==========================");
System.out.println("第 "+(int)(count+1)+" 题");break;
case 1:
tt=t.f1();
System.out.println("=%=%=%=%=%=%=%=%=%=%=%=%");
System.out.println("您共做的"+count+"题,"+"其中答对"+fens+"题");
System.out.println("你的总分为:"+(fens/count)*100);
System.out.println("下次再努力哦!"+"\n"+"谢谢使用,再见^_^!");
System.out.println("*********************");break;
}
}while(tt==0);
}
}


----------------解决方案--------------------------------------------------------
   好东西!
----------------解决方案--------------------------------------------------------
我个人觉得applet没什么用
----------------解决方案--------------------------------------------------------
楼上的什么话,Applet没什么用?用处可大了,要是没用,人家干嘛要去开发呀?
----------------解决方案--------------------------------------------------------

Applet以前可是风靡一时的!!


----------------解决方案--------------------------------------------------------
现在却少用武之地

----------------解决方案--------------------------------------------------------