import java.io.*; public class UseLetterQueue { public static void lettersShortRecipient(LetterQueue q, int len, String f) { try { PrintWriter fileout = new PrintWriter(f); // this thing works exactly like System.out // just that what you print in it will end // in file f instead of the terminal int list[] = q.shortLetters(len); // this call will return an array of letter // indices // now for each index in list[], I will call q.letter(..) to get the message // and then print the message to my PrintWriter fileout int i; for (i = 0; i < list.length; i++) { String msg = q.letter(list[i]); fileout.println(msg); } fileout.close(); } catch (Exception e) { System.out.println("something's wrong"); } } public static void main(String a[]) { try { LetterQueue q = new LetterQueue("Bolzano", 100); q.newLetter("Bersan: hello!"); q.newLetter("Foruzan: dont know and dont know why"); q.newLetter("Shogofa: bolzano is a green city and it is very cold!"); q.newLetter("Lecha: let's party like there was no today :-)"); q.newLetter("Khuseyn: good bye"); q.newLetter("Albert: big mountains big seas"); lettersShortRecipient(q, 20, "shortmessages.txt"); } catch (Exception e) { System.out.println("got an exception while calling my letter methods..."); } } }