You are on page 1of 3

CSCE A201, Fall 2017

Assignment 10
Due Thursday, 7 Dec 2017 at 10:00am on Blackboard
No late submissions allowed since I will discuss the solutions in class
30 points total

Complete the following programming problems using a separate class and file for each. For all programing
assignments, be sure to use good style and documentation. See the DocumetationAndStyle.pdf file on
Blackboard. For the programming assignments, style and documentation points are worth 10% of the point
total and are awarded independent of the correct functioning of your program. When complete, please zip your
NetBeans project directories together and upload to Blackboard.

1. (10 points) Recursively Find a File

A description of the File class is available here: http://docs.oracle.com/javase/8/docs/api/java/io/File.html. To


use it you must import java.io.File. For this program the relevant methods of the File class are described
below:

File(String The constructor takes a pathname and creates a File object corresponding to the file or
pathname) directory with that pathname.
String
Returns the pathname of the File object, e.g. C:\Papers\TermPaper.odt.
getAbsolutePath()
String getName() Returns the name of the File object, e.g. TermPaper.odt.
boolean isDirectory() Tests whether the File object is a directory.
If the File object is a directory then this returns an array of File objects corresponding
File[] listFiles()
to all the items within the directory.

Write a class with the static recursive method String searchForFile(File currentFolder,
String filename). The first parameter should be a File object that specifies the root folder to search for
the file named filename. The method should recursively search all subfolders for the file and return the
complete pathname to the first match. For example, if currentFolder is set to C:\Users\ and filename is
"names.txt" then it might return "C:\Code\Stuff\names.txt" if that is a valid pathname for the file. If there is
no file with a matching name within the currentFolder then the method should return a blank string, "".

For submission, have your program search for the name of your java program file, e.g. FileSearch.java starting
in C:\Users (assuming you are on a Windows machine). Note that it shouldnt take more than a minute to find
the file. Here is example output from my program including the execution time (NetBeans provides this):

Searching for "FileSearch.java" in C:\\Users


File found at C:\Users\witmer\Documents\NetBeansProjects\FileSearch\src\filesearch\FileSearch.java
BUILD SUCCESSFUL (total time: 8 seconds)
2. (10 points) Student Course List Report

You have a list of student IDs followed by the course number (separated by a space) that the student is
enrolled in. The listing is in no particular order. For example, if student 1 is in CS100 and CS200 while
student 2 is in CS105 and MATH210 then the list might look like this:

1 CS100
2 MATH210
2 CS105
1 CS200
Write a program that reads data in this format from the console. If the ID is -1 then stop inputting data. Use
the HashMap class to map from an Integer (the student ID) to an ArrayList of type String that holds each class
that the student is enrolled in. The declaration should look like this:

HashMap<Integer, ArrayList<String>> students = new HashMap<Integer, ArrayList<String>>();

After all data is input, iterate through the map and output the student ID and all classes stored in the vector for
that student. The result should be a list of classes organized by student ID. Here is example program output:

Enter student ID and class, -1 to stop:


1 CS100
2 MATH210
2 CS105
1 CS200
-1
Student Enrollment Report:
1 CS100 CS200
2 MATH210 CS105
3. (10 points) Lost Underground Adventure

Do you remember Zork or Hunt the Wumpus? Probably not, but no matter. Now you get to program your very
own text-based adventure game! Image you awaken in a maze of twisty little passages, all alike. Can you find
your way out? Here is a map of the maze:

You start in passage A. Passages can (possibly) go north, south, east, or west. For example, A can go east to C
or south to B, but is blocked to the west and north. From C you can go north to A, south to B, or east to D.
You escape the maze by making it to passage I. If you wander into passage F, that is the lair of the Wumpus,
and you will suffer a horrible fate.

Create a Passage class that has references to passages to the north, south, east, and west. Write a program with
instances of the Passage class that corresponds to the way passages are connected in the map (when you link
classes in such a manner it is called a graph). Add constructors, methods, variables, etc. as you deem
necessary.

Allow the user to input N, S, E, W to move in directions that are allowed. Stop if the user makes it to I. Your
final program should not output any of the passage letters. Here is a sample output:

You awaken in a maze of twisty little passages, all alike.


You can go: South East
S
You are in a maze of twisty little passages, all alike.
You can go: North South East
S
You are in a maze of twisty little passages, all alike.
You can go: North East West
E
You are in a maze of twisty little passages, all alike.
You can go: North East West
E
You made it out alive...this time!

You might also like