# Lazarillo de Tormes and the Swindler

Topics: Addition, Integer, Multiplication Pages: 8 (779 words) Published: April 20, 2013
/*Class.Project 1*/
import java.util.StringTokenizer;
import java.io.*;
import java.math.BigDecimal;
import java.util.*;

/**
*
* @author: Huma UmmulBanin Zaidi
* @Project:Project1, Data Structure.
* Running program looks like:
This program finds sum or product of a LARGE numbers of integers. Enter as many integers > 0 as you would like.
Enter the numbers: 1 3 5 7
7 5 3 1
Please select the number of one of these options:
1. Sum the numbers in the list
2. Multiply the numbers in the list

Exiting program...
*/

public class Project1 {
//public class ReadFile { // Read lists of numbers from a specified text file. public static void main(String[] args){

if(args.length == 0) System.out.println("No file specified.");
else {
String oneLine;
int s;
try{ // file not found exception must be caught
theFile = new FileReader(args[0]);
inFile = new BufferedReader(theFile);
while((oneLine = inFile.readLine()) != null) {
String numbers[] = oneLine.split(","); // " " for space
s = 0;
for (int i=0; i<numbers.length; i++) s=s+Integer.parseInt(numbers[i]);
System.out.println(numbers.length + "numbers Processed. There Sum equals" +s+ ".");
} //end while
} // else
catch (Exception e) {System.out.println(e); }

System.out.println("Test");
BigDecimal n1 = new BigDecimal("123");
System.out.println(n1);
BigDecimal n2 = new BigDecimal ("345");
LargeNumbers a = new LargeNumbers(n1);
LargeNumbers b = new LargeNumbers(n2);
System.out.println(a.toString());
System.out.println(b.toString());

LargeNumbers.Multiply (LargeNumbers n);

}
}

}

/*class.LargeNumbers*/
import java.math.BigDecimal;

public class LargeNumbers
{
// chain off to a non-static method to avoid static errors

private int size;

//constructor
LargeNumbers(){
size = 0;
}

LargeNumbers(BigDecimal n){

head = new Node();
Node node = new Node();
BigDecimal d = new BigDecimal("1000");
while(n.compareTo(n.ZERO) >= 0 ){
Node cur = new Node();
cur.setData(Integer.valueOf(n.remainder(d).intValue()));
n = n.divide(d);
node.setpNext(cur);
node = node.getpNext();
}

}

public void mainLoop()
{
int numbers = 0; // Used to store numbers read in Node pHead = null; // head of linked list
Node pTemp; // used in new node creation

while( numbers != -1) {

if (numbers != -1) {
pTemp = new Node();
// Insert at head of list
pTemp.setData( numbers); // store the number pTemp.setpNext( pHead); // set the "pointer" pHead = pTemp; // reset the head of the list }

}//end while( number...

}//end of mainLoop

//}

public LargeNumbers AddNumbers (LargeNumbers n)
{
//public static void main(String[] args) {
//System.out.println("Addition of two numbers!");
LargeNumbers sum = new LargeNumbers();

int b = 0;
int a = 0;
int sum1 = a + b;
System.out.println("Sum: " + sum1);
//}
return sum;

}

public static void AddNumbers(LargeNumbers a, LargeNumbers b) {

int n1 = 0;
int n2 = 0;
int sum1 = n1 + n2;...

Please join StudyMode to read the full document