//EDIT I\'ve got this mostly done. However it won\'t compile or give me correct
ID: 3663622 • Letter: #
Question
//EDIT
I've got this mostly done. However it won't compile or give me correct answers. Any ideas? This is due in an hour and a half.
package mngrae_assignment1;
import java.util.ArrayList;
import java.util.Scanner;
/**
* VeryLargeInteger(VLI) is a class for arbitrary precision integer computation.abstract
*/
public class VeryLargeInteger{
public int values[];
public String init;
/**
* 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){
int [] values = new int [init.length()];
for (int i=0; i < init.length(); i++){
values[i] = (int) init.charAt(i);
}
}
/**
* 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){
for (int i = 0; i < 1000; i++){
System.out.println(this.values[i] + values[i]);
}
}
/** 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){
for (int i = 0; i < 1000; i++){
System.out.println(this.values[i] - values[i]);
}
}
/** 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){
for (int i = 0; i < 1000; i++){
System.out.println(this.values[i] * values[i]);
}
}
/** 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){
for (int i = 0; i < 1000; i++){
System.out.println(this.values[i] / values[i]);
}
}
/** 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){
for (int i = 0; i < 1000; i++){
System.out.println(this.values[i] % values[i]);
}
}
/**
* Returns the textual representation of this VLI.
* @result a string representing this VLI
*/
public String toString(){
StringBuilder builder = new StringBuilder(init.length());
String [] theString = new String [init.length()];
for(int i = 0; i < init.length(); i++){
theString[i] = values[i];
}
return theString;
}
public static void main(String[] args){
final String init = args[0];
}
}
Explanation / Answer
When I add them I get:
instead of
This is a little messy.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.