/* * Basic. One class, one main method, one other static method. No arrays. * Read in the words in the text file * 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 AhoyCaptain3; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; public class AhoyCaptain3 { public static void main(String[]arggs){ readFile(); } // end main private static void readFile() { String theWord = null; int size = 0; try { Scanner scFile = new Scanner(new File("ahoy.txt")); while (scFile.hasNext()) { String line = scFile.nextLine(); // Only one word per line theWord = line; theWord = theWord.toLowerCase(); if(theWord.startsWith("a") || theWord.startsWith("e") ||theWord.startsWith("i") ||theWord.startsWith("o") ||theWord.startsWith("u")) { System.out.println("Ahoy Captain. There is an " + theWord + " off the port bow."); } else { System.out.println("Ahoy Captain. There is a " + theWord + " off the port bow."); } size++; } // end while } catch (FileNotFoundException ex) { Logger.getLogger(AhoyCaptain3.class.getName()).log(Level.SEVERE, null, ex); } } // end readFile }