Skip to content

Commit 311a58f

Browse files
committed
Виконані завдання з java-fundamentals-exercises
1 parent 707802e commit 311a58f

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

0-0-intro/src/main/java/com/bobocode/intro/ExerciseIntroduction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public class ExerciseIntroduction {
2424
*/
2525
public String getWelcomeMessage() {
2626
// todo: implement a method and return a message according to javadoc
27-
throw new ExerciseNotCompletedException();
27+
return "The key to efficient learning is practice!";
28+
2829
}
2930

3031
/**

1-0-java-basics/1-3-0-hello-generics/src/main/java/com/bobocode/basics/Box.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
* <p>
88
* todo: refactor this class so it uses generic type "T" and run {@link com.bobocode.basics.BoxTest} to verify it
99
*/
10-
public class Box {
11-
private Object value;
10+
public class Box<T> {
11+
private T value;
1212

13-
public Box(Object value) {
13+
public Box(T value) {
1414
this.value = value;
1515
}
1616

17-
public Object getValue() {
17+
public T getValue() {
1818
return value;
1919
}
2020

21-
public void setValue(Object value) {
21+
public void setValue(T value) {
2222
this.value = value;
2323
}
2424
}

1-0-java-basics/1-3-0-hello-generics/src/main/java/com/bobocode/basics/BoxDemoApp.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
*/
1010
public class BoxDemoApp {
1111
public static void main(String[] args) {
12-
Box intBox = new Box(123);
13-
Box intBox2 = new Box(321);
14-
System.out.println((int) intBox.getValue() + (int) intBox2.getValue());
12+
Box<Integer> intBox = new Box<>(123);
13+
Box<Integer> intBox2 = new Box<>(321);
14+
System.out.println(intBox.getValue() + intBox2.getValue());
1515

1616
intBox.setValue(222);
1717
intBox.setValue("abc"); // this should not be allowed
1818
// the following code will compile, but will throw runtime exception
1919
System.out.println((int) intBox.getValue() + (int) intBox2.getValue());
20+
2021
}
2122
}

0 commit comments

Comments
 (0)