Midterm Exam

For this exam you will be writing two programs to solve two problems. Please put each program in its own project, and then send me the two compressed project folders as attachments to an email.

This is an open-book, open-note exam. You are welcome to consult the textbook or the course web site during this exam. You may also copy code from the examples posted on the course web site.

1. Write a program that can compute the average of a list of numbers stored in a file and then print all of those numbers from the file that are greater than the average. To do this, your program should open and close the file three times. On the first pass through the file you should count how many numbers are in the file. On the second pass through you should compute the average of the numbers in the file. On the third pass through the file you should print all of the numbers that are greater than the average.

You can assume that all of the numbers in the file you read are integers. You should assume that the file you are reading the numbers from is named "numbers.txt".

(If you need instructions on how to add a text file to a NetBeans project, those instructions are available here.)

2. Write the code for a method

public static int smallestDivisor(int n)

that can compute and return the smallest integer greater than 1 that divides evenly into n. Use this method in a program that prompts the user to enter a positive integer and then prints a list of the prime factors of that number. For example, if the user enters the number 64342 your program should print the list

2 53 607