Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
367 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Add类为Randoms类的子类 | ||
* 该类中进行加法运算 | ||
*/ | ||
package cn.deu.ccut.two; | ||
|
||
public class Add { | ||
public void add(double number,double a,double b) { | ||
int c; | ||
int d; | ||
char opera[]= {' ','(',')'};//Opera[0]~Opera[2]依次输出“ (空格)”,“(”,“)” | ||
if(a>=0) { | ||
c=0; | ||
}else { | ||
c=1; | ||
} | ||
|
||
if(b>=0) { | ||
d=0; | ||
}else { | ||
d=1; | ||
} | ||
|
||
if(a+b<=number) { | ||
System.out.println(opera[c]+a+opera[c*2]+"+"+opera[d]+b+opera[d*2]+"="); | ||
|
||
}else { | ||
a=(int)a/2; | ||
b=(int)b/2; | ||
System.out.println(opera[c]+a+opera[c*2]+"+"+opera[d]+b+opera[d*2]+"="); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cn.deu.ccut.two; | ||
|
||
import java.util.Scanner; | ||
|
||
public class Chengchu { | ||
int a; | ||
public double chengchu() { | ||
Scanner sc=new Scanner(System.in); | ||
try { | ||
System.out.print("是否包含乘除运算,是按1,否按任意数字:"); | ||
a=sc.nextInt(); | ||
|
||
} catch (Exception e) { | ||
System.out.println("请输入正确的取值范围"); | ||
chengchu(); | ||
} | ||
|
||
return a; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Division类为Randoms类的子类 | ||
* 该类中进行除法运算 | ||
*/ | ||
package cn.deu.ccut.two; | ||
|
||
public class Division { | ||
public void division(double number,double a,double b) { | ||
int c; | ||
int d; | ||
char opera[]= {' ','(',')'};//Opera[0]~Opera[2]依次输出“ (空格)”,“(”,“)” | ||
if(a>=0) { | ||
c=0; | ||
}else { | ||
c=1; | ||
} | ||
if(b>=0) { | ||
d=0; | ||
}else { | ||
d=1; | ||
} | ||
|
||
if(a%b==0) { | ||
System.out.println(opera[c]+a+opera[c*2]+"/"+opera[d]+b+opera[d*2]+"="); | ||
}else { | ||
b=(int)(b/10); | ||
a=(int)(a%10); | ||
a=a*(b+1); | ||
System.out.println(opera[c]+a+opera[c*2]+"/"+opera[d]+b+opera[d*2]+"="); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Down类是Primary的子类 | ||
* 该类控制题目数量 | ||
*/ | ||
package cn.deu.ccut.two; | ||
import java.io.*; | ||
import java.util.*; | ||
public class Down { | ||
|
||
public double down() { | ||
double b = 0;//运算式的个数 | ||
Scanner sc=new Scanner(System.in); | ||
try { | ||
System.out.print("请输入题目的数量:"); | ||
b=sc.nextDouble();// 控制题目的数量 | ||
|
||
} catch (Exception e) { | ||
System.out.println("请输入正确的取值范围"); | ||
down(); | ||
} | ||
return b; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Factory为工厂类,是Randoms的子类 | ||
* 利用switch语句进行运算法则的选择 | ||
* switch(0)为加法; switch(1)为减法; switch(2)为乘法; switch(3)为除法; | ||
*/ | ||
package cn.deu.ccut.two; | ||
|
||
import java.util.Random; | ||
|
||
public class Factory extends Randoms{ | ||
Random rand =new Random(); | ||
public void factory(double max,double a,double b) { | ||
int i=0; | ||
switch(rand.nextInt(r)) { | ||
case 0: | ||
i++; | ||
Add ad=new Add(); | ||
ad.add(max,a,b); | ||
break; | ||
case 1: | ||
i++; | ||
Minus mis=new Minus(); | ||
mis.minus(max,a,b); | ||
break; | ||
case 2: | ||
i++; | ||
Multiply mul=new Multiply(); | ||
mul.multiply(max,a,b); | ||
break; | ||
case 3: | ||
i++; | ||
Division div=new Division(); | ||
div.division(max,a,b); | ||
break; | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cn.deu.ccut.two; | ||
|
||
import java.util.Scanner; | ||
|
||
public class Fuhao { | ||
int a; | ||
public double fuhao() { | ||
Scanner sc=new Scanner(System.in); | ||
try { | ||
System.out.print("是否包含负数,是按1,否按其他数字:"); | ||
a=sc.nextInt(); | ||
|
||
} catch (Exception e) { | ||
System.out.println("请输入正确的取值范围"); | ||
fuhao(); | ||
} | ||
|
||
return a; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Minus类为Randoms的子类 | ||
* 在该类中进行加法运算 | ||
*/ | ||
package cn.deu.ccut.two; | ||
|
||
public class Minus{ | ||
public void minus(double number,double a,double b) { | ||
int c; | ||
int d; | ||
char opera[]= {' ','(',')'};//Opera[0]~Opera[2]依次输出“ (空格)”,“(”,“)” | ||
if(a<0) { | ||
c=1; | ||
}else { | ||
c=0; | ||
} | ||
if(b<0) { | ||
d=1; | ||
}else { | ||
d=0; | ||
} | ||
if(a>b) { | ||
System.out.println(+opera[c]+a+opera[c*2]+"-"+opera[d]+b+opera[d*2]+"="); | ||
}else { | ||
System.out.println(+opera[c]+a+opera[c*2]+"-"+opera[d]+b+opera[d*2]+"="); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Multipiy类为Randoms类的子类 | ||
* 该类中进行乘法运算 | ||
*/ | ||
package cn.deu.ccut.two; | ||
|
||
public class Multiply { | ||
public void multiply(double number,double a,double b) { | ||
int c; | ||
int d; | ||
char opera[]= {' ','(',')'};//Opera[0]~Opera[2]依次输出“ (空格)”,“(”,“)” | ||
if(a>=0) { | ||
c=0; | ||
}else { | ||
c=1; | ||
} | ||
if(b>=0) { | ||
d=0; | ||
}else { | ||
d=1; | ||
} | ||
if(a*b<=number) { | ||
System.out.println(opera[c]+a+opera[c*2]+"*"+opera[d]+b+opera[d*2]+"="); | ||
}else { | ||
a=a%10; | ||
b=b%10; | ||
System.out.println(opera[c]+a+opera[c*2]+"*"+opera[d]+b+opera[d*2]+"="); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* PrimaryÀàÖÐ | ||
*/ | ||
|
||
package cn.deu.ccut.two; | ||
import java.awt.font.NumericShaper.Range; | ||
import java.util.Scanner; | ||
public class Primary { | ||
public static int scope1; | ||
public static int scope2; | ||
|
||
public static void main(String[] args) { | ||
Shut shu=new Shut(); | ||
shu.shut(); | ||
|
||
Down dow=new Down(); | ||
System.out.println(dow.down()); | ||
|
||
Rantwo rant=new Rantwo(); | ||
rant.rantwo(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Randoms类实现功能(1)————自动生成10道100以内的2个操作数的四则运算算式(+ - * /),要求运算结果也在100以内 | ||
* 在Randoms类中定义了两个成员变量a和b | ||
* 在ranDoms方法中调用工厂类——Factory中的factory方法实现功能(1) | ||
*/ | ||
package cn.deu.ccut.two; | ||
import java.util.Scanner; | ||
import java.util.Random; | ||
import java.io.FileNotFoundException; | ||
import java.io.PrintStream; | ||
|
||
import java.math.BigInteger; | ||
public class Randoms { | ||
|
||
static double number=100; | ||
static double b=10; | ||
static int t=0; | ||
static int r=4; | ||
static Random rand =new Random(); | ||
|
||
public static void main(String[] args) throws FileNotFoundException { | ||
PrintStream ps = new PrintStream("d:/result.txt"); | ||
Scanner sc=new Scanner(System.in); | ||
Fuhao fu=new Fuhao(); | ||
Chengchu che=new Chengchu(); | ||
|
||
ranDoms(); | ||
|
||
t= (int) fu.fuhao(); | ||
r=(int) che.chengchu(); | ||
if(r!=1) { | ||
r=2; | ||
}else { | ||
r=4; | ||
} | ||
Shut shu=new Shut(); | ||
number = shu.shut(); | ||
Down dow=new Down(); | ||
b=dow.down(); | ||
System.setOut(ps); | ||
ranDoms(); | ||
|
||
} | ||
public static void ranDoms(){ | ||
Scanner sc=new Scanner(System.in); | ||
for(int i=0;i<b;i++){ | ||
double a= rand.nextInt((int)number); | ||
double b= rand.nextInt((int)number); | ||
if(t==1) { | ||
a=((rand.nextInt(2))==1?-1:1)*a; | ||
b=((rand.nextInt(2))==1?-1:1)*b; | ||
} | ||
Factory fac=new Factory(); | ||
fac.factory(number,a,b); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Rantwo类是Primary类的子类 | ||
* 该类随机生成两个随机数组 | ||
*/ | ||
package cn.deu.ccut.two; | ||
|
||
public class Rantwo extends Primary { | ||
public void rantwo() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Shut类是Primary类的子类 | ||
* 该类控制输入的题目数值的取值范围 | ||
*/ | ||
|
||
package cn.deu.ccut.two; | ||
|
||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class Shut { | ||
|
||
static double shut() { | ||
Scanner sc=new Scanner(System.in); | ||
double a=0;//运算数的取值范围 | ||
|
||
try { | ||
System.out.print("请输入操作数的范围:"); | ||
a=sc.nextDouble();// 控制题目数值的取值范围 | ||
|
||
} catch (Exception e) { | ||
System.out.println("请输入正确的取值范围"); | ||
shut(); | ||
} | ||
return a; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* 创建Randoms类的对象ran,并利用ran对象调用Randoms函数中的ranDoms方法实现功能(1) | ||
* | ||
*/ | ||
package cn.deu.ccut.two; | ||
import java.util.Scanner; | ||
import java.io.FileNotFoundException; | ||
import java.io.PrintStream; | ||
import java.util.Random; | ||
public class Test { | ||
|
||
public static void main(String[] args) { | ||
Randoms rand=new Randoms(); | ||
rand.ranDoms(); | ||
|
||
|
||
} | ||
|
||
} |