Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package school.lemon.changerequest.java.Employees;

/**
* Created by User on 05.12.2016.
*/
public class Accountant extends Employees {
private static int countAccountant;
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need to count all objects that were created.

public Accountant(String nameE, int workHoursE) {
super(nameE, workHoursE);
countAccountant++;
Manager.SalaryOverAll=Manager.SalaryOverAll+getSalary();
Copy link
Contributor

Choose a reason for hiding this comment

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

Accountant should contain array of employees and calculate their salary instead of static fields.
You should avoid static fields/methods everywhere it possible.

}
@Override
public double getSalary() {
if (getRatio()<=1){return getRatio()*salaryPer160;}
else return salaryPer160;

}
public static int getCount() {
return countAccountant;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package school.lemon.changerequest.java.Employees;

/**
* Created by User on 05.12.2016.
*/
public class Employees {
Copy link
Contributor

Choose a reason for hiding this comment

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

Employee is most likely better name for this class.

public Employees(String nameE,int workHoursE){
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 it's a good way to pass worked hours via constructor. I'd prefer add method like work(int hours) or simple setWorkedHours(int hours).

name=nameE;
workHours=workHoursE;

}

public String getName(){
return name;}

public double getSalary(){
return salary;
}
public void SetSalary(int salarySet){
salary=salarySet;
}
public double getRatio(){
return (double)(workHours)/(double)(workHoursPerMonth);
}
public void setCount(){

}
public String getJob(){
return job;}



protected 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.

Please move fields on the top of the class.

protected String job;
protected double salary;
protected int workHours;
final int workHoursPerMonth= 160;
protected int salaryPer160= 100;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package school.lemon.changerequest.java.Employees;

/**
* Created by User on 05.12.2016.
*/
public class Manager extends Employees{
protected static double SalaryOverAll;
public Manager(String nameE, int salaryE) {
super(nameE,salaryE);
Manager.SalaryOverAll=Manager.SalaryOverAll+getSalary();
}
@Override
public double getSalary() {
if (getRatio()<=1){return getRatio()*salaryPer160;}
else return salaryPer160;

}
public void setSalaryPer160(int n){
salaryPer160=n;
}
public double SalaryOverAll(){



return SalaryOverAll;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package school.lemon.changerequest.java.Employees;

/**
* Created by User on 05.12.2016.
*/
public class Programmer extends Employees {

private static int countProgrammer;
public Programmer(String nameE,int workHoursE) {
super(nameE, workHoursE);
countProgrammer++;
Manager.SalaryOverAll=Manager.SalaryOverAll+getSalary();
}

@Override
public double getSalary() {

return getRatio()*salaryPer160;


}
public void setSalaryPer160(int n){
salaryPer160=n;
}
public static int getCount() {
return countProgrammer;
}
}


24 changes: 24 additions & 0 deletions src/main/java/school/lemon/changerequest/java/Employees/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package school.lemon.changerequest.java.Employees;

/**
* Created by User on 07.12.2016.
*/
public class Test {
public static void main(String[] args) {

Programmer c1= new Programmer("Petro",160);
System.out.println(c1.getName()+" "+c1.getSalary());
Programmer c2= new Programmer("Pavlo", 320);
System.out.println(c2.getName()+" "+c2.getSalary());
Manager c3= new Manager("Colya",100);
System.out.println(c3.getName()+" "+c3.getSalary());
Manager c4=new Manager("Kolya", 999);
System.out.println(c4.getName()+" "+c4.getSalary());
Accountant c5=new Accountant("Colya",160);
System.out.println(c5.getName()+" "+c5.getSalary());
Accountant c6= new Accountant("Kolya",999);
System.out.println(c6.getName()+" "+c6.getSalary());

System.out.println("salary for all accountable employees " + Manager.SalaryOverAll);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package school.lemon.changerequest.java.Fraction_Number;

/**
* Created by User on 07.12.2016.
*/
public class FractionNumber {
public FractionNumber() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This constructor is not needed.

}

public FractionNumber(int Numerator, int Denominator) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please read java convention. All variables, fields and method arguments should be named on lowerCamelCase.

this.Numerator = Numerator;

if(Denominator==0){System.out.println("WRONG");}
Copy link
Contributor

Choose a reason for hiding this comment

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

System.out.println("WRONG"); is not the case. Please set denominator to 1 or throw exception.

else this.Denominator = Denominator;
}

public FractionNumber(int NumeratorF) {
this(NumeratorF, 1);
}

public int Get() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Methods should be named in lowerCamelCase style.

Copy link
Contributor

Choose a reason for hiding this comment

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

Get what? Please think about better method name.

int m = getNumerator();
int n = getDenominator();
int r = 0;
while (n != 0) {
r = m % n;
m = n;
n = r;
}
return m;
}

public void Normalized() {
int div = Get();
Numerator = Numerator / div;
Denominator = Denominator / div;
}



public int getNumerator() {
return Numerator;
}

public int getDenominator() {
return Denominator;
}

public double getDecimalValue() {
return (double) Numerator / (double) Denominator;
}
public String toString() {
return Numerator + "/" + Denominator;
}


public FractionNumber add(FractionNumber a) {
int aN = a.getNumerator();
int aD = a.getDenominator();
int An = this.Numerator;
int Ad = this.Denominator;
if (this.Denominator == aD) {
aN = An + aN;
} else {
aN = aN * Ad;
An = An * aD;
aN = An + aN;
aD = Ad * aD;
}
FractionNumber b = new FractionNumber(aN, aD);
b.Normalized();
return b;
}
public FractionNumber multiply(FractionNumber a) {
int aN = a.getNumerator();
int aD = a.getDenominator();
aN = aN * this.Numerator;
aD = aD * this.Denominator;

FractionNumber b = new FractionNumber(aN, aD);
b.Normalized();
return b;
}
public FractionNumber divide(FractionNumber a) {
int aN = a.getNumerator();
int aD = a.getDenominator();
int An = this.Numerator;
int Ad = this.Denominator;

Ad = Ad * aN;
An = An * aD;
FractionNumber b = new FractionNumber(An, Ad);
b.Normalized();
Copy link
Contributor

Choose a reason for hiding this comment

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

Normalization should be done right on object creation. So please move it to constructor.

return b;
}

public FractionNumber subtract(FractionNumber a) {
int aN = a.getNumerator();
int aD = a.getDenominator();

int An = this.Numerator;
int Ad = this.Denominator;
if (this.Denominator == aD) {
aN = An - aN;
} else {

aN = aN * Ad;
An = An * aD;
aN = An-aN;
aD = Ad * aD;
}
FractionNumber b = new FractionNumber(aN, aD);
b.Normalized();
return b;
}


final int def = 1;
protected int Numerator;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move these fields on the top of the class.

protected int Denominator;

int a = Numerator;
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 variables a, b?

int b = Denominator;

}

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need these empty lines?














Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package school.lemon.changerequest.java.Fraction_Number;

/**
* Created by User on 07.12.2016.
*/
public class Test {
public static void main(String[] args) {

FractionNumber f1=new FractionNumber(3,4);
FractionNumber f2= new FractionNumber(9,2);
System.out.println("df");
FractionNumber f3=new FractionNumber(3,0);
System.out.println(f3.toString());
System.out.println(f1.toString());
System.out.println(f2.toString());
System.out.println("ТЕСТ на сложение "+f1.add(f2).toString());
System.out.println(f1.toString());
System.out.println(f2.toString());
System.out.println("Тест На умножение "+f1.multiply(f2).toString());
System.out.println(f1.toString());
System.out.println(f2.toString());
System.out.println("Тест На деление "+f1.divide(f2).toString());
System.out.println(f1.toString());
System.out.println(f2.toString());
System.out.println("Тест На отнимание "+f1.subtract(f2).toString());
System.out.println("Тест На отнимание "+f2.subtract(f1).toString());




}


}