My predicament of the day is a lack of correspondence between my file and my Scanner methods. The point of the code is to remove the "-" in the data file, then add the numbers after using the method useDelimiter.
Lab12C.Dat:
Lab12C:
Any help is greatly appreciated!
Lab12C.Dat:
Code:
7
22-11-22-11-22
1-2-3-4-5-6
90-100-90
1000-232
1-1-1-21-1-1-111-9999-1
9-9-9-9-9-9-9-9-9-9-9-9-9-9-9-9
1
Lab12C:
Code:
//Name -
//Date -
//Lab -
import java.io.IOException;
import java.io.File;
import java.util.Scanner;
import static java.lang.System.*;
class Social
{
private String socialNum;
private int sum;
public Social()
{
socialNum="";
sum = 0;
}
public Social(String soc)
{
socialNum = soc;
sum = 0;
}
public void setWord(String w)
{
socialNum=w;
setWord(w);
}
public void chopAndAdd()
{
Scanner g = new Scanner(socialNum);
for(int i = 0; i<socialNum.length(); i++)
{
socialNum.useDelimiter("-");
sum = sum+g.nextInt();
System.out.println(sum);
}
}
public String toString()
{
return "";
}
}
public class Lab12c
{
public static void main( String args[] ) throws IOException
{
Scanner file = new Scanner(new File("lab12c.dat"));
int size = file.nextInt();
file.nextLine();
for(int i=0; i<size; i++)
{
String line = file.nextLine();
Social test = new Social(line);
test.chopAndAdd();
System.out.println(test);
}
}
}
Any help is greatly appreciated!