Skip to content
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

created abstract class Machine with 2 abstract methods. Abstract meth… #1596

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
36 changes: 18 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: Java CI

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
cache: maven
- name: Build with Maven
run: mvn --batch-mode --update-snapshots verify
name: Java CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
cache: maven
- name: Build with Maven
run: mvn --batch-mode --update-snapshots verify
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea/*
*.iml
target/*
.idea/*
*.iml
target/*
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# jv-oop

- Create class Machine containing methods `public abstract void doWork()` and `public abstract void stopWork()`.
- Create classes `Truck`, `Bulldozer`, `Excavator` that will inherit from `Machine`.
- In those classes override `doWork()`, so it will print message that certain machine started its work.
- Override `stopWork()` as well. It should print messages that certain machine stopped its work.
- In `MainApp` class create `Machine` array with `Truck`, `Bulldozer` and `Excavator` and call methods `doWork()` and `stopWork()` in a loop.

#### [Try to avoid these common mistakes, while solving task](https://mate-academy.github.io/jv-program-common-mistakes/java-core/oop/oop)
# jv-oop
- Create class Machine containing methods `public abstract void doWork()` and `public abstract void stopWork()`.
- Create classes `Truck`, `Bulldozer`, `Excavator` that will inherit from `Machine`.
- In those classes override `doWork()`, so it will print message that certain machine started its work.
- Override `stopWork()` as well. It should print messages that certain machine stopped its work.
- In `MainApp` class create `Machine` array with `Truck`, `Bulldozer` and `Excavator` and call methods `doWork()` and `stopWork()` in a loop.
#### [Try to avoid these common mistakes, while solving task](https://mate-academy.github.io/jv-program-common-mistakes/java-core/oop/oop)
98 changes: 49 additions & 49 deletions checklist.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
## Common mistakes (jv-oop)

#### Please don't add redundant empty lines to your code.
We don't need them after class declaration or method signature.
* Bad example:
```
public class Main {

public static void main(String[] args) {

System.out.println("Hello world!");
}
}
```
* Improved example:
```
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
```

#### Write informative messages in methods.
Use english only and make them informative:
message should indicate what type of `Machine` is working right now `Truck`, `Bulldozer` or `Excavator`.

#### Use abstract reference instead of specific one where possible:
* Bad example:
```
Cat fluffy = new Cat();
Dog oscar = new Dog();
```
This example is bad cause it won't allow us to use polymorphism in our code.
Our reference is now bonded to specific implementation, but it is always better to depend on the abstraction.
Let's see how we can improve it:
* Improved example:
```
Animal fluffy = new Cat();
Animal oscar = new Dog();
```

#### Depending on the case, class elements should have different access modifiers
Remember that if you don't use any access modifiers that will apply the default one. Do we always want
to have all elements with default access modifiers? Remind yourself about encapsulation principle and
when private or public should be used.

#### Write informative messages when you commit code or open a PR.
Bad example of commit/PR message: `done`/`fixed`/`commit`/`solution`/`added homework`/`my solution` and other one-word, abstract or random messages.
## Common mistakes (jv-oop)
#### Please don't add redundant empty lines to your code.
We don't need them after class declaration or method signature.
* Bad example:
```
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
```
* Improved example:
```
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
```
#### Write informative messages in methods.
Use english only and make them informative:
message should indicate what type of `Machine` is working right now `Truck`, `Bulldozer` or `Excavator`.
#### Use abstract reference instead of specific one where possible:
* Bad example:
```
Cat fluffy = new Cat();
Dog oscar = new Dog();
```
This example is bad cause it won't allow us to use polymorphism in our code.
Our reference is now bonded to specific implementation, but it is always better to depend on the abstraction.
Let's see how we can improve it:
* Improved example:
```
Animal fluffy = new Cat();
Animal oscar = new Dog();
```
#### Depending on the case, class elements should have different access modifiers
Remember that if you don't use any access modifiers that will apply the default one. Do we always want
to have all elements with default access modifiers? Remind yourself about encapsulation principle and
when private or public should be used.
#### Write informative messages when you commit code or open a PR.
Bad example of commit/PR message: `done`/`fixed`/`commit`/`solution`/`added homework`/`my solution` and other one-word, abstract or random messages.
136 changes: 68 additions & 68 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
<?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>mate-academy</groupId>
<artifactId>oop-example</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<jdk.version>11</jdk.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.checkstyle.plugin.version>3.1.1</maven.checkstyle.plugin.version>
<maven.checkstyle.plugin.configLocation>
https://raw.githubusercontent.com/mate-academy/style-guides/master/java/checkstyle.xml
</maven.checkstyle.plugin.configLocation>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<configLocation>${maven.checkstyle.plugin.configLocation}</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

<?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>mate-academy</groupId>
<artifactId>oop-example</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<jdk.version>11</jdk.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.checkstyle.plugin.version>3.1.1</maven.checkstyle.plugin.version>
<maven.checkstyle.plugin.configLocation>
https://raw.githubusercontent.com/mate-academy/style-guides/master/java/checkstyle.xml
</maven.checkstyle.plugin.configLocation>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<configLocation>${maven.checkstyle.plugin.configLocation}</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
13 changes: 13 additions & 0 deletions src/main/java/core/basesyntax/Buldozzer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package core.basesyntax;

public class Buldozzer extends Machine {
@Override
public void doWork() {
System.out.println("Buldozzer started working");
}

@Override
public void stopWork() {
System.out.println("Buldozzer stopped working");
}
}
13 changes: 13 additions & 0 deletions src/main/java/core/basesyntax/Excavator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package core.basesyntax;

public class Excavator extends Machine {
@Override
public void doWork() {
System.out.println("Excavator started working");
}

@Override
public void stopWork() {
System.out.println("Excavator stopped working");
}
}
8 changes: 8 additions & 0 deletions src/main/java/core/basesyntax/Machine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package core.basesyntax;

public abstract class Machine {

public abstract void doWork();

public abstract void stopWork();
}
17 changes: 12 additions & 5 deletions src/main/java/core/basesyntax/MainApp.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package core.basesyntax;

public class MainApp {

}
package core.basesyntax;

public class MainApp {
public static void main(String[] args) {
Machine [] machineGroup = {new Truck(), new Buldozzer(), new Excavator()};

for (Machine machine : machineGroup) {
machine.doWork();
machine.stopWork();
}
}
}
13 changes: 13 additions & 0 deletions src/main/java/core/basesyntax/Truck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package core.basesyntax;

public class Truck extends Machine {
@Override
public void doWork() {
System.out.println("Truck started working");
}

@Override
public void stopWork() {
System.out.println("Truck stopped working");
}
}
8 changes: 4 additions & 4 deletions src/test/java/core/basesyntax/MainAppTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package core.basesyntax;

public class MainAppTest {

package core.basesyntax;
public class MainAppTest {
}
Loading