d1 = d1 - d2;
}else if(operator.equals("*")){
d1 = d1 * d2;
}else {
d1 = d1 / d2;
}
t1.setText(d1+"");//显示计算结果
append = false;
}
else if(".".equals(comm))//若是.号继续按
{
String temp = t1.getText();
if(temp.indexOf(".")==-1){
t1.setText(temp+".");
append = true;
}
}
}
}
java课程设计“小学算术运算测试程序”花了好几个小时,测试通过,希望楼主多给点分
import java.util.Scanner;
class Question{
private int firstParam;
private int secondParam;
private String operator;
private int answer;
private int score;
public int getFirstParam() {
return firstParam;
}
public void setFirstParam(int firstParam) {
this.firstParam = firstParam;
}
public int getSecondParam() {
return secondParam;
}
public void setSecondParam(int secondParam) {
this.secondParam = secondParam;
}
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
public int getAnswer() {
return answer;
}
public void setAnswer(int answer) {
this.answer = answer;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
//构造
public Question(int firstParam, int secondParam) {
this.firstParam = firstParam;
this.secondParam = secondParam;
}
}
public class StudentStudy {
private int questionNumber;
private String operator;
private Question[] questions;
private int rightNumber=0;
private int wrongNumber=0;
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
public int getQuestionNumber() {
return questionNumber;
}
public void setQuestionNumber(int questionNumber) {
this.questionNumber = questionNumber;
}
public int getRightNumber() {
return rightNumber;
}
public void setRightNumber(int rightNumber) {
this.rightNumber = rightNumber;
}
public int getWrongNumber() {
return wrongNumber;
}
public void setWrongNumber(int wrongNumber) {
this.wrongNumber = wrongNumber;
}
public Question[] getQuestions() {
return questions;
}
public void setQuestions(Question[] questions) {
this.questions = questions;
}
public int getRandom(){
return (int)(Math.random()*10);
}
public int calculateByOperator(String operator,int first,int second){
switch(operator.charAt(0)){
case '+':
return first+second;
case '-':
return first-second;
default:
return 0;
}
}
public void makeQuestion(){
mywhile:
while(questions[questionNumber-1]==null){
Question question=new Question(getRandom(),getRandom());
for(int i=0;questions[i]!=nulliquestionNumber;i++){
if((question.getFirstParam()==questions[i].getFirstParam())(question.getSecondParam()==questions[i].getSecondParam())){
continue mywhile;
}
}
for(int i=0;iquestionNumber;i++){
if(questions[i]==null){
questions[i]=question;
questions[i].setOperator(operator);
questions[i].setScore(100/questionNumber);
questions[i].setAnswer(calculateByOperator(operator,questions[i].getFirstParam(),questions[i].getSecondParam()));
break;
}
}
}
}
public StudentStudy(int questionNumber){
this.questionNumber=questionNumber;
questions=new Question[this.questionNumber];
}
public static void main(String[] args){
Scanner input=new Scanner(System.in);
推荐阅读
- 赛车街道赛叫什么游戏,赛车路段
- html5虚拟数字键盘,虚拟键盘数字键不能用
- 怎么取消电脑的局域网设置,怎么取消电脑的局域网设置方法
- 爱看直播设备,为什么爱直播不能用了
- java代码插入wps java读取wps建的excel
- javascript用处,javascript主要用来干嘛
- 为什么微信不能创建视频号,微信创建不了视频号
- linux下perl命令 linux中perl命令
- 如何理解建筑新媒体,新型建筑设计媒介技术