CS206 Very Large Integer
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
CS206 Very Large Integer
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 * VeryLargeInteger (VLI) is a class for arbitrary precision integer computation.
3 */
4 public class VeryLargeInteger {
5 /**
6 * Constructs a new VLI object from a long integer.
7 * @param init initial value
8 */
9 VeryLargeInteger(long init) { /* YOUR CODE */ }
10 /**
11 * Constructs a new VLI object from a String.
12 * @param init initial value. Note, the string represents a valid VLI, but can
13 * be prefixed with a sign (either + or -).
14 */
15 VeryLargeInteger(String init) { /* YOUR CODE */ }
16 /**
17 * Computes this+other and returns the result in a new object.
18 * @param other the left-hand side operand.
19 * @return a new VLI representing this+other
20 */
21 VeryLargeInteger add(VeryLargeInteger other) { /* YOUR CODE */ }
22 /**
23 * Computes this-other and returns the result in a new object.
24 * @param other the left-hand side operand.
25 * @return a new VLI representing this-other
26 */
27 VeryLargeInteger sub(VeryLargeInteger other) { /* YOUR CODE */ }
28 /**
29 * Computes this*other and returns the result in a new object.
30 * @param other the left-hand side operand.
31 * @return a new VLI representing this*other
32 */
33 VeryLargeInteger mul(VeryLargeInteger other) { /* YOUR CODE */ }
34 /**
35 * Computes this/other and returns the result in a new object.
36 * @param other the left-hand side operand.
37 * @return a new VLI representing this/other
38 */
39 VeryLargeInteger div(VeryLargeInteger other) { /* YOUR CODE */ }
40 /**
41 * Computes this%other and returns the result in a new object.
42 * @param other the left-hand side operand.
43 * @return a new VLI representing this%other
44 */
45 VeryLargeInteger mod(VeryLargeInteger other) { /* YOUR CODE */ }
46 /**
47 * Returns the textual representation of this VLI.
48 * @result a string representing this VLI
49 */
50 String toString() { /* YOUR CODE */ }
51 /* YOUR CODE */
52 }
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.
2026-02-09