-
Notifications
You must be signed in to change notification settings - Fork 8
Task 1-100%, Task 2-80% #2
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| public Accountant(String nameE, int workHoursE) { | ||
| super(nameE, workHoursE); | ||
| countAccountant++; | ||
| Manager.SalaryOverAll=Manager.SalaryOverAll+getSalary(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| } | ||
| @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 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| public Employees(String nameE,int workHoursE){ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| } | ||
|
|
||
|
|
| 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() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This constructor is not needed. |
||
| } | ||
|
|
||
| public FractionNumber(int Numerator, int Denominator) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| this.Numerator = Numerator; | ||
|
|
||
| if(Denominator==0){System.out.println("WRONG");} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| else this.Denominator = Denominator; | ||
| } | ||
|
|
||
| public FractionNumber(int NumeratorF) { | ||
| this(NumeratorF, 1); | ||
| } | ||
|
|
||
| public int Get() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Methods should be named in lowerCamelCase style.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need variables |
||
| int b = Denominator; | ||
|
|
||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
||
|
|
||
| } |
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 to count all objects that were created.