Skip to content

Conversation

@yarikpavlin
Copy link

Other tasks will be done soon

@didva didva self-assigned this Dec 13, 2016
Copy link
Contributor

@didva didva left a 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
Copy link
Contributor

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;
Copy link
Contributor

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++)
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. There is no need in this method at all. Determining operation by char is not the good approach, because you now which method was called and which operation to execute. So please split your logic to specific methods.
  2. Not sure multiplication is done correctly. Please read about it https://en.wikipedia.org/wiki/Matrix_multiplication
  3. 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;
Copy link
Contributor

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;
Copy link
Contributor

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();
Copy link
Contributor

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?

Copy link
Contributor

@didva didva left a 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) {
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Using instanceof isn't a good practice and should be avoided if it's possible. I do not see any reason for such check here.
  2. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants