Narzędzia użytkownika

Narzędzia witryny


java_e:java02

Object orientation


exercise 2.1
Write a definition for a class called Fraction, representing the fraction $\frac{a}{b}$. Your class should have two int fields representing the numerator and denominator of the fraction, and implementations of appropriate constructors and methods, so that it is possible to perform the following operations

Ulamek obj,obj2;
obj=new Ulamek(6,8);
obj2=new Ulamek(3,7);
 
System.out.println(obj);
 
double x=obj.rozwDziesietne();
 
Ulamek obj3=obj.plus(obj2);
Ulamek obj4=obj.minus(obj2);
Ulamek obj4=obj.razy(obj2);
 
obj.odwroc();
obj.skroc();

In the case of the rozwDziesietne() method, before dividing two int numbers, cast one of them to double, as in the example below

int i=7;
double x=(double)i;

Write an appropriate program and test the constructors and methods you have written.

exercise 2.2
Write a definition of the 'ComplexNumber' class. Implement methods that perform operations on complex numbers.

exercise 2.3
Write a definition of the Vector class whose objects will represent vectors in three-dimensional space. Implement methods that implement vector addition, vector product, dot product and other vector operations.

exercise 2.4
Write the definition of the SquarePolynomial class. Implement methods for adding polynomials, multiplying polynomials, and finding the zeros of a polynomial.

exercise 2.5
Write a definition of the BigNumber class. Implement a method to test whether a number is divisible by the number passed to this method as a parameter and a method to test whether the number is prime.

exercise 2.6
Write a definition of the 'Matrix' class whose objects will represent 3×3 matrices. Implement a method that returns the determinant of a matrix, a method that performs matrix transposition, a method that performs matrix diagonalization, a method that returns a matrix inverse, and other matrix operations.



Z. Dendzik, 2024

java_e/java02.txt · ostatnio zmienione: 2024/10/18 11:21 przez zbd