This homework has three problems.

A. Write a program that can process a file such as the following:

Campus President Salary Housing Auto Allowance
Bakersfield Horace Mitchell $285,000 $50,000 $12,000
Channel Island Richard R. Rush $275,000 $60,000 $12,000
Chico Paul J. Zingg $279,500 $50,000 $12,000
Dominguez Hills Mildred Garcia $295,000 provided $12,000
East Bay Mohammad H. Qayoumi $276,055 $60,000 $12,000
Fresno John Welty $299,000 provided $12,000
Fullerton Milton A. Gordon $295,000 provided $12,000
Humboldt Rollin C. Richmond $297,870 $50,000 $12,000
Long Beach F. King Alexander $320,329 provided $12,000
Los Angeles James Rosser $325,000 $60,000 $12,000
Maritime William B. Eisenhardt $258,680 provided $12,000
Monterey Bay Diane F. Harrison $270,315 provided $12,000
Northridge Jolene Koester $295,000 provided $12,000
Pomona J. Michael Ortiz $292,000 provided $12,000
Sacramento Alexander Gonzalez $295,000 $60,000 $12,000
San Bernardino Albert K. Karnig $290,000 $50,000 $12,000
San Diego Stephen L. Weber $299,435 provided $12,000
San Francisco Robert A. Corrigan $298,749 $60,000 $12,000
San Jose Don W. Kassing $328,209 provided $12,000
San Luis Obispo Jeffrey D. Armstrong $350,000 $60,000 $12,000
San Marcos Karen S. Haynes $270,568 $60,000 $12,000
Sonoma Ruben Arminaña $291,179 $60,000 $12,000
Stanislaus Hamid Shirvani $270,000 $50,000 $12,000

Each line contains the name of the campus, the president's name, and three figures (or the word provided). Your program will print the total compensation for each president, i.e.

Horace Mitchell $347,000
Richard R. Rush $347,000
 ...

It's a bit unfortunate that the campus names can have one or two parts and the president's names can have two or three. Use the following heuristic: Going backwards from the first dollar amount, take the two preceding words as the president's name, except if the first of these has the form X., where X is a single letter, or the one preceding it has the form X., in which case the name has three parts.

Your program should read the name of the file from the command line. If the file name is not present, print

File not found: (Name of file)

In the draft, just print the totals, not the names. For example,

$347,000
$347,000
 ...

Pay attention to those $ and commas. You need to remove them before turning the strings to numbers. To put the commas back in, use printf.

Your program will be tested by some file that is similar, but not identical to this one. For example, you should be able to process

New York City J. Pierpont Flathead $1,340,000 provided $12,000

And no, I don't know why they get a car allowance when the rest of us are expected to pay for our own cars. I guess life is just different at the top.

Visit this link and paste in your class. Submit Homework3A.java in the dropbox.

B. The Desire2Learn program lets you import quiz questions, but the format is icky. Here is an example:

NewQuestion,MC
Title,"What does the following LinkedList code print?"
QuestionText,"Consider the following code snippet:

LinkedList<String> words = new LinkedList<String>();
words.addFirst(""abc"");
words.addLast(""def"");
words.addFirst(""ghi"");
System.out.print(words.removeLast());
System.out.print(words.removeFirst());
System.out.print(words.removeLast());

What will this code print when it is executed?"
Points,1
Difficulty,1
Option,0,"abcdefghi"
Option,0,"ghiabcdef"
Option,0,"abcghidef"
Option,100,"defghiabc"

That's not what a quiz author wants to write. Here is a more author-friendly format:

What does the following LinkedList code print?
Consider the following code snippet:

LinkedList<String> words = new LinkedList<String>();
words.addFirst("abc");
words.addLast("def");
words.addFirst("ghi");
System.out.print(words.removeLast());
System.out.print(words.removeFirst());
System.out.print(words.removeLast());

What will this code print when it is executed?
A) abcdefghi
B) ghiabcdef
C) abcghidef
*D) defghiabc

Your task is to write  a program that reads a question in author-friendly format and writes it out in D2L format. Note the following:

The input file name is specified on the command line.

Your main method should throw a FileNotFoundException if the input file is not specified or not found, and an InputMismatchException if there is any error in the input format (i.e. no title, or the last four lines not A) B) C) D) with exactly one *)

Draft: Just print the title, with any quotation marks doubled, and throw the exceptions as indicated. For example, if your input file starts with What is wrong with this "Hello, World" program?, then you print

NewQuestion,MC
Title,"What is wrong with this ""Hello, World"" program?"

Visit this link and paste in your class. Submit Homework3B.java in the dropbox.

C. Write a program that reads a text file and prints the number of words and sentences in the file.               

A sentence ends in a period, exclamation mark, or question mark. But an ellipsis (...) is not the end of a sentence, so don't count

A word consists of only upper- and lowercase letters and apostrophes.

The input

"What's up?", he said. I didn't know--and don't think I was ever going to know...that's just how I am.

has 21 words and 3 sentences. This input has 29511 words and 1718 sentences.

In your solution, read a character at a time:

      Scanner in = new Scanner(System.in, "UTF-8");
      in.useDelimiter("");
      while (in.hasNext())
      {
         char ch = in.next().charAt(0);
         ...
      }
      ...
      System.out.println("Words: " + words);
      System.out.println("Sentences: " + sentences);

Your program should read from System.in.

Draft: Print the number of words.

Visit this link and paste in your class. Submit Homework3C.java in the dropbox.