Project 1: The Unit Converter

Due: Oct 4, 9:39:99 am. NO EXTENSION!

Important: Last modified Sep 25

Changes have been made on Converter interface. Be sure to get the new version before you begin to work! See below for detailed information about the new interface and extra credit!

You are to design a metric to english unit converter. Your program should convert miles to kilometers, quarts to liters, yards to meters and pounds to kilograms (and vice versa).

ONLY the following conversion factors should be used - variations will lead to differences in accuracy, resulting in a loss of points.


1 kilometre [km] = 0.6214 mile
1 pound [lb] = 0.4536 kg
1 quart = 0.946 liter
1 yard [yd] = 0.9144 m


Assignment

We will be doing automatic grading for part of your grade for all projects. This makes grading more fair for the students, and it makes it easier for us to grade all projects. Your project's functionality will be graded automatically, while your programming style as well as your readme will be graded by hand.

Because this is such a large class, and also for the automatic grading, there will be strict guidelines as to exactly what needs to be handed in, and how it should be handed in.

You will notice from the grading scale of this project (see bottom of page) that you get points for a readme, code style, and functionality of your program. The following describes each.

Assignment Submission Guidelines


Functionality Guidelines for Automatic Grading

Since we are using automatic grading to test the functionality of your program, it will need to conform to strict standards. Any deviation from these standards will result in it not working with the automatic grader as well as a substantial loss of points for you. For each project, you will get a list of specifications which your program must conform to EXACTLY. This will actually be good practice for you, since most software engineers use similar specs when coding a large project with many people involved. Consider yourself as writing a portion of a program (the project) which will fit into a bigger program (the automatic grading program). You will still need to make a stand-alone program to test your portion of the program, but in the end, you will need to submit a class (or group of classes) which will then be plugged into the automatic grader and then tested.

Part of the specification will be given to you in the form of a java interface. You will write a class which must implement this interface, which means that your class must at least have methods that match the ones in the interface definition (of course it can have more methods and variables as well). Because both the concepts of coding as PART of a program and using interfaces in java are probably new to a lot of you, we will be providing a testing environment for your code for this project only. This will let you test if your class implements the interface properly as well as give you an example of what the bigger program (the automatic grader) your code will be plugged into will look like.

You will be required to submit a class that will plug into the automatic grader. You will also be required to submit an application that demonstrates and tests the key functionality of your implementation.


Project specs


You can download both the interface files and the sample program here. You will need to unzip this file; it will automatically create a subdirectory named grader and the following files will be installed in your current directory:

LazyConverter.java
LazyConverter.class
grader/ClassFinder.class
grader/ClassFinder.java
grader/Converter.class
grader/Converter.java
grader/ConverterTest.class
grader/ConverterTest.java
grader/StudentSolution.class
grader/StudentSolution.java

