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
Original file line number Diff line number Diff line change
@@ -1,38 +1,65 @@
package school.lemon.changerequest.java.container;

public class ContainerImpl implements Container{
private int INITIAL_ARRAY_SIZE = 10;
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need this variable ?

private int[] array;
private int size;

public ContainerImpl() {
this.array = new int[Container.INITIAL_ARRAY_SIZE];
this.size = 0;
Copy link
Member

Choose a reason for hiding this comment

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

size will be initialized as 0 by default

}

@Override
public int size() {
// TODO: please implement me
return 0;
return this.size;
}

@Override
public void clear() {
// TODO: please implement me
this.size = 0;
}

@Override
public Integer get(int index) {
// TODO: please implement me
return null;
if (index < 0 || index >= size)
return null;
return array[index];
}

@Override
public void add(int element) {
// TODO: please implement me
checkSize();
array[size++] = element;

}

@Override
public boolean add(int element, int index) {
// TODO: please implement me
return false;
if (index < 0 || index > size)
return false;
checkSize();
System.arraycopy(array, index, array, index + 1, size - index);
array[index] = element;
++size;
return true;
}

@Override
public boolean remove(int index) {
// TODO: please implement me
return false;
if (index < 0 || index >= size)
return false;
System.arraycopy(array, index + 1, array, index, size - index - 1);
--size;
return true;
}

private void checkSize() {
if (size == array.length) {
int[] newArray = new int[array.length * 2];
System.arraycopy(array, 0, newArray, 0, array.length);
array = newArray;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,115 +5,136 @@
*/
public class ExtendedInteger {

private int value;

public ExtendedInteger(int value) {
//TODO: implement me
this.value = value;
}

/**
* Check whether specified value is even
*
* @param value to check
* @return true if value is even, false - otherwise
*/
public static boolean isEven(int value) {
//TODO: implement me
return false;
return value % 2 == 0;
}

/**
* Check whether specified value is odd
*
* @param value to check
* @return true if value is odd, false - otherwise
*/
public static boolean isOdd(int value) {
//TODO: implement me
return false;
return value % 2 != 0;
}

/**
* Check whether specified value is prime
*
* @param value to check
* @return true if value is prime, false - otherwise
*/
public static boolean isPrime(int value) {
//TODO: implement me
return false;
if (value < 2)
return false;
for (int i = 2; i * i <= value; i++)
if (value % i == 0)
return false;
return true;
}

/**
* Parse specified char array and create instance of {@code ExtendedInteger}
*
* @param value to parse
* @return instance of {@code ExtendedInteger} or
* null in case specified value is null or the value does not contain a parsable integer
*/
public static ExtendedInteger parseInt(char[] value) {
//TODO: implement me
if (value == null || value.length == 0)
return null;
String newValue = new String(value);
return ExtendedInteger.parseInt(newValue);
}

/**
* Parse specified string and create instance of {@code ExtendedInteger}
*
* @param value to parse
* @return instance of {@code ExtendedInteger} or
* null in case specified value is null or the value does not contain a parsable integer
*/
public static ExtendedInteger parseInt(String value) {
//TODO: implement me
if (value == null | value.length() == 0)
return null;
StringBuilder sb = new StringBuilder();
if (Character.isDigit(value.charAt(0)) || value.startsWith("-"))
sb = sb.append(value.charAt(0));
for (int i = 1; i < value.length(); i++) {
Copy link
Member

Choose a reason for hiding this comment

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

As far as I see, your implementation will correctly process smth like: G123 - where first character will be any symbol.

if (Character.isDigit(value.charAt(i))) {
sb = sb.append(value.charAt(i));
} else return null;
}
return new ExtendedInteger(new Integer(value));

}

/**
* Get int representation of {@code ExtendedInteger}
*
* @return int representation
*/
public int getValue() {
//TODO: implement me
return 0;
return value;
}

/**
* Check whether current value is even
*
* @return true if value is even, false - otherwise
*/
public boolean isEven() {
//TODO: implement me
return false;
return isEven(this.value);
}

/**
* Check whether current value is odd
*
* @return true if value is odd, false - otherwise
*/
public boolean isOdd() {
//TODO: implement me
return false;
return isOdd(this.value);
}

/**
* Check whether current value is prime
*
* @return true if value is prime, false - otherwise
*/
public boolean isPrime() {
//TODO: implement me
return false;
return isPrime(this.value);
}

/**
* Check whether current {@code ExtendedInteger} is equal to specified int value
*
* @return true if values are equal, false - otherwise
*/
public boolean equals(int value) {
//TODO: implement me
return false;
return this.value == value;
}

/**
* Check whether current {@code ExtendedInteger} is equal to specified object
*
* @return true if values are equal, false - otherwise
*/
@Override
public boolean equals(Object obj) {
//TODO: implement me
return false;
return obj != null && obj instanceof ExtendedInteger && this.value == ((ExtendedInteger) obj).value;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package school.lemon.changerequest.java.vehicles;

/**
* Created by Yaroslav Pavlinskiy on 04.12.2016.
*/
public class Airplane extends Vehicle implements IAirplane {
private int maximumHeightFeet;

public Airplane(int manufacturedYear, String make, String model, int maximumHeightFeet) {
super(manufacturedYear, make, model);
this.maximumHeightFeet = maximumHeightFeet;
}
Copy link
Member

Choose a reason for hiding this comment

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

You have got a lot of duplicated code: manufacturedYear, make and model as parameters of Airplane AND Car AND Boat, so it'll be better to move them into some abstract predecessor.

I'll not duplicate this comment, but it also applies to Bot and Car implementations.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed it



@Override
public int getManufacturedYear() {
return this.manufacturedYear;
}

@Override
public void setManufacturedYear(int year) {
this.manufacturedYear = year;
}

@Override
public String getMake() {
return this.make;
}

@Override
public void setMake(String make) {
this.make = make;
}

@Override
public String getModel() {
return this.model;
}

@Override
public void setModel(String model) {
this.model = model;
}

@Override
public int getMaximumHeightFeet() {
return this.maximumHeightFeet;
}

@Override
public void setMaximumHeightFeet(int maximumHeightFeet) {
this.maximumHeightFeet = maximumHeightFeet;
}

@Override
public String accelerate() {
return "fire engines on wings";
}

@Override
public String steerLeft() {
return "lift wing flaps to turn left";
}

@Override
public String steerRight() {
return "lift wing flaps to turn right";
}

@Override
public String toString() {
return String.format("This airplane is a %1$d %2$s %3$s that can reach %4$d feet.", this.getManufacturedYear(), this.getMake(), this.getModel(), this.getMaximumHeightFeet());
}

@Override
public boolean equals(Object obj) {
if (obj == null)
Copy link
Member

Choose a reason for hiding this comment

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

First check should be null-check.
After that - you should check if currect object is really Airplane and only then re-assign value.
Also, do not assign anything to the argument - create new object.

return false;
if (this == obj)
return true;
if (!(obj instanceof Airplane))
return false;
obj = (Airplane) obj;
if (this.getMaximumHeightFeet() + 1000 > ((Airplane) obj).getMaximumHeightFeet() || this.getMaximumHeightFeet() - 1000 < ((Airplane) obj).getMaximumHeightFeet())
return true;
return false;
}
}
Loading