Programming Assignment 6


Due: Week of Feb. 27 before lab


  1. (25 points) Problem 12.7 of the book. NumberFormatException. Write the bin2Dec(String binaryString) method to convert a binary string into a decimal number. Implement the bin2Dec method to throw a NumberFormatException if the string is not a binary string. In main, allow a user to enter a binary string and test your method.
  2. (25 points) Based on problem 12.11 of the book. Remove text. Write a program that removes all occurrences of a specified string from a text file. You should take three inputs from the user, first an input filename, second a string to remove, and third an output filename to output the new text. You should assume the string to remove is a single word without spaces and that the input file only has occurrences of the string as whole words (as in it will not appear in the middle of a string).
  3. (25 points) Problem 12.19 of the book. Count words. Write a program that counts the number of words in President Abraham Lincoln's Gettysburg address.
  4. (25 points) Problem 12.21 of the book. Data sorted? Write a program that reads the strings from a file and reports whether the strings in the files are sorted in alphabetical order. If the strings are not sorted in the file, the program displays the first two strings that are out of order.
  5. Bonus. (10 points) Based on problem 12.25 of the book. Process large dataset. A university posts its employees' salaries here. Each line in the file consists of a faculty member's first name, last name, rank, and salary. Write a program that outputs a file named Summary.txt that contains the total salary for assistant professors, associate professors, full professors, and all faculty, respectively, and contains the average salary for assistant professors, associate professors, full professors, and all faculty, respectively.