java课程设计算术运算测试
A. java编写算术运算测试
真是没啥好说的
B. java课程程序设计报告 课题:小学算术运算测试程序
这个你可找一个
简单计算器
就可以,能实现你的要求
C. JAVA学年课程设计题目:四则运算测试(求高人解答啊~~)
首先要明白Vector和ArrayList在使用上非常相似,都可用来表示一组数量可变的对象应用的集合,并且可以随机内地访问其中的容元素。
Vector的方法都是同步的(Synchronized),是线程安全的(thread-safe),而ArrayList的方法不是,由于线程的同步必然要影响性能,因此,ArrayList的性能比Vector好。
当Vector或ArrayList中的元素超过它的初始大小时,Vector会将它的容量翻倍,而ArrayList只增加50%的大小,这样,ArrayList就有利于节约内存空间。
所以这里用arraylist吧
应该是用来存储每道题的答案用,比如:
第一道题
int num1 = 1;
int num2 = 2;
int num3 = num1 + num2;
List nums = new ArrayList();
nums.add(num3); //将计算结果存入数组中
System.out.println(nums.get(0)); //取值
这只是思路,你借鉴下吧
D. JAVA 算术运算测试
importjava.util.Random;
importjava.util.Scanner;
publicclassTestRandom{
publicstaticvoidmain(String[]args){
Randomrand=newRandom();
Scannerinput=newScanner(System.in);
while(true){
inta=rand.nextInt(100);
intb=rand.nextInt(100);
intresult=a+b;
System.out.println(a+"+"+b+"=?");
intyourGuess=input.nextInt();
if(yourGuess==result){
System.out.println("youareright");
}else{
System.out.println("youarewrong");
}
}
}
}
E. JAVA课设小学算数运算测试程序报告中界面设计部分的详细设计与关键问
package demo;
import java.util.Scanner;
public class Test {
static Scanner sc = new Scanner(System.in);
public static boolean isNum(String str) {
boolean a = str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");
boolean b = str.matches("^[-+]?$");
return a && !b;
}
public static double input(int i) {
System.out.print("输入第" + i + "个数:");
String num = "";
do {
num = sc.next();
if (!isNum(num)) {
System.out.print("输入的不为数字,请重新输入:");
}
} while (!isNum(num));
return Double.parseDouble(num);
}
public static String input2() {
String operator = "";
boolean re;
System.out.print("输入运算符(+、-、*、/、^):");
do {
operator = sc.next();
re = operator.equals("+") || operator.equals("-") || operator.equals("*") || operator.equals("/")
|| operator.equals("^");
if (!re) {
System.out.print("请输入(+、-、*、/、^)中的一个:");
}
} while (!re);
return operator;
}
public static void main(String[] args) {
String judge = "";
do {
double n1 = input(1);
double n2 = input(2);
String result = "";
double res = 0;
String op = null;
op = input2();
switch (op) {
case "+":
res = n1 + n2;
break;
case "-":
res = n1 - n2;
break;
case "*":
res = n1 * n2;
break;
case "/":
if (n2 == 0) {
result = "除数不能为0";
} else {
res = n1 / n2;
}
break;
case "^":
res = Math.pow(n1, n2);
break;
}
if (result.isEmpty()) {
result = String.valueOf(res);
}
System.out.println("计算结果:" + n1 + op + n2 + "=" + result);
System.out.print("是否继续?(Y/任意退出)");
judge = sc.next();
} while (judge.equals("Y") || judge.equals("y"));
System.out.println("谢谢使用_(:зゝ∠)_");
}
}
F. 谁有java算术运算测试代码 100分
我有计算器的JAVA代码。。。
G. 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]!=null&&i<questionNumber;i++){
if((question.getFirstParam()==questions[i].getFirstParam())&&(question.getSecondParam()==questions[i].getSecondParam())){
continue mywhile;
}
}
for(int i=0;i<questionNumber;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);
System.out.println("现在开始测试,请填写要测试的试题数量(1-100):");
int number=input.nextInt();
StudentStudy ss=new StudentStudy(number);
System.out.println("请选择要测试的试题类型:1加法2减法");
int type=input.nextInt();
switch(type){
case 1:
ss.setOperator("+");
break;
case 2:
ss.setOperator("-");
break;
default:
System.out.println("输入有误,退出系统!");
System.exit(0);
}
ss.makeQuestion();
for(int i=0;i<number;i++){
System.out.println("第"+(i+1)+"题:"+ss.getQuestions()[i].getFirstParam()+ss.getQuestions()[i].getOperator()+ss.getQuestions()[i].getSecondParam()+"=?");
int answer=input.nextInt();
if(ss.getQuestions()[i].getAnswer()==answer){
ss.setRightNumber(ss.getRightNumber()+1);
System.out.println("回答正确!");
}
else{
ss.setWrongNumber(ss.getWrongNumber()+1);
System.out.println("回答错误!");
}
}
System.out.println("您总共答了"+ss.getQuestionNumber()+"道题,答对"+ss.getRightNumber()+"道,答错"+ss.getWrongNumber()+"道,最后总分为:"+ss.getRightNumber()*100/ss.getQuestionNumber()+"分");
}
}
H. 用java编写程序 课题:算术运算测试
你好,按照你的要求代码如下,可以直接运行
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class test {
public static void main(String[] args) {
int count = 0;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < 10; i++) {
int a = (int) (Math.random() * 100);
int b = (int) (Math.random() * 100);
int c = (int) (Math.random() * 2);
int r = 0;
switch (c) {
case 0:
if (a + b >= 100) {
a = 100 - b;
}
System.out.print(a + " + " + b + " = ");
r = a + b;
break;
case 1:
if (a < b) {
int t = a;
a = b;
b = t;
}
System.out.print(a + " - " + b + " = ");
r = a - b;
}
int input;
try {
input = Integer.valueOf(in.readLine());
} catch (Exception e1) {
System.out.println("答案错误\n");
continue;
}
if (input == r) {
count++;
System.out.println("答案正确\n");
} else {
System.out.println("答案错误\n");
}
}
if (null != in) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("答对数量:" + count + "\n得分: " + count * 10);
}
}
I. Java课程设计小学生算数测试程序APPLET版
明白算法就不难实现了。首先生成考题:十以内的两个数字随机组合,小学是没有负数的,0不能做除数等细节考虑到,生成后。学生输入答案,判断是否和执行结果一致就行了。applet只是java的一种呈现方式,核心算法都一样。如果还不清楚,可以到码源网联系客服定制开发 源码交易平台
J. 用Java设计一个小学算术运算测试软件
package com.amixuse.calcdemo;
import java.util.ArrayList;
import java.util.Random;
public class Calc {
public static void main(String[] args) {
computeString = new ComputeString();
for (int i = 0; i < 100; i++) {
System.out.print(computeString.getComputeString()
+ computeString.getComputeResult() + "\t");
if ((i + 11) % 10 == 0) {
System.out.println();
}
}
computeString.setMaxNumber(100);
for (int i = 0; i < 100; i++) {
System.out.print(computeString.getComputeString()
+ computeString.getComputeResult() + "\t");
if ((i + 11) % 10 == 0) {
System.out.println();
}
}
}
}
class ComputeString {
private char flag = '+';
private int maxNumber = 10;
private int num1 = 0;
private int num2 = 0;
public static Random random = new Random(System.currentTimeMillis());
private char[] flags = new char[] { '+', '-', '*', '/' };
public int getMaxNumber() {
return maxNumber;
}
public void setMaxNumber(int maxNumber) {
this.maxNumber = Math.abs(maxNumber);
}
public char getFlag() {
return flag;
}
public void setFlag(char flag) {
this.flag = flag;
}
public int getNum1() {
return num1;
}
public void setNum1(int num1) {
this.num1 = Math.abs(num1);
}
public int getNum2() {
return num2;
}
public void setNum2(int num2) {
this.num2 = Math.abs(num2);
}
/**
* 根据指定的运算符号生成指定的算术表达式
* */
public String getComputeString(char flag) {
setFlag(flag);
setNum1(Math.abs(random.nextInt(maxNumber)));
StringBuffer result = new StringBuffer();
result.append(num1).append(flag);
switch (flag) {
case '+':
if (getNum1() == maxNumber - 1) {
setNum2(0);
} else {
setNum2(random.nextInt(maxNumber - num1 - 1));
}
break;
case '-':
if (getNum1() == 0) {
setNum2(0);
} else {
setNum2(random.nextInt(getNum1()));
}
break;
case '*':
if (getNum1() == 0) {
setNum2(random.nextInt(maxNumber));
} else {
setNum2(maxNumber / getNum1());
}
break;
case '/':
int tmp = Integer.MAX_VALUE;
if (getNum1() == 0) {
while (true) {
tmp = Math.abs(maxNumber);
if (tmp != 0) {
setNum1(tmp);
break;
}
}
result.setLength(0);
result.append(num1).append(flag);
}
setNum2(getGongyuesu(getNum1()));
break;
}
result.append(num2).append("=");
return result.toString();
}
/**
* 随机生成运算符表达式
* */
public String getComputeString() {
setFlag(flags[random.nextInt(flags.length - 1)]);
return getComputeString(getFlag());
}
/**
* 产生最大公约数
*/
private int getGongyuesu(int number) {
ArrayList<Integer> result = new ArrayList<>();
int length = (int) Math.sqrt(number);
for (int i = 1; i <= length; i++) {
if (number % i == 0) {
result.add(new Integer(i));
}
}
int position = Math.abs(result.size());
position = position == result.size() ? position - 1 : position;
position = position <= 0 ? 0 : position;
return result.get(position);
}
/**
* 取得运算符结果
* */
public int getComputeResult() {
switch (flag) {
case '+':
return num1 + num2;
case '-':
return num1 - num2;
case '*':
return num1 * num2;
case '/':
return num1 / num2;
default:
return 0;
}
}
}
图形界面暂时没有弄。