-
Notifications
You must be signed in to change notification settings - Fork 8
Task with matrix done. #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
didva
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please go on with other tasks.
| */ | ||
| public class Matrix { | ||
|
|
||
| private final int Rows; // count Rows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow java code convention. All fields, methods, method arguments should be named in lowerCamelCase style.
| public Matrix(int[][]data) //Constructor 2d array | ||
| { | ||
| this.Rows = data.length; | ||
| this.Columns = data[0].length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible to create multidimensional arrays in Java like:
int[][] example = new int[3][];
example[0] = new int[100];
example[1] = new int[1000];
example[2] = new int[0];
So determine columns count by the data[0].length is not the best approach. Please add verification that all rows has the same columns number.
By the way, if you will modify this incoming array - your matrix will be changed too. So I'd prefer copying.
|
|
||
| @Override | ||
| public String toString() { | ||
| for(int i = 0; i < Rows;i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main point of toString method that it should return string representation of the object and do not print anything.
So please use StringBuilder or any other way to create resulting string and get rid of System.out.print.
| return C; | ||
| } | ||
|
|
||
| public Matrix Calculate(Matrix B,char d) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- There is no need in this method at all. Determining operation by
charis not the good approach, because you now which method was called and which operation to execute. So please split your logic to specific methods. - Not sure multiplication is done correctly. Please read about it https://en.wikipedia.org/wiki/Matrix_multiplication
- As you may remember the point was that current matrix should be changed. So no need to create third matrix. You should modify existing one.
|
|
||
| public Matrix Transpose() | ||
| { | ||
| Matrix A = this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure you need extract this to variable. As for me it's even better to use data directly. Like C.data[i][j] = data[j][i];
| int[][]A = new int[2][2];//initialization matrix A | ||
| int[][]B = new int[2][2];//initialization matrix | ||
|
|
||
| A[0][0] = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer int[][] example = {{1,2}, {3,4}}; such kind of initialization.
| public class TestApp { | ||
|
|
||
| public static void main(String[] args) { | ||
| TestApp app = new TestApp(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need this object?
didva
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please format your code. Please follow java code convention.
| * Created by Yaroslav Pavlinskiy on 06.01.2017. | ||
| */ | ||
| public class Accountant extends Employee { | ||
| Accountant(String name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer public constructors everywhere in this task.
| } | ||
|
|
||
| public double calculateSalaryForEmployee(Employee e) { | ||
| if(e instanceof Programmer || e instanceof Manager || e instanceof Accountant) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Using
instanceofisn't a good practice and should be avoided if it's possible. I do not see any reason for such check here. - The main idea was to calculate salary for a array/list of employees. They should be passed in constructor/setter method. So we'll have some kind of responsibility. This Accountant is responsible for a list/array of employees and calculates their salary.
Other tasks will be done soon