/* * One class, one main method, one other static method. With an array. * Static global variables - no parameter passing * Read in the words in the text file into a one dimensional array * Using the words complete the given sentence correctly * "Ahoy Captain a ______ off the port bow." Words starting with a consonants * "Ahoy Captain an ______ off the port bow." Words starting with a vowel * There must be the same amount of sentences as there are words in the text file. */ package AhoyCaptain5; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; public class AhoyCaptain5 { // Global variables private static int size = 0; private static String[] wordArray = new String[20]; public static void main(String[]args){ readFile(); reportOutput(); } // end main private static void readFile() { size = 0; try { Scanner scFile = new Scanner(new File("ahoy.txt")); while (scFile.hasNext()) { String line = scFile.nextLine(); // Only one word per line line = line.toLowerCase(); wordArray[size] = line; size++; } // end while } catch (FileNotFoundException ex) { Logger.getLogger(AhoyCaptain5.class.getName()).log(Level.SEVERE, null, ex); } } // end readFile private static void reportOutput() { for(int i = 0; i < size; i++) { if(wordArray[i].startsWith("a") || wordArray[i].startsWith("e") ||wordArray[i].startsWith("i") ||wordArray[i].startsWith("o") ||wordArray[i].startsWith("u")) { System.out.println("Ahoy Captain. There is an " + wordArray[i] + " off the port bow."); } else { System.out.println("Ahoy Captain. There is a " + wordArray[i] + " off the port bow."); } } // end for loop } // end reportOutput }