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

Pull_request_1 #918

Open
wants to merge 1 commit 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
28 changes: 28 additions & 0 deletions src/main/java/core/mate/academy/model/Bulldozer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,39 @@
* Do not remove no-args constructor
*/
public class Bulldozer extends Machine {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't begin class or method implementation with an empty line. Please remove the unnecessary empty lines (lines 3-6) to comply with the checklist.

private int bladeWidth;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget about access modifiers for your custom fields in Bulldozer class. It's a good practice to encapsulate fields using private access modifier and provide public getters and setters for accessing them.

private int operatingWeight;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget about access modifiers for your custom fields in Bulldozer class. It's a good practice to encapsulate fields using private access modifier and provide public getters and setters for accessing them.

private String engineType;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget about access modifiers for your custom fields in Bulldozer class. It's a good practice to encapsulate fields using private access modifier and provide public getters and setters for accessing them.


public Bulldozer() {
}

@Override
public void doWork() {
System.out.println("Bulldozer started to work");
}

public int getBladeWidth() {
return bladeWidth;
}

public void setBladeWidth(int bladeWidth) {
this.bladeWidth = bladeWidth;
}

public int getOperatingWeight() {
return operatingWeight;
}

public void setOperatingWeight(int operatingWeight) {
this.operatingWeight = operatingWeight;
}

public String getEngineType() {
return engineType;
}

public void setEngineType(String engineType) {
this.engineType = engineType;
}
}
28 changes: 28 additions & 0 deletions src/main/java/core/mate/academy/model/Excavator.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,39 @@
* Do not remove no-args constructor
*/
public class Excavator extends Machine {
private double bucketCapacity;
private int maxReach;
private String armType;

public Excavator() {
}

@Override
public void doWork() {
System.out.println("Excavator started to work");
}

public double getBucketCapacity() {
return bucketCapacity;
}

public void setBucketCapacity(double bucketCapacity) {
this.bucketCapacity = bucketCapacity;
}

public int getMaxReach() {
return maxReach;
}

public void setMaxReach(int maxReach) {
this.maxReach = maxReach;
}

public String getArmType() {
return armType;
}

public void setArmType(String armType) {
this.armType = armType;
}
}
28 changes: 28 additions & 0 deletions src/main/java/core/mate/academy/model/Truck.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,39 @@
* Do not remove no-field constructor
*/
public class Truck extends Machine {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget about access modifiers for your custom fields in Truck class. It's a good practice to make fields private and provide public getters and setters to access them, which you've done, but the fields themselves should also be declared as private to prevent direct access.

private int cargoCapacity;
private int numberOfAxles;
private String fuelType;

public Truck() {
}

@Override
public void doWork() {
System.out.println("Truck started to work");
}

public int getCargoCapacity() {
return cargoCapacity;
}

public void setCargoCapacity(int cargoCapacity) {
this.cargoCapacity = cargoCapacity;
}

public int getNumberOfAxles() {
return numberOfAxles;
}

public void setNumberOfAxles(int numberOfAxles) {
this.numberOfAxles = numberOfAxles;
}

public String getFuelType() {
return fuelType;
}

public void setFuelType(String fuelType) {
this.fuelType = fuelType;
}
}
12 changes: 12 additions & 0 deletions src/main/java/core/mate/academy/service/BulldozerProducer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package core.mate.academy.service;

import core.mate.academy.model.Bulldozer;
import java.util.List;

public class BulldozerProducer implements MachineProducer<Bulldozer> {

@Override
public List<Bulldozer> get() {
return List.of(new Bulldozer(), new Bulldozer(), new Bulldozer());
}
}
12 changes: 12 additions & 0 deletions src/main/java/core/mate/academy/service/ExcavatorProducer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package core.mate.academy.service;

import core.mate.academy.model.Excavator;
import java.util.List;

