学习任务:设计并实现大数类 BigNum
代码示例:
import java.util.Scanner;
public class BigNum {
private double num;
public BigNum(double c) {
num=c;
System.out.println("BigNum Constructorrun");
}
public void setNum(double c) {
num=c;
}
public final double getNum() {
return num;
}
public final void show() {
System.out.println("BigNum("+num+")");
}
public static void main(String[] args) {
double c1,c2;
String op;
System.out.println("请输入c1:");
Scanner sc=new Scanner(System.in);
c1=sc.nextDouble();
BigNum b1=new BigNum(c1);
BigNum b2=b1;
b1.show();
System.out.println("请输入c2:");
Scanner sc1=new Scanner(System.in);
c2=sc1.nextDouble();
b2.setNum(c2);
b2.show();
System.out.println("请输入op:");
Scanner sc2=new Scanner(System.in);
op=sc2.next();
if(op.equals("+")) {
BigNum b3=new BigNum(c1+c2);
b3.show();
}
if(op.equals("-")) {
BigNum b4=new BigNum(c1-c2);
b4.show();
}
}
}
运行截图:
明天任务:以点类 Point 及平面图形类 Plane 为基础设计三角形类 Triangle