I assigned it to a friend who was struggling with Java, and now I am thinking of making it public on my website.

Any suggestions?

http://rcs.hostoi.co...opexercise.html

Site is down but here's the assignment:

Spoiler

By succesfully completing this exercise you will:

-be introduced to Object Oriented Programming in Java

-understand the meaning of is a (inheritance), has (composition) and is (interface)

-learn to extend abstract classes and implement abstract methods

-learn when to implement the Comparable<T> interface

-learn how to write your own interface and understand why they're useful

-learn how to override parent class methods, namely the toString() method

-know when to throw errors and use assertions

1. A rational, or a fraction, is a number that has a numerator and a denominator. A rational is arithmetical, meaning all four operations can be performed on it.

Create a Rational class that extends Java's built-in abstract Number class, implements Java's built-in Comparable<T> interface, and implements your own user-defined Arithmetical<T> class.

Arithmetical<T> should declare four methods for addition, subtraction, multiplication and division.

What should you do if the user creates a Rational object with a 0 in the denominator?

Your class should also override the Java's Object class' toString() method to return a string representation of your Rational object.

Provide a default construtor with no parameters another constructor that takes as parameter only the numerator.

Create a method to simplify a Rational to lowest terms (i.e 1/2 instead of 3/6).

2. Create a Matrix class that also implements Arithmetical<T>. Answer this question: should Matrix also implement Comparable<T>? Hint: is a Matrix comparable to another?

Your Matrix class should be composed of a two dimensional array of Rational objects.

Provide getter and setter methods to return or to modify individual entries within the Matrix.

Matrix division is simply multiplication by the inverse. For the purpose of this exercise you may throw an error when the user calls the division method.

Remember that only matrices of the same dimensions can be added to or subtracted from one another. When can matrices multiply with one another? Handle the errors.

Override the toString() method to return a string of your Matrix object. Your implementation should make use of the toString() in the Rational class.

Provide methods to return the transpose and identity of your Matrix

Create a method that checks if two matrices are equal.

Create a method to find the determinant of a 2 x 2 matrix.

Create a method to find the inverse of a 2 x 2 matrix.

Advanced: find the determinant of a any square matrix (hint: recursion).

Advanced: create an algorithm to find the inverse of any square matrix.

3. Create a test client to demonstrate and test all functionalities of the project above.

-be introduced to Object Oriented Programming in Java

-understand the meaning of is a (inheritance), has (composition) and is (interface)

-learn to extend abstract classes and implement abstract methods

-learn when to implement the Comparable<T> interface

-learn how to write your own interface and understand why they're useful

-learn how to override parent class methods, namely the toString() method

-know when to throw errors and use assertions

**Assignment:**1. A rational, or a fraction, is a number that has a numerator and a denominator. A rational is arithmetical, meaning all four operations can be performed on it.

Create a Rational class that extends Java's built-in abstract Number class, implements Java's built-in Comparable<T> interface, and implements your own user-defined Arithmetical<T> class.

Arithmetical<T> should declare four methods for addition, subtraction, multiplication and division.

What should you do if the user creates a Rational object with a 0 in the denominator?

Your class should also override the Java's Object class' toString() method to return a string representation of your Rational object.

**Extra:**Provide a default construtor with no parameters another constructor that takes as parameter only the numerator.

Create a method to simplify a Rational to lowest terms (i.e 1/2 instead of 3/6).

2. Create a Matrix class that also implements Arithmetical<T>. Answer this question: should Matrix also implement Comparable<T>? Hint: is a Matrix comparable to another?

Your Matrix class should be composed of a two dimensional array of Rational objects.

Provide getter and setter methods to return or to modify individual entries within the Matrix.

Matrix division is simply multiplication by the inverse. For the purpose of this exercise you may throw an error when the user calls the division method.

Remember that only matrices of the same dimensions can be added to or subtracted from one another. When can matrices multiply with one another? Handle the errors.

Override the toString() method to return a string of your Matrix object. Your implementation should make use of the toString() in the Rational class.

**Extra:**Provide methods to return the transpose and identity of your Matrix

Create a method that checks if two matrices are equal.

Create a method to find the determinant of a 2 x 2 matrix.

Create a method to find the inverse of a 2 x 2 matrix.

Advanced: find the determinant of a any square matrix (hint: recursion).

Advanced: create an algorithm to find the inverse of any square matrix.

3. Create a test client to demonstrate and test all functionalities of the project above.

This post has been edited by **carnivroar**: 09 February 2013 - 11:50 AM