The interface file you have to implement is Converter.java. You will have to create a class that implements this interface and write methods that correspond to the methods in this class. Notice also that Converter.java extends StudentSolution.java which has just 2 methods that will give us your name and email address. You will need to implement these methods in your derived class as well (note that you won't have to specifically put StudentSolution in your implements clause since it is inherited by Converter). If you don't implement all of these methods then Java will give you an error. Look inside the files Converter.java and StudentSolution.java to get more details of exactly what each method is supposed to do.

Since many of you will be new to interfaces, we have also provided a sample solution to the problem that implements the Converter interface, namely LazyConverter.java. It is not the right solution. It implements the program incorrectly. It is just there so you can get a feel for how to implement an interface. With the interface specs above, you also downloaded a test program called ConverterTest, which will allow you to test your Converter class. To use it, you will need to put all of your code for your class in the directory above the grader subdirectory. If you want to try it with LazyConverter, your installation directory should have LazyConverter.java, LazyConverter.class, and the subdirectory called grader. You can run the demo from your installation directory by using the following command:

    java grader/ConverterTest

This notation is there because the interfaces and the ConverterTest program are in a package called grader. You really don't need to understand packages to plug in your own assignment, though. Also, in case you have to recompile the grader package for some reason (you shouldn't because you should not change the code in grader, especially the interfaces) you just do javac grader/*.java.

A final note: DO NOT change the interface files (Converter.java and StudentSolution.java)! if you do so, your class will not be compatible with the automatic grader and you will get a very bad grade! You will only turn in the contents of your directory, nothing from the grader directory.


How to implement your own code


The simplest way is to keep the installation directory as your working directory. You can begin by rewriting the LazyConverter.java. Be sure to put your own class file into the installation directory (not the grader dir!) when you are ready to test. If there are multiple classes in the installation directory that implement the Converter interface, eg. LazyConverter.class and your own class, they will all be tested. You can always delete classes which you are not interested in testing. (Remember, you can always regenerate class files with javac <filename.java>)

If you don't put the test class in the installation directory, you may encounter a "No Converter Implementation Found" error.

Be aware the inputs of our final grading are not garuranteed to be the same as the inputs in the simple test. So do not just hard-code the correct answer of the test into your program.

Finally, turn in only ONE implementation of your converter. We wouldn't know which one to grade if you submit multiple implementations.



The Converter Interface

You must implement the Converter interface (Converter.java). This interface extends StudentSolution (StudentSolution.java). So in the end, your class will be required to implement a total of 10 methods (8 from Converter and 2 from StudentSolution). These are the methods with a description of what they need to do. Note that your method headers must look exactly like these. Any change to them will result in your program being incompatible with the automatic grader.

Note: The new version of Converter.java has yet another method named convert which is set for those who want to gain extra credit. You are NOT required to implement this one fully but you MUST at least provide an empty implementation for it. (You can just keep it as the one in LazyConverter.java.) Otherwise your program can not even pass the javac compilation! (If you still use the old version of Converter interface, you can pass the compilation but your program will meet difficulty in autograding!)

public String getName();
This method returns your name as it appears in the class roll.

public String getEmail();
This method returns the email address you would like your score sent to.

public double mile2kilometer(double miles);

This method should, given a distance in miles, return the equivalent in kilometers.

public double kilometer2mile(double kms);
This method should, given a distance in kilometers, return the equivalent in meters

public double pound2kilogram(double pounds);
public double kilogram2pound(double kgs);

public double quart2liter(double quarts);
public double liter2quart(double liters);

public double yard2meter(double yards);
public double meter2yard(double meters);

public double convert(String from, String to, double amount);
This method should, given the original unit, the original amount and the target unit, return the equivalent amount in target unit. You need to include at least an empty implementation in your program even you don't want to make it works and gain extra credit.

These may seem like very strict and very arbitrary, which they are, but it is unfortunately necessary to have strict guidelines in order to do automatic grading.

If you have any questions about anything, please ask a TA. There may be some ambiguities we have missed above.


GRADING :

Readme 10%

Code Style 10%

Functionality 80% (10% for each of the 8 implemented methods, excluding getName() and getEmail())

Extra Credit 10%
Implement convert method which combines the functionalities of the other eight conversion methods. The unit names we will use in autograding for this part would strictly include:

kilometer, mile, kilogram, pound, liter, quart, meter, yard

For example, the calling

convert("mile","kilometer",1.0)

acquires the equivalent in kilometers of 1 mile.


NOTE: 

Grading rules of thumb for "scrap code" : (Readme & boiler plate code is worth 20% total for project, Readme & Code that does not compile gets 30% total for project, Readme & code that compiles but does not run gets 40% total for project.)

NOTE : WE USE THE TURN IN SCRIPT - NO EXTENSIONS - ONE SECOND LATE IS TOO MUCH - YOU HAVE BEEN WARNED. DO NOT EMBARRASS YOURSELF BY ASKING FOR EXTENSIONS.