「java小学数学设计」小学数学设计方案
今天给各位分享java小学数学设计的知识,其中也会对小学数学设计方案进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、java课程设计“小学算术运算测试程序”
- 2、java课程设计Application和Applet两个版本猜数字游戏。邮箱992956686@qq.com
- 3、小学生算术计算两个三位数在相加时需要多少次进位 要求用java实现
- 4、自动生成50道数学题,每题为3个100以内的加减混合运算。用JAVA 怎么实现?
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);
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;inumber;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()+"分");
}
}
java课程设计Application和Applet两个版本猜数字游戏。邮箱992956686@qq.com
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*10以内计算题,根据输入生成题目个数
*
*/
public class T2013_6_21IN10 extends JFrame implements ActionListener{
JisuanPanel[] panels;
int n;
public T2013_6_21IN10(){
super("10以内计算题");
String inputValue = JOptionPane.showInputDialog("输入题目个数:");
try{
n=Integer.parseInt(inputValue);
}catch(Exception e){n=20;}
panels=new JisuanPanel[n];
for(int i=0;ipanels.length;i++)
panels[i]=new JisuanPanel();
Container c=getContentPane();
c.setLayout(new BorderLayout());
JPanel panel=new JPanel(new GridLayout(n/2+1,2));
for(int i=0;ipanels.length;i++)
panel.add(panels[i]);
c.add(new JScrollPane(panel),BorderLayout.CENTER);
panel=new JPanel(new FlowLayout());
JButton button=new JButton("评卷");
button.setActionCommand("JUDGE");
button.addActionListener(this);
panel.add(button);
button=new JButton("重新出题");
button.setActionCommand("RESET");
button.addActionListener(this);
panel.add(button);
c.add(panel,BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("RESET")){
for(int i=0;ipanels.length;i++)
panels[i].init();
}
if(e.getActionCommand().equals("JUDGE")){
int n=0;
for(int i=0;ipanels.length;i++){
if(panels[i].right())
n++;
}
JOptionPane.showMessageDialog(null,"一共"+this.n+"题,共做对"+n+"道!\n得分:"+(int)((((double)n)/this.n)*100));
}
return;
}
public static void main (String[] args) {
JFrame frame=new T2013_6_21IN10();
frame.setBounds(50,50,400,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class JisuanPanel extends JPanel{
JLabel label;
JTextField field;
int result;
public JisuanPanel(){
super();
label=new JLabel();
field=new JTextField(4);
add(label);
add(field);
init();
}
public void init(){
int a,b;
String fu;
a=(int)(Math.random()*10)+1;
b=(int)(Math.random()*10)+1;
switch((int)(Math.random()*2)){
case 0:fu="+";label.setText(""+a+fu+b+"=");result=a+b;break;
case 1:fu="-";label.setText(""+a+fu+b+"=");result=a-b;break;
//case 2:fu="*";label.setText(""+a+fu+b+"=");result=a*b;break;
//case 3:fu="/";label.setText(""+a+fu+b+"=");result=a/b;break;
default:JOptionPane.showMessageDialog(null,"出错!");System.exit(0);
}
if(result0||result10)
init();
field.setText("");
return;
}
public boolean right(){
if(field.getText().equals(""))return false;
int num=result+1;
try{
num=Integer.parseInt(field.getText());
}catch(NumberFormatException e){
JOptionPane.showMessageDialog(null,"输入错误!");
field.setText("");
}
if(num==result){
if(!(label.getText()).startsWith("√"))
label.setText("√"+label.getText());
return true;
}
else return false;
}
}
小学生算术计算两个三位数在相加时需要多少次进位 要求用java实现
ublic static void main(String[] args) {
plusR();
}
public static void plusR() {
Scanner scanner = new Scanner(System.in);
StringBuilder result = new StringBuilder();
String temp1; // 第一个数
String temp2; // 第二个数
char[] no1;
char[] no2;
int counts; // 统计进位次数
while (true) {
System.out.println("输入两个3位数\n第一个:");
temp1 = scanner.next();
if ("0".equals(temp1)) {
scanner.close();
break;
}
System.out.println("第二个:");
temp2 = scanner.next();
no1 = temp1.toCharArray();
no2 = temp2.toCharArray();
if (no1.length == 3 no2.length == 3) {
counts = 0;
for (int i = 0; i 3; i++) {
// System.out.print( no1[i] + no2[i] + "\t");
// ASCII 中 0 - 48 , 9 - 57
// 0 + 9 = 48 + 57 = 105
if (no1[i] + no2[i] 105) {
counts++;
}
}
result.append(counts).append("\n");
} else {
System.out.println("不是三位数!");
}
}
System.out.println("结果:" + result);
}
没做非数字验证
自动生成50道数学题,每题为3个100以内的加减混合运算。用JAVA 怎么实现?
用for循环50次,用random生成100内的三个随机数,随机组合成数学计算题就行了
java小学数学设计的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于小学数学设计方案、java小学数学设计的信息别忘了在本站进行查找喔。
发布于:2022-11-22,除非注明,否则均为
原创文章,转载请注明出处。