Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'ve been working on this all day and I don\'t even know where to begin. Everyt

ID: 3663575 • Letter: I

Question

I've been working on this all day and I don't even know where to begin. Everything provided in this code is supposed to stay the same, minus where it says //CODE. I can't figure out how to do anything with the longs. Someone please help. This is due soon and I dont know what to do.

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 (bonus), and remainder (bonus)). 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

/**
* VeryLargeInteger(VLI) is a class for arbitrary precision integer computation.abstract
*/
public class VeryLargeInteger{
   /**
   * Constructs a new VLI object from a long integer.
   * @param init initial value
   */
   VeryLargeInteger(long init){

//code
      
   }
   /**
   * Constructs a new VLI objects 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){
       //CODE
   }
   /**
   * Computers 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){
       //CODE
   }
   /** Computer 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){
       //CODE
   }
   /** Computer 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){
       //CODE
   }
   /** Computer 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){
       //CODE
   }
   /** Computer 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){
       //CODE
   }
   /**
   * Returns the textual representation of this VLI.
   * @result a string representing this VLI
   */
   String toString(){
       //CODE
   }
  
   public static void main(String[] args){
       long init = ;
      
   }
  
}

Explanation / Answer

This is not trivial. But you might want to consider that multiplication is just repeated addition and division is repeated subtraction. There are certainly more direct methods that are more efficient. And you can't use the BigInteger class for your assignment. But I assume you could use it to check the correctness of your own methods.

Java Code:

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

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

import java.util.ArrayList;

  

/**

VeryLargeInteger (VLI) is a class for arbitrary precision integer computation

*/

public class VeryLargeInteger {

    private int[] num1;

    private int[] num2;

    private int[] num3;

  

/**

Constructs a new VLI object from a long integer

*/

VeryLargeInteger(long) {

    VeryLargeInteger veryLargeInteger = new VeryLargeInteger();

    }

  

/**

Constructs a new VLI object from a String

*/

VeryLargeInteger(String) {

      

    }

  

/**

Computes this+other and returns the result in a new object

*/

VeryLargeInteger add(VeryLargeInteger other) {

    int carry = 0, pos = 0;

    while(pos<num1.size() && num2.size()) {

        int value = num2[pos] + num1[pos] + carry;

        num3[pos++] = value % base;

        carry = value / base;

    }

    // a couple extra whiles

    if (carry!=0) {

        num3[pos++] = carry;

    }

    }

  

/**

Computes thisother and returns the result in a new object

*/

VeryLargeInteger sub(VeryLargeInteger other) {

    /* YOUR CODE */

    }

  

/**

Computes thisother and returns the result in a new object

*/

VeryLargeInteger mul(VeryLargeInteger other) {

    /* YOUR CODE */

    }

  

/**

Computes this/other and returns the result in a new object

*/

VeryLargeInteger div(VeryLargeInteger other) {

    /* YOUR CODE */

    }

  

/**

Computes this%other and returns the result in a new object

*/

VeryLargeInteger mod(VeryLargeInteger other) {

    /* YOUR CODE */

    }

  

/**

Returns the textual representation of this VLI

*/

String toString() {

    /* YOUR CODE */

    }

  

/* YOUR CODE */

}

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

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

import java.util.ArrayList;

  

/**

VeryLargeInteger (VLI) is a class for arbitrary precision integer computation

*/

public class VeryLargeInteger {

    private int[] num1;

    private int[] num2;

    private int[] num3;

  

/**

Constructs a new VLI object from a long integer

*/

VeryLargeInteger(long) {

    VeryLargeInteger veryLargeInteger = new VeryLargeInteger();

    }

  

/**

Constructs a new VLI object from a String

*/

VeryLargeInteger(String) {

      

    }

  

/**

Computes this+other and returns the result in a new object

*/

VeryLargeInteger add(VeryLargeInteger other) {

    int carry = 0, pos = 0;

    while(pos<num1.size() && num2.size()) {

        int value = num2[pos] + num1[pos] + carry;

        num3[pos++] = value % base;

        carry = value / base;

    }

    // a couple extra whiles

    if (carry!=0) {

        num3[pos++] = carry;

    }

    }

  

/**

Computes thisother and returns the result in a new object

*/

VeryLargeInteger sub(VeryLargeInteger other) {

    /* YOUR CODE */

    }

  

/**

Computes thisother and returns the result in a new object

*/

VeryLargeInteger mul(VeryLargeInteger other) {

    /* YOUR CODE */

    }

  

/**

Computes this/other and returns the result in a new object

*/

VeryLargeInteger div(VeryLargeInteger other) {

    /* YOUR CODE */

    }

  

/**

Computes this%other and returns the result in a new object

*/

VeryLargeInteger mod(VeryLargeInteger other) {

    /* YOUR CODE */

    }

  

/**

Returns the textual representation of this VLI

*/

String toString() {

    /* YOUR CODE */

    }

  

/* YOUR CODE */

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote