Java代写:CS206 Very Large Integer

Introduction

代写一个小Lab作业,考察基本OOP概念,题目是比较经典的大数算法。由于Int,Long等类型总有最大上限,当一个数超过这个上限时,需要编程处理这类大数的加减乘除运算。

Objectives: abstract data type (ADT), encapsulation

Integer types are very convenient, but their limited width makes them unsuitable for some applications where precise large values are more important than speed. Develop a class VeryLargeInteger that can handle arbitrary long integer numbers (both negative and positive) and the basic arithmetic operations (addition, subtraction, multiplication, division, and remainder).

Hint: The number could be represented as string, the sign could be represented either as boolean or as part of the string.

Note: Implementations of addition/subtraction through repeated use of a constant increment/decrement will not be accepted. Implementations of multiplication and division that rely on stepwise addition or subtraction will not be accepted.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* VeryLargeInteger (VLI) is a class for arbitrary precision integer computation.
*/

public class VeryLargeInteger {
/**
* Constructs a new VLI object from a long integer.
* @param init initial value
*/

VeryLargeInteger(long init) { /* YOUR CODE */ }
/**
* Constructs a new VLI object from a String.
* @param init initial value. Note, the string represents a valid VLI, but can
* be prefixed with a sign (either + or -).
*/

VeryLargeInteger(String init) { /* YOUR CODE */ }
/**
* Computes this+other and returns the result in a new object.
* @param other the left-hand side operand.
* @return a new VLI representing this+other
*/

VeryLargeInteger add(VeryLargeInteger other) { /* YOUR CODE */ }
/**
* Computes this-other and returns the result in a new object.
* @param other the left-hand side operand.
* @return a new VLI representing this-other
*/

VeryLargeInteger sub(VeryLargeInteger other) { /* YOUR CODE */ }
/**
* Computes this*other and returns the result in a new object.
* @param other the left-hand side operand.
* @return a new VLI representing this*other
*/

VeryLargeInteger mul(VeryLargeInteger other) { /* YOUR CODE */ }
/**
* Computes this/other and returns the result in a new object.
* @param other the left-hand side operand.
* @return a new VLI representing this/other
*/

VeryLargeInteger div(VeryLargeInteger other) { /* YOUR CODE */ }
/**
* Computes this%other and returns the result in a new object.
* @param other the left-hand side operand.
* @return a new VLI representing this%other
*/

VeryLargeInteger mod(VeryLargeInteger other) { /* YOUR CODE */ }
/**
* Returns the textual representation of this VLI.
* @result a string representing this VLI
*/

String toString() { /* YOUR CODE */ }
/* YOUR CODE */
}

Turn in a zip file named blazerid hw1.zip. The file should contain an exported Eclipse project with the following items.

  • All files needed to compile and run your solution.
  • Your tests (test driver needs to be a separate file).
  • A document (or text file) that describes your design decisions, your tests, any difficulties you had. If you would like to get a graded version on paper, add a note at the top of the report saying “paper copy requested”. If you received help from somebody else in class, please give credit to them.

Grading

  • (10pts) Lab
  • (10pts) Assignment report.
  • (10pts) Turned in code compiles without error or warning and code is well documented (consider using -Xlint:all and/or checkStyle).
  • (10pts) Quality of test design.
  • (10pts) Constructors, addition, subtraction, multiplication, and toString work correctly.
  • (10pts) Division and remainder methods operations correctly.