Lab 4: Exceptionally Confusing

Due by the end of class

For this lab, you will not need to submit any code, although you will need to write a little. Each person has a secret code made up of three integers based on your user name. You will need to apply your knowledge of exceptions to figure out what your three number code is.

Specification

Create a project called Lab4. When you have worked with Java classes in the past (other than libraries), you have probably had the source .java file. In this lab, I will provide the compiled version of some classes (in .class files), but I will not provide their source code. If I did, finding your secret code would be trivial.

Keep it Classy

Using a .class file from the command line is easy, but using it with Eclipse is more painful. You will need to add these .class files to a folder used for libraries for the current Eclipse project.

To do so, right-click on the name of your project and select Properties from the bottom of the context menu. From the left pane of the Properties dialog, select Java Build Path. Once it is selected, make sure that the Libraries tab is the current tab. Then, click the Add Class Folder... button. A dialog with the title Class Folder Selection should pop up, with your current project selected. Click the Create New Folder... button to create a new folder inside your project. Name it what you like, but I recommend classes. Then, you should see a folder in your Project Explorer called classes (or whatever you selected) below the JRE System Library.

Now, download the following files.

Drag these files into the folder you created (or save them directly into your folder). This video also describes the process.

Finding the Code

The SecretCode class has a constructor that takes a String representing your user name. You can create such an object as follows.

SecretCode code = new SecretCode("wittman1"); // substitute your user name

Once you've created such an object, you can call its process() method, which looks like the following.

public void process(int a, int b, int c) {
	boolean check = false;
	try {
		boast(a);
		shock(b);
		polish(c);
		check = true;
	}
	catch(ConfusingException e) {
		System.out.println(e.getMessage());
	}
	catch(TooHighException e) {
		System.out.println("Too high!");
	}
	catch(TooLowException e) {
		System.out.println("Too Low!");
	}
	finally {
		if(check)
			System.out.format("You are correct: The code is %d %d %d.%n", a, b, c);
	}
}	

The boast(), shock(), and polish() methods have the following signatures.

private void boast(int a)
private void shock(int b) throws TooHighException, TooLowException
private void polish(int c) throws ConfusingException

By calling the process() method on the SecretCode object a number of times and deciphering the messages caused by exceptions thrown, you should be able to discover your own personal secret code.

Turn In

Create a file called code.txt. Type the three numbers that make up your secret code in this file and save it. Then, upload code.txt to Blackboard. Do not upload the entire project. I only want this text file, no Java source files

All work must be done individually. Never look at someone else's code. Please refer to the course policies if you have any questions about academic integrity. If you have trouble with the assignment, I am always available for assistance.