First, the topic
Please write a "software" that can automatically generate primary arithmetic topics.
Allow the program to accept the user to enter the answer, and determine the right and wrong.
Finally, the total number of pairs/errors is given.
Second, demand analysis
This program is suitable for elementary school students, exercise their computing ability. Practice the software.
Third, Basic Requirements
1. Display the number of questions
2, automatic display of the topic
3, the user can answer questions
4. Show right and wrong answers
5. Statistics on the number of errors
Iv. implementation of the Code
Import Java.util.Scanner;
public class Calculator {
public static int Suiji (int num1,int num2) {
int c= (int) num1+ (int) (Math.random () * (NUM2-NUM1));
return C;
}
public static void Main (string[] args) {
int s,a,b,i=1,f=0,h=0;
Double D;
while (i<=5) {
S=suiji (1,4);
i=i+1;
A=suiji (0,100);
B=suiji (0,100);
Switch (S) {
Case 1:
System.out.println (A + "+" +b+ "=");
Scanner reader=new Scanner (system.in);
D=reader.nextint ();
if (d==a+b) {
h++;
}
else{
System.out.println ("The Wrong answer is:" + (a+b));
}
Break
Case 2:
System.out.println (A + "*" +b+ "=");
Scanner reader1=new Scanner (system.in);
D=reader1.nextint ();
if (d==a*b) {
h++;
}
else{
System.out.println ("The Wrong answer is:" + (a*b));
}
Break
Case 3:
System.out.println (A + "-" +b+ "=");
Scanner reader2=new Scanner (system.in);
D=reader2.nextint ();
if (d==a-b) {
h++;
}
else{
System.out.println ("The Wrong answer is:" + (A-B));
}
Break
Case 4:
System.out.println (A + "/" +b+ "=");
Scanner reader3=new Scanner (system.in);
D=reader3.nextint ();
if (d==a/b) {
h++;
}
else{
System.out.println ("Wrong answer:" + (A/b));
}
Break
}
Continue
}
SYSTEM.OUT.PRINTLN ("You have correctly answered the" +h+ "question");
}
}
V: Running Result:
Vi. Analysis and summary
Software design is a continuous process, this process needs to have a rigorous concept and careful logical thinking, in the design of the program, the use of their familiar Java language relative to C + + easier, this would like to design a Java Swing GUI program, but due to time constraints, failed to carry out, Later use free time to try to write the program, in order to improve their programming ability!
Vii. PSP Statistics Table
Software Engineering--second assignment