Skip to content

Commit

Permalink
Create Analysis.java
Browse files Browse the repository at this point in the history
  • Loading branch information
giusepped committed Aug 23, 2014
1 parent a1df9cf commit 662235f
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Week9/FileAnalysis/file/Analysis.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

package file;

/**
*
* @author giuseppedesantis
*/

import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;

public class Analysis {
private List<String> lines;

public Analysis(File file) throws Exception{
Scanner reader = null;
try{
reader = new Scanner(file);
}catch(Exception e){
System.out.println("we could not find the file");
return;
}
lines = new ArrayList<String>();

while(reader.hasNextLine()){
String line = reader.nextLine();
lines.add(line);
}
}

public int lines(){
int numberOfLines = 0;
for(String l : lines){
numberOfLines++;
}
return numberOfLines;
}

public int characters(){
int numberOfCharacters = 0;
for(String l : lines){
numberOfCharacters += l.length() + 1;

}
return numberOfCharacters;
}
}

0 comments on commit 662235f

Please sign in to comment.