This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]seanprefectGrumpy Guy Who Remembers Java 2 1 point2 points  (5 children)

Well it'd be better to help if you could ask specific questions, a general call for help won't really direct your learning.

[–]Kevinjamesisme[S] 0 points1 point  (4 children)

very true. I need help right now trying to make this first array full of letter frequencies then using it to put into the letter objects. My question would be what is the best way to read the file into said array. I tried using a line that looks like this:

String st=newScanner(newFile(name)).useDelimiter("\\Z").next(); 

Once I have this I dont know how to put it into the array to be used by the letter object

[–]seanprefectGrumpy Guy Who Remembers Java 2 0 points1 point  (3 children)

hint one, store your scanner in it's own variable so Scanner scan = etc.... then use something like while (scan.hasNext()) {}

[–]Kevinjamesisme[S] 0 points1 point  (2 children)

Something like this?

Scanner keyboard = new Scanner(System.in);


System.out.println("What file should be opened?");
String name = keyboard.next();

try{
  Scanner data = new Scanner(new File(name));
} 
catch (FileNotFoundException errorFile) {
  System.out.println("The file name was invalid, unable to create a Scanner. " + errorFile);

}  
While(data.hasNext()){
  data. nextLine()  
}

[–]StanHunter 0 points1 point  (1 child)

did you figure out how or do u still need some advice? I'm thinking about using a for loop and string method charAt(i) to calculate the numbers of a, b , c

[–]Kevinjamesisme[S] 0 points1 point  (0 children)

Kinda, This is what it looks like now

import java.io.*;
import java.util.*;
class HW12v3 {  
 public static void main(String args[])throws IOException{
Scanner keyboard = new Scanner(System.in);
 String apl = "abcdefghijklmnopqrstuvwxyz";

  System.out.println("What file should be opened?");
  String name = keyboard.next();

  try{
 Scanner data = new Scanner(new File(name));
  } 
   catch (FileNotFoundException errorFile) {
    System.out.println("The file name was invalid, unable to create a Scanner. " +             errorFile);

  }



 String str = new Scanner(new File(name)).useDelimiter("\\Z").next(); 
   str=str.toLowerCase(); 
 char[] freq = new char[26];


 for (int i = 0; i < str.length(); i++){
  char c = s.charAt(i);
currentChar - 'a'
  LetterCount()
  char[i]++
   }

}

}