Session 19 v2
Session19.java
import java.io.*;
import java.util.*;
public class Session19 {
public static void main(String[] args) throws IOException {
System.out.println("Session 19");
// Menu
System.out.println("Menu");
System.out.println("E1 - Example 1");
System.out.println("Q - Quit");
// setup Scanner
Scanner in = new Scanner(System.in);
System.out.print("Choice: ");
String choice = in.nextLine();
// switch choices
switch (choice) {
case "E1":
System.out.println("Example 1");
example1();
break;
case "E2":
System.out.println("Example 2");
example2();
break;
case "E3":
System.out.println("Example 3");
example3();
break;
case "E4":
System.out.println("Example 4");
example4();
break;
case "E5":
System.out.println("Example 5");
example5();
break;
case "E6":
System.out.println("Example 6");
example6();
break;
case "E7":
System.out.println("Example 7");
example7();
break;
case "E8":
System.out.println("Example 8");
example8();
break;
case "E9":
System.out.println("Example 9");
example9();
break;
case "E10":
System.out.println("Example 10");
example10();
break;
case "Q":
System.out.println("Quitting..!");
break;
}
}
// example1 method
public static void example1() {
// Create a File object that represents the file data1.txt
// Declare a Scanner variable and set it to null for now
// Create a Scanner that reads from the file
// Read and display the first word in the file
// Read and display the second word in the file
// This block runs if Java cannot find the file
// close file
}
// example2 method
public static void example2() {
// Create a File object for the file named data2.txt
// Declare a Scanner variable and set it to null for now
// Create an array that can store 4 color names
// Keep track of the current position in the array
// Create a Scanner that reads from the file
// Keep reading words from the file until there are no more words
// Store the next word from the file into the array
// Move to the next index in the array
// This block runs if Java cannot find the file
// Close the Scanner after reading the file
// Loop through the array and print each color
}
// example3 method
public static void example3() {
// Create a File object for the file named data3.txt
// Declare a Scanner variable and set it to null for now
// Create a Scanner that reads from the file
// Keep reading words from the file until there are no more words
// Close the Scanner after reading the file
}
// example4 method
public static void example4() throws IOException {
}
// example5 method
public static void example5() {
}
// example6 method
public static void example6() {
}
// example7 method
public static void example7() {
}
// example8 method
public static void example8() {
}
// example9 method
public static void example9() {
}
// example10 method
public static void example10() {
}
}
data3.txt
data4.txt
data5.txt
S19Problem1.java
problem1.txt
S19Problem2.java
problem2.txt
S19Problem3.java
problem3.txt
S19Problem4.java
problem4.txt
S19Problem5.java
problem5.txt
S19Problem6.java
S19Problem7.java
S19Problem8.java
Last updated
Was this helpful?