
January 26th, 2007, 09:42 PM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 1
Time spent in forums: 15 m 49 sec
Reputation Power: 0
|
|
Project Help
hi there, i am totaly stuck, i didn't understand anything from the java project given blow:
Quote: Project 3:
1. Define a GenArith interface giving the add, sub, mul, div, abs methods to be supported
for any number type which implements this interface. abs should return a positive double value
Here is a (partial) definition for the class:
public interface GenArith{
public GenArith add(GenArith input);
................................
public double abs();
................................
}
2. Define GenReal class that implements the GenArith interface.
Here is a (partial) definition for the class:
public class GenReal implements GenArith{
double value;
public GenArith add(GenArith input){
GenReal r;
if (input instanceof GenReaL){
r=(GenReal)input;
...............
}
else if (input instanceof .........)
.........
........
}
3. Define GenInteger class that implements the GenArith interface.
Here is a (partial) definition for the class:
public class GenInteger implements GenArith{
int value;
................................
}
4. Define GenRational class that implements the GenArith interface.
Here is a (partial) definition for the class:
public class GenRational implements GenArith{
int numerator, denumerator;
................................
}
5. Define GenPolynomial class which represents a polynomial in one variable over the real numbers.Just give a blank definition for the div and abs methods; and add an absPol method take abs of each coefficient in the polynomial and returns the new polynomial.
A polynomial object can be operated with any object from the other classes. So, make your design so that a polynomial object can be added, subtracted or multiplied by any object from the other classes or the GenPolynomial class and vice versa. Think the type of the resultant object you should return and the characteristics of the operation.
Here is a (partial) definition for the class:
public class GenPolynomial implements GenArith{
double [] coeffs;
public GenArith div(GenArith input){ return null;}
public double abs(){ return 0;}
public GenPolynomial absPol(){
................................
}
................................
}
The coefficients of the polynomial are stored in the array coeffs starting with the constant term.
6. Write the proper constructor for these classes.
7. Write a method for the GenPolynomial class,
GenPolynomial multiplyByX()
That produces a new Polynomial object that repesents the result of multiplying the
current polynomial by x, where the polynomial is a polynomial in x.
8. Write a method for the GenPolynomial class,
GenPolynomial multiplyByAxPlusB (double a, double b)
That produces a new Polynomial object that repesents the result of multiplying the
current polynomial by (ax +b), where the polynomial is a polynomial in x.
9. Write a method for the GenPolynomial class,
GenPolynomial differentiate()
That returns a new Polynomial object that represents the differentiated form of the polynomial.
10. Write a method for the GenPolynomial class,
GenPolynomial integrate()
That returns a new Polynomial object that represents the integrated form of the polynomial with constant term=0..
11. Your classes should obviously have suitable toString() methods |
i would code but i have no idea what to code, i don't even know the purposes of the given classes, it's not fair enough.. I just need to be guided. I can code but it's impossible to code without knowing the aim of the project.. I would appreciate if anyone would share their thoughts about the project and tell me what to do! Thanks...
|