Skip to content

Commit 5fa50af

Browse files
committed
lab04 collect input parameters.
1 parent e3fed09 commit 5fa50af

8 files changed

Lines changed: 405 additions & 81 deletions

File tree

lab04_java8/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Salary Income Predictor
2+
3+
## Tech stack
4+
5+
1. java8 stream api
6+
2. java enum
7+
3. builder pattern
8+
9+
## Setup
10+
11+
```sh
12+
git clone https://github.com/uniquejava/FSD.git
13+
cd FSD/lab04_java8
14+
mvn clean package
15+
java -cp ./target/*.jar me.cyper.fsd.lab04.SalaryPredictor
16+
```
17+
18+
## Sample output
19+
20+
```sh
21+
$ java -cp ./target/*.jar me.cyper.fsd.lab04.SalaryPredictor
22+
23+
Salary Income Predictor
24+
=================================================
25+
26+
Input starting salary: 1500
27+
Input increment in percent: 20
28+
Input increment received frequency: 2
29+
Input deductions on income: 200
30+
Input deductions received frequency: 1
31+
Input prediction years: 3
32+
33+
Input parameters
34+
=================================================
35+
36+
SalaryInput{startingSalary=1500, incInPercent=20, incFrequency=HALF_YEARLY, decAmount=200, decFrequency=ANNUALLY, years=3}
37+
```
38+
39+
## References

lab04_java8/pom.xml

Lines changed: 76 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,85 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<modelVersion>4.0.0</modelVersion>
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
66

7-
<groupId>me.cyper.fsd.lab04</groupId>
8-
<artifactId>salary-predictor</artifactId>
9-
<version>1.0-SNAPSHOT</version>
7+
<groupId>me.cyper.fsd.lab04</groupId>
8+
<artifactId>salary-predictor</artifactId>
9+
<version>1.0-SNAPSHOT</version>
1010

11-
<name>salary-predictor</name>
12-
<!-- FIXME change it to the project's website -->
13-
<url>http://www.example.com</url>
11+
<name>salary-predictor</name>
12+
<url>https://github.com/uniquejava/FSD</url>
1413

15-
<properties>
16-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17-
<maven.compiler.source>1.8</maven.compiler.source>
18-
<maven.compiler.target>1.8</maven.compiler.target>
19-
</properties>
14+
<properties>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<maven.compiler.source>1.8</maven.compiler.source>
17+
<maven.compiler.target>1.8</maven.compiler.target>
18+
</properties>
2019

21-
<dependencies>
22-
<dependency>
23-
<groupId>junit</groupId>
24-
<artifactId>junit</artifactId>
25-
<version>4.11</version>
26-
<scope>test</scope>
27-
</dependency>
28-
</dependencies>
20+
<dependencies>
21+
<dependency>
22+
<groupId>com.google.guava</groupId>
23+
<artifactId>guava</artifactId>
24+
<version>22.0</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.apache.commons</groupId>
28+
<artifactId>commons-lang3</artifactId>
29+
<version>3.7</version>
30+
</dependency>
2931

30-
<build>
31-
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
32-
<plugins>
33-
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
34-
<plugin>
35-
<artifactId>maven-clean-plugin</artifactId>
36-
<version>3.1.0</version>
37-
</plugin>
38-
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
39-
<plugin>
40-
<artifactId>maven-resources-plugin</artifactId>
41-
<version>3.0.2</version>
42-
</plugin>
43-
<plugin>
44-
<artifactId>maven-compiler-plugin</artifactId>
45-
<version>3.8.0</version>
46-
</plugin>
47-
<plugin>
48-
<artifactId>maven-surefire-plugin</artifactId>
49-
<version>2.22.1</version>
50-
</plugin>
51-
<plugin>
52-
<artifactId>maven-jar-plugin</artifactId>
53-
<version>3.0.2</version>
54-
</plugin>
55-
<plugin>
56-
<artifactId>maven-install-plugin</artifactId>
57-
<version>2.5.2</version>
58-
</plugin>
59-
<plugin>
60-
<artifactId>maven-deploy-plugin</artifactId>
61-
<version>2.8.2</version>
62-
</plugin>
63-
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
64-
<plugin>
65-
<artifactId>maven-site-plugin</artifactId>
66-
<version>3.7.1</version>
67-
</plugin>
68-
<plugin>
69-
<artifactId>maven-project-info-reports-plugin</artifactId>
70-
<version>3.0.0</version>
71-
</plugin>
72-
</plugins>
73-
</pluginManagement>
74-
</build>
32+
<dependency>
33+
<groupId>junit</groupId>
34+
<artifactId>junit</artifactId>
35+
<version>4.11</version>
36+
<scope>test</scope>
37+
</dependency>
38+
</dependencies>
39+
40+
<build>
41+
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
42+
<plugins>
43+
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
44+
<plugin>
45+
<artifactId>maven-clean-plugin</artifactId>
46+
<version>3.1.0</version>
47+
</plugin>
48+
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
49+
<plugin>
50+
<artifactId>maven-resources-plugin</artifactId>
51+
<version>3.0.2</version>
52+
</plugin>
53+
<plugin>
54+
<artifactId>maven-compiler-plugin</artifactId>
55+
<version>3.8.0</version>
56+
</plugin>
57+
<plugin>
58+
<artifactId>maven-surefire-plugin</artifactId>
59+
<version>2.22.1</version>
60+
</plugin>
61+
<plugin>
62+
<artifactId>maven-jar-plugin</artifactId>
63+
<version>3.0.2</version>
64+
</plugin>
65+
<plugin>
66+
<artifactId>maven-install-plugin</artifactId>
67+
<version>2.5.2</version>
68+
</plugin>
69+
<plugin>
70+
<artifactId>maven-deploy-plugin</artifactId>
71+
<version>2.8.2</version>
72+
</plugin>
73+
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
74+
<plugin>
75+
<artifactId>maven-site-plugin</artifactId>
76+
<version>3.7.1</version>
77+
</plugin>
78+
<plugin>
79+
<artifactId>maven-project-info-reports-plugin</artifactId>
80+
<version>3.0.0</version>
81+
</plugin>
82+
</plugins>
83+
</pluginManagement>
84+
</build>
7585
</project>

