This project is the final exam for this course. In this project, you will improve the design of some existing code. Your new code must be far less brittle and be easy to maintain and extend. Keep in mind that this is a FINAL EXAM. As such, you must work alone and you may not communicate with anyone else about this project. You may only use the following resources: - Me (Kyle Burke),
- The course lecture notes,
- Dale Skrien's text book,
- Your notes from class,
- Code from your projects (that you or your teammates wrote; you can't use outside packages for this) and
- The Java SE API.
You may not use any other physical or electronic sources (e.g. Stack Overflow). Ignoring this restriction will cause you to earn a zero on the project and may result in an academic honor code violation. If you think there's another resource that you should be able to use, ask me first! If you proceed without asking, you are running the risk of getting a zero on this project!Part 0, 0 points: Start by reading chapters 6 and 8 of the text book. This will be extremely insightful with regards to improving this code. Specifically, it shows the application of many design patterns to something that at first glance seems extremely simple.
Part 1, 0 points: For convenience, the code for this project is all in this repo.
Part 2, 0 points: Some friends of yours are software engineers at FastNCheapWare, and they dutifully put together some Java code to help manage geographical exploration: RiverDiscoverer.java. You mentioned to them that you are going to be holding an expedition soon, and they demanded that you give their code a whirl. You compiled it and tested it in the following way: (If there's a discrepancy between this and the testing code on GitHub, the testing code's version is the correct one!)
$ javac RiverDiscoverer.java
$ java RiverDiscoverer
You have found the mouth of a new river where it spills into the sea. What do the locals call this river?
Nile
How much water is flowing into the sea? (L/s)
2830000
How far did you walk until you reached the next junction? (in km)
3000
Are you done traveling upstream on the Nile? (y/N)
n
That means you must be at another confluence. What is the name the locals have given the river flowing into this one?
Atbarah River
How much water is flowing from that tributary into the main river? (L/s)
374000
How far did you walk until you reached the next junction? (in km)
400
Are you done traveling upstream on the Nile? (y/N)
n
That means you must be at another confluence. What is the name the locals have given the river flowing into this one?
White Nile
How much water is flowing from that tributary into the main river? (L/s)
878000
How far did you walk until you reached the next junction? (in km)
700
Are you done traveling upstream on the Nile? (y/N)
n
That means you must be at another confluence. What is the name the locals have given the river flowing into this one?
Dinder River
How much water is flowing from that tributary into the main river? (L/s)
112000
How far did you walk until you reached the next junction? (in km)
750
Are you done traveling upstream on the Nile? (y/N)
y
Great! We're done!
You have now explored the Nile!
The river is at least 4850 km long.
From the furthest distance we explored:
1466000 L/s flows 750 km downstream.
Then, the Dinder River flows into the river.
Then 1578000 L/s flows 700 km downstream.
Then, the White Nile flows into the river.
Then 2456000 L/s flows 400 km downstream.
Then, the Atbarah River flows into the river.
2830000 L/s flows 3000 km downstream.
Then the Nile flows into the sea.
$
(You can definitely try this out.) Part 3, 0 points: You are going to change the code so that you can explore tributaries. (This will be for BetterRiverDiscoverer.) After you're done updating the code, you want the I/O to look like this: (Again, if there's a discrepancy between this and the testing code on GitHub, the testing code's version is the correct one!)
$ javac *.java
$ java BetterRiverDiscoverer
You have found the mouth of a new river where it spills into the sea. What do the locals call this river?
Nile
How much water is flowing into the sea? (L/s)
2830000
How far did you walk until you reached the next junction? (in km)
3000
Are you done traveling upstream on the Nile? (y/N)
n
That means you must be at another confluence. What is the name the locals have given the river flowing into this one?
Atbarah River
How much water is flowing from that tributary into the main river? (L/s)
374000
Are you going to explore the tributary? (y/N)
n
Are you done traveling upstream on the Nile? (y/N)
n
How far did you walk until you reached the next junction? (in km)
400
Are you done traveling upstream on the Nile? (y/N)
n
That means you must be at another confluence. What is the name the locals have given the river flowing into this one?
White Nile
How much water is flowing from that tributary into the main river? (L/s)
878000
Are you going to explore the tributary? (y/N)
y
How far did you walk until you reached the next junction? (in km)
1200
Are you done traveling upstream on the White Nile? (y/N)
n
That means you must be at another confluence. What is the name the locals have given the river flowing into this one?
Sobat River
How much water is flowing from that tributary into the main river? (L/s)
412000
Are you going to explore the tributary? (y/N)
n
Are you done traveling upstream on the White Nile? (y/N)
n
How far did you walk until you reached the next junction? (in km)
200
Are you done traveling upstream on the White Nile? (y/N)
y
Finished exploring the White Nile.
Returning 1400 km back to the Nile...
Are you done traveling upstream on the Nile? (y/N)
n
How far did you walk until you reached the next junction? (in km)
700
Are you done traveling upstream on the Nile? (y/N)
n
That means you must be at another confluence. What is the name the locals have given the river flowing into this one?
Dinder River
How much water is flowing from that tributary into the main river? (L/s)
112000
Are you going to explore the tributary? (y/N)
n
Are you done traveling upstream on the Nile? (y/N)
n
How far did you walk until you reached the next junction? (in km)
750
Are you done traveling upstream on the Nile? (y/N)
y
Finished exploring the Nile.
Great! We're done!
Nile, at the furthest upstream we explored, dumps 1466000 L/s
This flows 750 km downstream.
Then, tributary:
Dinder River, at the furthest upstream we explored, dumps 112000 L/s
In total, we explored 0 km of the Dinder River.
The Nile now flows 1578000 L/s.
This flows 700 km downstream.
Then, tributary:
White Nile, at the furthest upstream we explored, dumps 466000 L/s
This flows 200 km downstream.
Then, tributary:
Sobat River, at the furthest upstream we explored, dumps 412000 L/s
In total, we explored 0 km of the Sobat River.
The White Nile now flows 878000 L/s.
This flows 1200 km downstream.
In total, we explored 1400 km of the White Nile.
The Nile now flows 2456000 L/s.
This flows 400 km downstream.
Then, tributary:
Atbarah River, at the furthest upstream we explored, dumps 374000 L/s
In total, we explored 0 km of the Atbarah River.
The Nile now flows 2830000 L/s.
This flows 3000 km downstream.
In total, we explored 4850 km of the Nile.
Then the Nile flows into the sea.
$
Part 4, 0 points: Two sections: You first take a look at at the RiverExplorer source code. After you fight back the resulting waves of nausea, you realize you should do this in two sections:
- First, update RiverDiscoverer.java so that the code is less brittle, but the functionality remains the same. This way, if your friend is getting nosy, you can show them that their code still runs.
- Second, use that cleaner code to create BetterRiverDiscoverer to handle the new functionality where you explore tributaries.
While you do all this, you realize it's going to be a really good idea to document what you do. You decide that this is going to be a learning experience, so you start a new text file, FinalExamNotes.txt, to keep some valuable notes as you go.Part 5, 25 points: Keeping Track - Refactoring: In those notes, list a refactoring you perform at any point. (Here's a list of refactorings you can use, and here's the Wikipedia entry, which might be more useful.) At some point you must have refactored some part of this. Tell me about it. (Only list your favorite.)
Part 6, 100 points: Keeping Track - Design Patterns: I want you to use at least two Object-Oriented design patterns in your project. Add to your text file (FinalExamNotes.txt) a list of all the design patterns you implemented, each with a list of all participants mapped to your class names. (50 points for each correct-and-fully-described pattern; -12.5 points for each incorrect or non-OO design pattern listed.) For example, if you use the Composite Pattern:
Composite Pattern:
- Component ----> Figure
- Leaf ----> Shape
- Composite ----> CompositeFigure
- Client ----> Painter
You can always add extra information, but be careful not to say anything incorrect!Part 7, 25 points: Improve the old code without changing the functionality of RiverDiscoverer. (So, don't explore the tributaries yet.) Think about what you want to accomplish (I recommend reading the other parts first) but make sure the old functionality is intact. (That way if you ever happen to explore with your FastNCheap friend, you can use RiverDiscoverer without making them sad.) The model will almost certainly become more complex, but it can make future changes easier. I am going to test that the old stuff still works (I'm going to run RiverDiscoverer) but will also check that it uses new code.
This can be a bit cumbersome to test, so you spend some time writing nice code to test the I/O. You save the guts in IOTester.java, with the specific code in InitialIOTest.java. (I did this for you.) Run InitialIOTest to test that everything's working.
Part 8, 75 points: When you are ready to add the exploring-tributary functionality, create BetterRiverDiscoverer.java
to handle the new stuff. Once it's ready, you can test the new functionality with the included FinalIOTest.java. (I'm obviously going to use a different river to test it, so you should probably add a second test too.)
Part 9, 0 points: Hints: I used the Composite Pattern to handle the joining of two rivers. (Component: River (abstract); Leaf: SingleRiver; Composite: Confluence.) I also see the potential for other patterns, including:
- State Pattern: to handle whether you're dealing with the new or old Discoverer
- Factory Pattern: To generate the actual river parts from the user input.
- Visitor Pattern: to explore the river and get the stats after it's been created.
- Null Object Pattern: to handle unexplored branches of the river.
- ... and there are other patterns that even I'm not familiar with!
Part 10, 25 points: Include the following integrity statement (but using your name) in your FinalExamNotes.txt file: "I, my-full-name, did not consult with anyone about the material for this exam except for Kyle. I did not use any resources aside from those listed on the final exam assignment. I understand that any breach of this agreement will result in a score of 0 on this exam and also involve administrative penalties."
Submitting your Project:
Create a folder named YourLastNameFinal (but using your last name) and add all of the following files to it:
- RiverDiscoverer.java
- BetterRiverDiscoverer.java
- Any other java source files needed to compile and run your code. (But not the testing files InitialIOTest.java, FinalIOTest.java, and IOTester.java; I've already got those.)
- FinalExamNotes.txt
Zip the folder into either a .zip or .tar.gz file (WinRar-compressed files (.rar) will not be accepted.) and upload it to the Moodle page for the final project.In order for me to grade your project, I need to be able to compile and run your code from the command line. Ensure that I can do the following:
YourLastNameFinal$ javac *.java
YourLastNameFinal$ java RiverDiscoverer
...
YourLastNameFinal$ java BetterRiverDiscoverer
...
If the compilation fails on my end, I cannot award you any points for the code.If you do not include one of the files, you will not earn points for those parts. If you don't include the FinalExamNotes.txt file or the integrity statement is incorrect or missing, you will earn zero points. If I cannot access the files inside your zipped folder, I cannot award you any points. If there is any other mistake in the submission process (e.g. not making a correctly-named folder before zipping) but I can still recover your files, 5 points will be deducted.