面向对象的编程。任务

时间:2014-09-23 22:59:46

标签: java

我正在努力完成一项任务。但我不知道我怎么能开始。我想简单解释一下任务条件。非常感谢您的支持。这是任务条件:

创建类HugeInteger - 它使用40个数字的数字数组来存储大小为40位的整数。提供方法解析,toString,加减。方法解析应该接收一个String,使用方法charAt提取每个数字,并将每个数字的等价整数放入整数数组。

1 个答案:

答案 0 :(得分:0)

你可以从这样的事情开始

public class HugeInteger {

    private int[] value;

    private HugeInteger(String s) {
        super();
        parse(s);
    }

    public void parse(String s) {
        //read s and check if it's a valid array of x<=40 digits
    }

    public String toString() {
        //return the contents of int[] value as a readable String
        return null;
    }

    public HugeInteger add(HugeInteger hi) {
        //return the sum of this object and hi
        return null;
    }

    public HugeInteger subtract(HugeInteger hi) {
        //return the difference between this object and hi
        return null;
    }

    public static void main(String[] args) {
        // don't forget to deal with overflows and underflows

        HugeInteger hi = new HugeInteger("10000");
        HugeInteger hi2 = hi.add(new HugeInteger("-10000"));
        System.out.println(hi2.toString()); //expected 0


    }

}