public class ExcavatorProducer implements MachineProducer<Excavator> {

@Override
public List<Excavator> get() {
return List.of(new Excavator(), new Excavator(), new Excavator());
}
}
5 changes: 3 additions & 2 deletions src/main/java/core/mate/academy/service/MachineProducer.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package core.mate.academy.service;

import core.mate.academy.model.Machine;
import java.util.List;

public interface MachineProducer {
public interface MachineProducer<T extends Machine> {
/**

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't begin class or method implementation with an empty line.

* In your implementations - create 2-3 models, add them to the list and return
* @return - the list of models
*/
List<Object> get();
List<T> get();
}
8 changes: 4 additions & 4 deletions src/main/java/core/mate/academy/service/MachineService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Parameterize this service and add its implementation in a separate class.
*/
public interface MachineService {
public interface MachineService<T> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't begin interface or method implementation with an empty line.


/**
* Return the list of machines.
Expand All @@ -16,7 +16,7 @@ public interface MachineService {
* @param type - any class of Machine sub class. For example: Truck.class or Bulldozer.class
* @return the list of machines
*/
List<Object> getAll(Class type);
List<T> getAll(Class<? extends T> type);

/**
* Fill the machines list with passed value
Expand All @@ -26,13 +26,13 @@ public interface MachineService {
* @param machines - list of machines to be filled with value
* @param value - any object of machine sub class
*/
void fill(List<Object> machines, Object value);
void fill(List<? super T> machines, T value);

/**
* Call the method doWork() from each machine.
* This method should be able to accept a list of bulldozers as well as list of trucks.
*
* @param machines - the list of machines
*/
void startWorking(List<Object> machines);
void startWorking(List<? extends T> machines);
}
41 changes: 40 additions & 1 deletion src/main/java/core/mate/academy/service/MachineServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
package core.mate.academy.service;

import core.mate.academy.model.Bulldozer;
import core.mate.academy.model.Excavator;
import core.mate.academy.model.Machine;
import core.mate.academy.model.Truck;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Your implementation of MachineService.
*/
public class MachineServiceImpl {
public class MachineServiceImpl implements MachineService<Machine> {
@Override
public List<Machine> getAll(Class<? extends Machine> type) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider creating a local variable in your implementation of getAll(Class type) method. This can help to improve the readability of the method and ensure that the returned list is a new list rather than a direct reference to the list obtained from the producer.

List<Machine> machineList = new ArrayList<>();

if (type == Bulldozer.class) {
BulldozerProducer bulldozerProducer = new BulldozerProducer();
machineList.addAll(bulldozerProducer.get());
}

if (type == Excavator.class) {
ExcavatorProducer excavatorProducer = new ExcavatorProducer();
machineList.addAll(excavatorProducer.get());
}

if (type == Truck.class) {
TruckProducer truckProducer = new TruckProducer();
machineList.addAll(truckProducer.get());
}
return machineList;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep if else constructions simple. Here, since each 'if' block contains a return statement, the subsequent 'if' statements can be changed to 'else if' to prevent unnecessary checks once a match is found.

}

@Override
public void fill(List<? super Machine> machines, Machine value) {
Collections.fill(machines, value);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size of a list passed to fill() method should remain the same. Just replace the old values with the new ones. The use of Collections.fill replaces all elements in the list with the specified value, which might not be the intended behavior if the list contains different types of Machines.


@Override
public void startWorking(List<? extends Machine> machines) {
machines.forEach(Machine::doWork);

}
}
Comment on lines +14 to 46

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't begin class or method implementation with empty lines (lines 11-13). It would be better to remove these to comply with the checklist.

12 changes: 12 additions & 0 deletions src/main/java/core/mate/academy/service/TruckProducer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package core.mate.academy.service;

import core.mate.academy.model.Truck;
import java.util.List;

public class TruckProducer implements MachineProducer<Truck> {

@Override
public List<Truck> get() {
return List.of(new Truck(), new Truck(), new Truck());
}
}
Loading