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
13 changes: 13 additions & 0 deletions AlexSubbotin/lesson_10/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions AlexSubbotin/lesson_10/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions AlexSubbotin/lesson_10/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions AlexSubbotin/lesson_10/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions AlexSubbotin/lesson_10/lesson_10.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />
33 changes: 33 additions & 0 deletions AlexSubbotin/lesson_10/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>lesson_10</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>


</project>
45 changes: 45 additions & 0 deletions AlexSubbotin/lesson_10/src/main/java/Cow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
public class Cow {
public final int DAYS_IN_YEAR = 365;
private float cowMilkProduction;
private float cowFoodConsumption;
private float cowFoodPrise;
private float cowMilkPrice;

protected float calculateYearlyCowRevenue() {
float revenue = (this.cowMilkProduction * this.cowMilkPrice
- this.cowFoodConsumption * this.cowFoodPrise) * DAYS_IN_YEAR;
return revenue;
}

public float getCowMilkProduction() {
return cowMilkProduction;
}

protected void setCowMilkProduction(float cowMilkProduction) {
this.cowMilkProduction = cowMilkProduction;
}

public float getCowFoodConsumption() {
return cowFoodConsumption;
}

protected void setCowFoodConsumption(float cowFoodConsumption) {
this.cowFoodConsumption = cowFoodConsumption;
}

public float getCowFoodPrise() {
return cowFoodPrise;
}

protected void setCowFoodPrise(float cowFoodPrise) {
this.cowFoodPrise = cowFoodPrise;
}

public float getCowMilkPrice() {
return cowMilkPrice;
}

protected void setCowMilkPrice(float cowMilkPrice) {
this.cowMilkPrice = cowMilkPrice;
}
}
109 changes: 109 additions & 0 deletions AlexSubbotin/lesson_10/src/main/java/Farm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
public class Farm {
private float farmPrice;
private float percentIncomeTax;
private float percentSalaryToMilkmaids;
private int numberOfCows;
Cow cows = new Cow();

public String calculateFarmProfit() {
float revenueOfAllCows = calculateYearlyAllCowsRevenue();
float revenueAfterTax = calculateYearlyRevenueAfterTax(revenueOfAllCows);
float revenueAfterSalary = calculateYearlyRevenueAfterSalary(revenueAfterTax);
String farmProfit = calculateChanceBuyNewFarms(revenueAfterSalary);
return farmProfit;
}

public String calculateChanceBuyNewFarms(float revenue) {
String farmsNumber;
int farmsNumb = (int) (revenue / farmPrice);
if (farmsNumb > 3) {
System.out.println("You can buy " + farmsNumb + " farms.");
farmsNumber = "SUPER PROFITABLE";
} else if (farmsNumb >= 1) {
System.out.println("You can buy " + farmsNumb + " farms.");
farmsNumber = "PROFITABLE";
} else {
System.out.println("You can not buy farms.");
farmsNumber = "NOT PROFITABLE";
}
System.out.println(farmsNumber);
return farmsNumber;
}

public float calculateYearlyRevenueAfterSalary(float revenue) {
revenue -= revenue * percentSalaryToMilkmaids / 100;
return revenue;
}

public float calculateYearlyRevenueAfterTax(float revenue) {
revenue -= revenue * percentIncomeTax / 100;
return revenue;
}

public float calculateYearlyAllCowsRevenue() {
float revenue = cows.calculateYearlyCowRevenue() * numberOfCows;
return revenue;
}


protected boolean paramsLimitsChecking(int lowerLimit, int upperLimit, float parameter) {
if (parameter < lowerLimit || parameter > upperLimit) {
return false;
} else {
return true;
}
}

public String setFarmParams(float farmPrice, float percentIncomeTax, float percentSalaryToMilkmaids) {
String result;
if (paramsLimitsChecking(500, 1000, farmPrice)
&& paramsLimitsChecking(10, 20, percentIncomeTax)
&& paramsLimitsChecking(5, 10, percentSalaryToMilkmaids)) {
this.farmPrice = farmPrice;
this.percentIncomeTax = percentIncomeTax;
this.percentSalaryToMilkmaids = percentSalaryToMilkmaids;
result = "";
} else {
result = "INPUT PARAMS ARE INCORRECT.";
System.out.println(result);
}
return result;
}

public String setCowParams(int numberOfCows, float cowFoodConsumption, float cowFoodPrise,
float cowMilkProduction, float cowMilkPrice) {
String result;
if (paramsLimitsChecking(50, 100, numberOfCows)
&& paramsLimitsChecking(5, 10, cowFoodConsumption)
&& paramsLimitsChecking(1, 3, cowFoodPrise)
&& paramsLimitsChecking(1, 5, cowMilkProduction)
&& paramsLimitsChecking(5, 10, cowMilkPrice)) {
this.cows.setCowFoodPrise(cowFoodPrise);
this.cows.setCowMilkPrice(cowMilkPrice);
this.cows.setCowMilkProduction(cowMilkProduction);
this.cows.setCowFoodConsumption(cowFoodConsumption);
this.numberOfCows = numberOfCows;
result = "";
} else {
result = "INPUT PARAMS ARE INCORRECT.";
System.out.println(result);
}
return result;
}

public float getFarmPrice() {
return farmPrice;
}

public float getPercentIncomeTax() {
return percentIncomeTax;
}

public float getPercentSalaryToMilkmaids() {
return percentSalaryToMilkmaids;
}

public int getNumberOfCows() {
return numberOfCows;
}
}
15 changes: 15 additions & 0 deletions AlexSubbotin/lesson_10/src/test/java/CowTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

public class CowTest {

Farm farm = new Farm();

@Test
public void testCalculateYearlyCowRevenue() {
farm.setCowParams(50, 8f, 3f, 3f, 10f);
assertThat(farm.cows.calculateYearlyCowRevenue(), is(equalTo((3*10-8*3f)*365)));
}
}
Loading