-
Notifications
You must be signed in to change notification settings - Fork 9
Task Vehicles done. #2
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
base: master
Are you sure you want to change the base?
Changes from all commits
12fb49e
13f126a
9cd925c
44e7a0a
e521baf
b0ce726
3d9a567
6acaed7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| private int[] array; | ||
| private int size; | ||
|
|
||
| public ContainerImpl() { | ||
| this.array = new int[Container.INITIAL_ARRAY_SIZE]; | ||
| this.size = 0; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| @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 |
|---|---|---|
|
|
@@ -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++) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I see, your implementation will correctly process smth like: |
||
| 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; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have got a lot of duplicated code: I'll not duplicate this comment, but it also applies to Bot and Car implementations.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First check should be |
||
| 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; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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 ?