2014-09-23 2 views
-4

하나의 작업을 위해 노력하고 있습니다. 하지만 어떻게 시작할 수 있을지 모르겠다. 나는 단순한 작업 조건에 대한 설명을 원한다. 많은 도움을 주셔서 감사합니다. 이것은 작업 조건입니다 :객체 지향 프로그래밍. 작업

클래스를 생성하십시오. 40 자리 요소 배열을 사용하여 각각 최대 40 자리의 정수를 저장하는 HugeInteger 클래스를 작성하십시오. 구문 분석, toString, 더하기 및 빼기 메소드를 제공하십시오. 메소드 구문 분석은 String을 받아야하며 charAt 메소드를 사용하여 각 숫자를 추출하고 각 숫자와 동일한 정수를 정수 배열에 배치해야합니다.

+0

같은 시작할 수 있습니다 : 공용 클래스 HugeInteger을. 제발,이 질문은 Java에 대한 지식이 전혀 없다는 것을 보여 주며 특정 문제를 진술하지 않습니다. 이 사이트에서 할 수있는 것과 할 수없는 것에 대한 지침은 Stack Overflow [도움말 파일] (http://stackoverflow.com/help)를 참조하십시오. – MarsAtomic

+1

수업을위한 교과서를 제공하지 않았습니까? – ajb

답변

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 


    } 

} 
+0

레오 감사합니다. 이 대답으로 나를 많이 도왔습니다. 다시 감사합니다. – user3747038