├── .gitignore
├── .idea
├── .gitignore
├── vcs.xml
├── misc.xml
├── modules.xml
└── uiDesigner.xml
├── src
├── main
│ └── java
│ │ ├── day04
│ │ ├── CurrentAccount.java
│ │ ├── BankAccount.java
│ │ └── SavingsAccount2.java
│ │ ├── day03
│ │ ├── enums
│ │ │ ├── Fruit.java
│ │ │ └── FuelType.java
│ │ ├── Monkey.java
│ │ ├── Person.java
│ │ └── GasStation.java
│ │ ├── day05
│ │ ├── bank
│ │ │ ├── Taxable.java
│ │ │ └── Account.java
│ │ └── forms
│ │ │ ├── CalculableArea.java
│ │ │ ├── Square.java
│ │ │ ├── Circle.java
│ │ │ ├── Rectangle.java
│ │ │ └── Trapeze.java
│ │ ├── day02
│ │ ├── Calculator.java
│ │ ├── Employee.java
│ │ └── Tv.java
│ │ └── day01
│ │ ├── Invoice.java
│ │ ├── PhysicalAssessment.java
│ │ └── Client.java
├── Main.java
└── test
│ └── java
│ ├── day05
│ ├── SquareTest.java
│ ├── RectangleTest.java
│ ├── TrapezeTest.java
│ ├── CircleTest.java
│ └── FormsTest.java
│ ├── day01
│ ├── InvoiceTest.java
│ ├── ClientTest.java
│ └── PhysicalAssessmentTest.java
│ ├── day02
│ ├── EmployeeTest.java
│ ├── CalculatorTest.java
│ └── TvTest.java
│ ├── day03
│ ├── MonkeyTest.java
│ ├── PersonTest.java
│ └── GasStationTest.java
│ └── day04
│ └── BankAccountTest.java
├── lib
├── opentest4j-1.2.0.jar
├── junit-jupiter-5.8.1.jar
├── apiguardian-api-1.1.2.jar
├── junit-jupiter-api-5.8.1.jar
├── junit-jupiter-engine-5.8.1.jar
├── junit-jupiter-params-5.8.1.jar
├── junit-platform-commons-1.8.1.jar
└── junit-platform-engine-1.8.1.jar
└── Aprendendo POO de uma vez por todas.iml
/.gitignore:
--------------------------------------------------------------------------------
1 | # Project exclude paths
2 | /out/
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/src/main/java/day04/CurrentAccount.java:
--------------------------------------------------------------------------------
1 | package main.java.day04;
2 |
3 | public class CurrentAccount {
4 | }
5 |
--------------------------------------------------------------------------------
/lib/opentest4j-1.2.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cami-la/Aprendendo_POO_de_uma_vez_por_todas_test/HEAD/lib/opentest4j-1.2.0.jar
--------------------------------------------------------------------------------
/lib/junit-jupiter-5.8.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cami-la/Aprendendo_POO_de_uma_vez_por_todas_test/HEAD/lib/junit-jupiter-5.8.1.jar
--------------------------------------------------------------------------------
/src/main/java/day03/enums/Fruit.java:
--------------------------------------------------------------------------------
1 | package main.java.day03.enums;
2 |
3 | public enum Fruit {
4 | BANANA, ORANGE, APPLE;
5 | }
6 |
--------------------------------------------------------------------------------
/lib/apiguardian-api-1.1.2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cami-la/Aprendendo_POO_de_uma_vez_por_todas_test/HEAD/lib/apiguardian-api-1.1.2.jar
--------------------------------------------------------------------------------
/src/main/java/day05/bank/Taxable.java:
--------------------------------------------------------------------------------
1 | package main.java.day05.bank;
2 |
3 | public interface Taxable {
4 | double calculateTax();
5 | }
6 |
--------------------------------------------------------------------------------
/lib/junit-jupiter-api-5.8.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cami-la/Aprendendo_POO_de_uma_vez_por_todas_test/HEAD/lib/junit-jupiter-api-5.8.1.jar
--------------------------------------------------------------------------------
/lib/junit-jupiter-engine-5.8.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cami-la/Aprendendo_POO_de_uma_vez_por_todas_test/HEAD/lib/junit-jupiter-engine-5.8.1.jar
--------------------------------------------------------------------------------
/lib/junit-jupiter-params-5.8.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cami-la/Aprendendo_POO_de_uma_vez_por_todas_test/HEAD/lib/junit-jupiter-params-5.8.1.jar
--------------------------------------------------------------------------------
/lib/junit-platform-commons-1.8.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cami-la/Aprendendo_POO_de_uma_vez_por_todas_test/HEAD/lib/junit-platform-commons-1.8.1.jar
--------------------------------------------------------------------------------
/lib/junit-platform-engine-1.8.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cami-la/Aprendendo_POO_de_uma_vez_por_todas_test/HEAD/lib/junit-platform-engine-1.8.1.jar
--------------------------------------------------------------------------------
/src/main/java/day05/forms/CalculableArea.java:
--------------------------------------------------------------------------------
1 | package main.java.day05.forms;
2 |
3 | public interface CalculableArea {
4 | double calculateArea();
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/day03/enums/FuelType.java:
--------------------------------------------------------------------------------
1 | package main.java.day03.enums;
2 |
3 | import java.math.BigDecimal;
4 |
5 | public enum FuelType {
6 | GASOLINE , ALCOOHOL;
7 | }
8 |
--------------------------------------------------------------------------------
/src/Main.java:
--------------------------------------------------------------------------------
1 | public class Main {
2 | public static void main(String[] args) {
3 | System.out.println("Hello world!");
4 |
5 | double i = 5d / 0d;
6 | System.out.println(i);
7 | }
8 | }
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/main/java/day05/forms/Square.java:
--------------------------------------------------------------------------------
1 | package main.java.day05.forms;
2 |
3 | public class Square extends Rectangle {
4 | public Square(double sideA, double sideB) {
5 | super(sideA, sideB);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/main/java/day05/forms/Circle.java:
--------------------------------------------------------------------------------
1 | package main.java.day05.forms;
2 |
3 | public class Circle implements CalculableArea {
4 | //attributes
5 | private double radius;
6 |
7 | public Circle(double radius) {
8 | this.radius = radius;
9 | }
10 |
11 | @Override
12 | public double calculateArea() {
13 | return Math.pow(this.radius, 2) * Math.PI;
14 | }
15 |
16 | public double getRadius() {
17 | return radius;
18 | }
19 |
20 | public void setRadius(double radius) {
21 | this.radius = radius;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/test/java/day05/SquareTest.java:
--------------------------------------------------------------------------------
1 | package test.java.day05;
2 |
3 | import main.java.day05.forms.Square;
4 | import org.junit.jupiter.api.Assertions;
5 | import org.junit.jupiter.api.BeforeEach;
6 | import org.junit.jupiter.api.Test;
7 |
8 | class SquareTest {
9 | private Square square;
10 | @BeforeEach
11 | void setUp() {
12 | square = new Square(4d, 4d);
13 | }
14 |
15 | @Test
16 | void shouldCalculateSquareArea_ThenReturnResult() {
17 | //given
18 | //when
19 | double actual = square.calculateArea();
20 | //then
21 | double expected = 16d;
22 | Assertions.assertEquals(expected, actual);
23 | }
24 | }
--------------------------------------------------------------------------------
/src/main/java/day02/Calculator.java:
--------------------------------------------------------------------------------
1 | package main.java.day02;
2 |
3 | public class Calculator {
4 | public static double calculate(double value1, double value2, char sign) {
5 | if (sign == '+') {
6 | return value1 + value2;
7 | } else if (sign == '-') {
8 | return value1 - value2;
9 | } else if (sign == '*') {
10 | return value1 * value2;
11 | } else if (sign == '/') {
12 | if (value2 == 0) {
13 | throw new ArithmeticException("Division impossible!");
14 | }
15 | return value1 / value2;
16 | } else {
17 | throw new RuntimeException("This sign " + sign + " is invalid!");
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/test/java/day05/RectangleTest.java:
--------------------------------------------------------------------------------
1 | package test.java.day05;
2 |
3 | import main.java.day05.forms.Rectangle;
4 | import org.junit.jupiter.api.Assertions;
5 | import org.junit.jupiter.api.BeforeEach;
6 | import org.junit.jupiter.api.Test;
7 |
8 | class RectangleTest {
9 | private Rectangle rectangle;
10 | @BeforeEach
11 | void setUp() {
12 | rectangle = new Rectangle(4d, 6d);
13 | }
14 |
15 | @Test
16 | void shouldCalculateRectangleArea_ThenReturnResult() {
17 | //given
18 | //when
19 | double actual = rectangle.calculateArea();
20 | //then
21 | double expected = 24d;
22 | Assertions.assertEquals(expected, actual);
23 | }
24 | }
--------------------------------------------------------------------------------
/src/test/java/day05/TrapezeTest.java:
--------------------------------------------------------------------------------
1 | package test.java.day05;
2 |
3 | import main.java.day05.forms.Trapeze;
4 | import org.junit.jupiter.api.Assertions;
5 | import org.junit.jupiter.api.BeforeEach;
6 | import org.junit.jupiter.api.Test;
7 |
8 | class TrapezeTest {
9 | //attributes
10 | private Trapeze trapeze;
11 |
12 | @BeforeEach
13 | void setUp() {
14 | trapeze = new Trapeze(12, 20, 15);
15 | }
16 |
17 | @Test
18 | void shouldCalculateTrapezeArea_ThenReturnResult() {
19 | //given
20 | //when
21 | double actual = trapeze.calculateArea();
22 | //then
23 | double expected = 240d;
24 | Assertions.assertEquals(expected, actual);
25 | }
26 | }
--------------------------------------------------------------------------------
/src/test/java/day01/InvoiceTest.java:
--------------------------------------------------------------------------------
1 | package test.java.day01;
2 |
3 | import main.java.day01.Invoice;
4 | import org.junit.jupiter.api.Assertions;
5 | import org.junit.jupiter.api.BeforeEach;
6 | import org.junit.jupiter.api.Test;
7 |
8 | import java.math.BigDecimal;
9 |
10 | class InvoiceTest {
11 | private Invoice invoice;
12 |
13 | @BeforeEach
14 | void setup() {
15 | this.invoice = new Invoice(123L, "Description Item", 3, BigDecimal.TEN);
16 | }
17 |
18 | @Test
19 | void shouldReturnInvoiceAmount() {
20 | //given
21 | //when
22 | BigDecimal actual = this.invoice.getInvoiceAmount();
23 | //then
24 | BigDecimal expected = BigDecimal.valueOf(30);
25 | Assertions.assertEquals(expected, actual);
26 | }
27 | }
--------------------------------------------------------------------------------
/src/main/java/day05/forms/Rectangle.java:
--------------------------------------------------------------------------------
1 | package main.java.day05.forms;
2 |
3 | public class Rectangle implements CalculableArea {
4 | //attributes
5 | protected double sideA;
6 | protected double sideB;
7 |
8 | public Rectangle(double sideA, double sideB) {
9 | this.sideA = sideA;
10 | this.sideB = sideB;
11 | }
12 |
13 | @Override
14 | public double calculateArea() {
15 | return sideA * sideB;
16 | }
17 |
18 | public double getSideA() {
19 | return sideA;
20 | }
21 |
22 | public void setSideA(double sideA) {
23 | this.sideA = sideA;
24 | }
25 |
26 | public double getSideB() {
27 | return sideB;
28 | }
29 |
30 | public void setSideB(double sideB) {
31 | this.sideB = sideB;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/test/java/day01/ClientTest.java:
--------------------------------------------------------------------------------
1 | package test.java.day01;
2 |
3 | import main.java.day01.Client;
4 | import org.junit.jupiter.api.Assertions;
5 | import org.junit.jupiter.api.BeforeEach;
6 | import org.junit.jupiter.api.Test;
7 |
8 | import java.time.LocalDate;
9 | import java.time.Month;
10 |
11 | class ClientTest {
12 | private Client client;
13 |
14 | @BeforeEach
15 | void setUp() {
16 | client = new Client();
17 | }
18 |
19 | @Test
20 | void shouldReturnCurrentAge() {
21 | //given
22 | LocalDate birthDay = LocalDate.of(1994, Month.JANUARY, 13);
23 | client.setBirthDate(birthDay);
24 | //when
25 | int actual = client.calculateAge();
26 | //then
27 | int expected = 28;
28 | Assertions.assertEquals(actual, expected);
29 | }
30 | }
--------------------------------------------------------------------------------
/src/test/java/day02/EmployeeTest.java:
--------------------------------------------------------------------------------
1 | package test.java.day02;
2 |
3 | import main.java.day02.Employee;
4 | import org.junit.jupiter.api.Assertions;
5 | import org.junit.jupiter.api.BeforeEach;
6 | import org.junit.jupiter.api.Test;
7 |
8 | import java.math.BigDecimal;
9 |
10 | import static org.junit.jupiter.api.Assertions.*;
11 |
12 | class EmployeeTest {
13 | private Employee employee;
14 |
15 | @BeforeEach
16 | void setUp() {
17 | this.employee = new Employee("Cami", BigDecimal.valueOf(100));
18 | }
19 |
20 | @Test
21 | void shouldReturnSalaryWithIncrement() {
22 | //given
23 | double percentualIncrement = 10;
24 | //when
25 | BigDecimal actual = this.employee.incremetSalary(percentualIncrement);
26 | //then
27 | BigDecimal expected = BigDecimal.valueOf(110.0);
28 | Assertions.assertEquals(expected, actual);
29 | }
30 | }
--------------------------------------------------------------------------------
/src/test/java/day05/CircleTest.java:
--------------------------------------------------------------------------------
1 | package test.java.day05;
2 |
3 | import main.java.day05.forms.Circle;
4 | import org.junit.jupiter.api.Assertions;
5 | import org.junit.jupiter.api.BeforeEach;
6 | import org.junit.jupiter.api.Test;
7 |
8 | import java.text.DecimalFormat;
9 |
10 | class CircleTest {
11 | //attributes
12 | private Circle circle;
13 |
14 | @BeforeEach
15 | void setUp() {
16 | circle = new Circle(3d);
17 | }
18 |
19 | @Test
20 | void shouldCalculateCircleArea_ThenReturnResult() {
21 | //given
22 | DecimalFormat df = new DecimalFormat("#.00");
23 | //when
24 | double actual = circle.calculateArea();
25 | String actualFormat = df.format(actual);
26 | //then
27 | double expected = 28.27;
28 | String expectedFormat = df.format(expected);
29 | Assertions.assertEquals(expectedFormat, actualFormat);
30 | }
31 | }
--------------------------------------------------------------------------------
/src/main/java/day05/bank/Account.java:
--------------------------------------------------------------------------------
1 | package main.java.day05.bank;
2 |
3 | import java.math.BigDecimal;
4 |
5 | public class Account {
6 | //attributes
7 | private int number;
8 | private BigDecimal balance;
9 |
10 | public void toWithdraw(BigDecimal value) {
11 | if(value.compareTo(BigDecimal.ZERO) <= 0 || this.balance.compareTo(value) <= -1) {
12 | throw new IllegalArgumentException("Invalid value to withdraw");
13 | } else {
14 | this.balance = this.balance.subtract(value);
15 | }
16 | }
17 |
18 | public void toDeposit(BigDecimal value) {
19 | if(value.compareTo(BigDecimal.ZERO) <= 0) {
20 | throw new IllegalArgumentException("Invalid value to deposit");
21 | } else {
22 | this.balance = this.balance.add(value);
23 | }
24 | }
25 |
26 | public BigDecimal getBalance() {
27 | return balance;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/day02/Employee.java:
--------------------------------------------------------------------------------
1 | package main.java.day02;
2 |
3 | import java.math.BigDecimal;
4 |
5 | public class Employee {
6 | //attribute
7 | private String name;
8 | private BigDecimal salary;
9 |
10 | //constructor method
11 | public Employee(String name, BigDecimal salary) {
12 | this.name = name;
13 | this.salary = salary;
14 | }
15 |
16 | //methods
17 | public BigDecimal incremetSalary(double percentageIncrease) {
18 | BigDecimal percentagemIncreaseBigDecimal = BigDecimal.valueOf(1 + (percentageIncrease / 100));
19 | return this.salary.multiply(percentagemIncreaseBigDecimal);
20 | }
21 | public String getName() {
22 | return name;
23 | }
24 |
25 | public void setName(String name) {
26 | this.name = name;
27 | }
28 |
29 | public BigDecimal getSalary() {
30 | return salary;
31 | }
32 |
33 | public void setSalary(BigDecimal salary) {
34 | this.salary = salary;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/day04/BankAccount.java:
--------------------------------------------------------------------------------
1 | package main.java.day04;
2 |
3 | import java.math.BigDecimal;
4 |
5 | public abstract class BankAccount {
6 | //attributes
7 | private String number;
8 | private String nameCustomer;
9 | private BigDecimal balance;
10 |
11 | //methods
12 | public abstract void toWithdraw(BigDecimal value);
13 |
14 | public abstract void toDeposit(BigDecimal value);
15 |
16 | public String getNumber() {
17 | return number;
18 | }
19 |
20 | protected void setNumber(String number) {
21 | this.number = number;
22 | }
23 |
24 | public String getNameCustomer() {
25 | return nameCustomer;
26 | }
27 |
28 | protected void setNameCustomer(String nameCustomer) {
29 | this.nameCustomer = nameCustomer;
30 | }
31 |
32 | public BigDecimal getBalance() {
33 | return balance;
34 | }
35 |
36 | protected void setBalance(BigDecimal balance) {
37 | this.balance = balance;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/test/java/day05/FormsTest.java:
--------------------------------------------------------------------------------
1 | package test.java.day05;
2 |
3 | import main.java.day05.forms.*;
4 | import org.junit.jupiter.api.Assertions;
5 | import org.junit.jupiter.api.BeforeEach;
6 | import org.junit.jupiter.api.Test;
7 |
8 | public class FormsTest {
9 | private Rectangle rectangle;
10 | private Square square;
11 | private Circle circle;
12 | private Trapeze trapeze;
13 |
14 | @BeforeEach
15 | void setUp() {
16 | rectangle = new Rectangle(4d, 6d);
17 | square = new Square(4d, 4d);
18 | circle = new Circle(3d);
19 | trapeze = new Trapeze(12d, 20d, 15d);
20 | }
21 |
22 | @Test
23 | void shouldCreateArrayWithAllForms() {
24 | //given
25 | //when
26 | CalculableArea[] forms = {this.rectangle, this.square, this.circle, this.trapeze};
27 | CalculableArea actual = forms[2];
28 | //then
29 | CalculableArea expected = this.circle;
30 | Assertions.assertEquals(expected, actual);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/day05/forms/Trapeze.java:
--------------------------------------------------------------------------------
1 | package main.java.day05.forms;
2 |
3 | public class Trapeze implements CalculableArea {
4 | //attributes
5 | private double baseA;
6 | private double baseB;
7 | private double height;
8 |
9 | public Trapeze(double baseA, double baseB, double height) {
10 | this.baseA = baseA;
11 | this.baseB = baseB;
12 | this.height = height;
13 | }
14 |
15 | @Override
16 | public double calculateArea() {
17 | return ((this.baseA + this.baseB)/2) * this.height;
18 | }
19 |
20 | public double getBaseA() {
21 | return baseA;
22 | }
23 |
24 | public void setBaseA(double baseA) {
25 | this.baseA = baseA;
26 | }
27 |
28 | public double getBaseB() {
29 | return baseB;
30 | }
31 |
32 | public void setBaseB(double baseB) {
33 | this.baseB = baseB;
34 | }
35 |
36 | public double getHeight() {
37 | return height;
38 | }
39 |
40 | public void setHeight(double height) {
41 | this.height = height;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/day02/Tv.java:
--------------------------------------------------------------------------------
1 | package main.java.day02;
2 |
3 | public class Tv {
4 | //attributes
5 | private int channelNumber;
6 | private int volume;
7 |
8 | //construct method
9 | public Tv(int channelNumber) {
10 | this.channelNumber = channelNumber;
11 | this.volume = 5;
12 | }
13 |
14 | //methods
15 | public void turnUpVolume() {
16 | this.volume++;
17 | if(this.volume > 10) {
18 | this.volume = 10;
19 | throw new RuntimeException("It's already at full volume");
20 | }
21 | }
22 |
23 | public void turnDownVolume() {
24 | this.volume--;
25 | if(this.volume < 0) {
26 | this.volume = 0;
27 | throw new RuntimeException("It's already at minimum volume");
28 | }
29 | }
30 |
31 | public int getChannelNumber() {
32 | return channelNumber;
33 | }
34 |
35 | public void setChannelNumber(int channelNumber) {
36 | this.channelNumber = channelNumber;
37 | }
38 |
39 | public int getVolume() {
40 | return volume;
41 | }
42 |
43 | public void setVolume(int volume) {
44 | this.volume = volume;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/day03/Monkey.java:
--------------------------------------------------------------------------------
1 | package main.java.day03;
2 |
3 | import main.java.day03.enums.Fruit;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | public class Monkey {
9 | //attributes
10 | private String name;
11 | private List