Exercise 1: Coza Loza Woza

Write a class called CozaLozaWoza which prints the numbers 1 to 110, 11 numbers per line. The program shall print "Coza" in place of the numbers which are multiples of 3, "Loza" for multiples of 5, "Woza" for multiples of 7, "CozaLoza" for multiples of 3 and 5, and so on. The output shall look like:
1 2 Coza 4 Loza Coza Woza 8 Coza Loza 11 
Coza 13 Woza Coza Loza 16 17 Coza 19 Loza Coza Woza 22 
23 Coza Loza 26 Coza Woza 29 Coza Loza 31 32 Coza 
...
Note that when a number is divisible by both 3 and 5, such as 15, both Coza and Loza are printed. The same applies when a number is divisible by any of the other combinations.

Write a test class for your program and call the appropriate method(s) to get it to print the desired output.

See solution (CozaLozaWoza.java).

Exercise 2: Mulitiplications Table

Write a class called TimeTable to produce the multiplication table of 1 to 9 as shown:
 1  2  3  4  5  6  7  8  9
 2  4  6  8 10 12 14 16 18
 3  6  9 12 15 18 21 24 27
 4  8 12 16 20 24 28 32 36
 5 10 15 20 25 30 35 40 45
 6 12 18 24 30 36 42 48 54
 7 14 21 28 35 42 49 56 63
 8 16 24 32 40 48 56 64 72
 9 18 27 36 45 54 63 72 81

Write a test class for your program and call the appropriate method(s) to get it to print the desired output.

See solution (TimeTable.java).

Exercise 3: Text Processing

Complete the following program by counting the number of vowels in a word inside the method called procFile(). Write a test class for your program and call the appropriate method(s) to get it to print the desired output.

Note: This program reads words from a file using the Scanner class. You won't be tested on this part in this course. Recall that the Scanner constructor takes the location of where it should read input from and lets us process it. Previously, we used System.in to represent the keyboard input from users. Now, we give it a File object, so the text stored in that file is the location of where we will process the text from.

If you have the following text stored inside "textfile.txt":

Understanding the Patterns
there is
a
lot of
Common patterns in English 
to 
consider
What output will be printed? Trace through your loops and convince yourself the output makes sense.
import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import javax.swing.JPanel;

/**
 * class to reads in a text file and counts the number of vowels in it
 */
public class TextProcessing 
{
  String filename;
  Scanner fileScan;
  int numA, numE, numI, numO, numU;
  
  /**
   * constructor
   * when files are used, we have to handle specific exceptions (see next course)
   * @throws FileNotFoundException
   */
  public TextProcessing() throws FileNotFoundException
  {
    filename = "textfile.txt";
    File myFile = new File( filename );
    fileScan = new Scanner( myFile );
    numA = 0;
    numE = 0;
    numI = 0;
    numO = 0;
    numU = 0;
    System.out.println( "reading from: " + filename );
  }
  
  /**
   * counts the number of vowels in all the words in a file
   * @param void
   * @return void
   */
  public void procFile()
  {
    // while there is still another token in the file
    while( fileScan.hasNext() )
    {
      String oneWord = fileScan.next();

      // count how many vowels there are in oneWord, increment accordingly













      }
    }
  }
  
  /**
   * print out the counted vowels
   * @param void
   * @return void
   */
  public void prNumVowels()
  {
    System.out.println( "A\tE\tI\tO\tU" );
    System.out.println( numA + "\t" + numE + "\t" + numI + "\t" + numO + "\t" + numU );
  }
}

See solution (procFile()).

Exercise 4: Using the GUI Template

(Optional) Following the examples from Tuesday's class, how would you change your program so that you get a window to pop up with output such as:

See solution (TextProcessing.java and TestTextProc.java).