lab04_java8/src/main/java/me/cyper/fsd/lab04/App.java

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package me.cyper.fsd.lab04;
2+
3+
import me.cyper.fsd.lab04.model.SalaryInput;
4+
import me.cyper.fsd.lab04.utils.SalaryInputBuilder;
5+
6+
/**
7+
* Salary Income Predictor.
8+
*/
9+
public class SalaryPredictor {
10+
public static void main(String[] args) {
11+
section("Salary Income Predictor");
12+
13+
SalaryInput input = new SalaryInputBuilder()
14+
.collectStartingSalary()
15+
.collectIncrementInPercent()
16+
.collectIncrementFrequency()
17+
.collectDeductionsOnIncome()
18+
.collectDeductionsFrequency()
19+
.collectPredictionYears()
20+
.build();
21+
22+
23+
section("Input parameters");
24+
System.out.println(input);
25+
}
26+
27+
private static void section(String title) {
28+
System.out.println();
29+
System.out.println(title);
30+
System.out.println("=================================================");
31+
System.out.println();
32+
}
33+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package me.cyper.fsd.lab04.model;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import java.util.Set;
6+
7+
public enum Frequency {
8+
QUARTERLY(4), HALF_YEARLY(2), ANNUALLY(1);
9+
10+
private final int value;
11+
private static Map<Integer, Frequency> map = new HashMap<>();
12+
13+
private Frequency(int value) {
14+
this.value = value;
15+
}
16+
17+
static {
18+
for (Frequency frequency : Frequency.values()) {
19+
map.put(frequency.value, frequency);
20+
}
21+
}
22+
23+
public static Frequency valueOf(Integer value) {
24+
Frequency frequency = map.get(value);
25+
if (frequency == null) {
26+
throw new IllegalArgumentException("Incorrect frequency value.");
27+
}
28+
return frequency;
29+
}
30+
31+
public int getValue() {
32+
return value;
33+
}
34+
35+
public static Set<Integer> getValues() {
36+
return map.keySet();
37+
}
38+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package me.cyper.fsd.lab04.model;
2+
3+
import java.math.BigDecimal;
4+
5+
public class SalaryInput {
6+
private BigDecimal startingSalary;
7+
private BigDecimal incInPercent;
8+
private Frequency incFrequency;
9+
private BigDecimal decAmount;
10+
private Frequency decFrequency;
11+
private int years;
12+
13+
public BigDecimal getStartingSalary() {
14+
return startingSalary;
15+
}
16+
17+
public void setStartingSalary(BigDecimal startingSalary) {
18+
this.startingSalary = startingSalary;
19+
}
20+
21+
public BigDecimal getIncInPercent() {
22+
return incInPercent;
23+
}
24+
25+
public void setIncInPercent(BigDecimal incInPercent) {
26+
this.incInPercent = incInPercent;
27+
}
28+
29+
public Frequency getIncFrequency() {
30+
return incFrequency;
31+
}
32+
33+
public void setIncFrequency(Frequency incFrequency) {
34+
this.incFrequency = incFrequency;
35+
}
36+
37+
public BigDecimal getDecAmount() {
38+
return decAmount;
39+
}
40+
41+
public void setDecAmount(BigDecimal decAmount) {
42+
this.decAmount = decAmount;
43+
}
44+
45+
public Frequency getDecFrequency() {
46+
return decFrequency;
47+
}
48+
49+
public void setDecFrequency(Frequency decFrequency) {
50+
this.decFrequency = decFrequency;
51+
}
52+
53+
public int getYears() {
54+
return years;
55+
}
56+
57+
public void setYears(int years) {
58+
this.years = years;
59+
}
60+
61+
@Override
62+
public String toString() {
63+
return "SalaryInput{" +
64+
"startingSalary=" + startingSalary +
65+
", incInPercent=" + incInPercent +
66+
", incFrequency=" + incFrequency +
67+
", decAmount=" + decAmount +
68+
", decFrequency=" + decFrequency +
69+
", years=" + years +
70+
'}';
71+
}
72+
}

0 commit comments

Comments
 (0)