Skip to content

Commit 5e0a972

Browse files
committed
Clean up methods in practice files
1 parent e146ca2 commit 5e0a972

12 files changed

+27
-141
lines changed

src/main/java/practice/streamapi/ConstructorReferencesDemo.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,6 @@
55

66
public class ConstructorReferencesDemo {
77

8-
static class Employee {
9-
String name;
10-
int age;
11-
int salary;
12-
Employee(String name) { this.name = name; }
13-
Employee(String name, int age, int salary) {
14-
this.name = name;
15-
this.age = age;
16-
this.salary = salary;
17-
}
18-
19-
public String getName() { return name; }
20-
public int getAge() { return age; }
21-
public int getSalary() { return salary; }
22-
23-
@Override
24-
public String toString() {
25-
return "Employee{" +
26-
"name='" + name + '\'' +
27-
", age=" + age +
28-
", salary=" + salary +
29-
'}';
30-
}
31-
}
32-
33-
public int getLength(String str) { return str.length(); }
34-
358
public static void main(String[] args) {
369
List<String> list = new ArrayList<>();
3710
list.add("we");

src/main/java/practice/streamapi/ConvertStringsToUppercase.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,8 @@
55

66
public class ConvertStringsToUppercase {
77

8-
public static List<String> convertToUppercase(List<String> strings) {
9-
return null;
10-
}
11-
128
public static void main(String[] args) {
13-
List<String> strings = List.of("apple", "banana", "orange", "pineapple", "grape");
14-
List<String> uppercaseStrings = convertToUppercase(strings);
15-
System.out.println("Uppercase strings: " + uppercaseStrings);
9+
1610
}
1711

1812
}

src/main/java/practice/streamapi/CountWordsLongerThan5Characters.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44

55
public class CountWordsLongerThan5Characters {
66

7-
public static long countWordsLongerThanFiveChars(List<String> words) {
8-
return -1;
9-
}
10-
117
public static void main(String[] args) {
12-
List<String> words = List.of("apple", "banana", "orange", "pineapple", "grape");
13-
long count = countWordsLongerThanFiveChars(words);
14-
System.out.println("Words longer than 5 characters: " + count);
8+
159
}
1610

1711
}

src/main/java/practice/streamapi/FilterEvenNumbers.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44

55
public class FilterEvenNumbers {
66

7-
public static List<Integer> filterEvenNumbers(List<Integer> numbers) {
8-
return null;
9-
}
10-
117
public static void main(String[] args) {
12-
List<Integer> numbers = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
13-
List<Integer> evenNumbers = filterEvenNumbers(numbers);
14-
System.out.println("Even numbers: " + evenNumbers);
8+
159
}
1610

1711
}

src/main/java/practice/streamapi/FindAverageAgeOfEmployeesByDepartment.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,10 @@
44
import java.util.Map;
55
import java.util.stream.Collectors;
66

7-
class Employee {
8-
private final String name;
9-
private final int age;
10-
private final String title;
11-
public Employee(String name, int age, String title) {
12-
this.name = name;
13-
this.age = age;
14-
this.title = title;
15-
}
16-
}
17-
187
public class FindAverageAgeOfEmployeesByDepartment {
198

20-
public static Map<String, Double> averageAgeByDepartment(List<Employee> employees) {
21-
return null;
22-
}
23-
249
public static void main(String[] args) {
25-
List<Employee> employees = List.of(
26-
new Employee("Alice", 25, "HR"),
27-
new Employee("Bob", 30, "Finance"),
28-
new Employee("Charlie", 28, "HR"),
29-
new Employee("David", 35, "Finance")
30-
);
3110

32-
Map<String, Double> averageAgeByDept = averageAgeByDepartment(employees);
33-
averageAgeByDept.forEach((dept, avgAge) ->
34-
System.out.println("Average age in " + dept + ": " + avgAge));
3511
}
3612

3713
}

src/main/java/practice/streamapi/FindMinimumAndMaximumNumbers.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@
55

66
public class FindMinimumAndMaximumNumbers {
77

8-
public static void findMinMax(List<Integer> numbers) {
9-
10-
}
11-
128
public static void main(String[] args) {
13-
List<Integer> numbers = List.of(3, 6, 2, 8, 4, 9, 1);
14-
findMinMax(numbers);
9+
1510
}
1611

1712
}

src/main/java/practice/streamapi/FindMostFrequentWordsInListOfSentences.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77

88
public class FindMostFrequentWordsInListOfSentences {
99

10-
public static List<String> mostFrequentWords(List<String> sentences) {
11-
return null;
12-
}
13-
1410
public static void main(String[] args) {
1511
List<String> sentences = List.of(
1612
"Java is a programming language",
@@ -19,8 +15,8 @@ public static void main(String[] args) {
1915
"Java and Python are popular languages"
2016
);
2117

22-
List<String> frequentWords = mostFrequentWords(sentences);
23-
System.out.println("Most frequent words: " + frequentWords);
18+
// List<String> frequentWords = mostFrequentWords(sentences);
19+
// System.out.println("Most frequent words: " + frequentWords);
2420
}
2521

2622
}

src/main/java/practice/streamapi/FindSumOfSquares.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44

55
public class FindSumOfSquares {
66

7-
public static int sumOfSquares(List<Integer> numbers) {
8-
return -1;
9-
}
10-
117
public static void main(String[] args) {
12-
List<Integer> numbers = List.of(1, 2, 3, 4, 5);
13-
int sum = sumOfSquares(numbers);
14-
System.out.println("Sum of squares: " + sum);
8+
// List<Integer> numbers = List.of(1, 2, 3, 4, 5);
9+
// int sum = sumOfSquares(numbers);
10+
// System.out.println("Sum of squares: " + sum);
1511
}
1612

1713
}

src/main/java/practice/streamapi/FlattenNestedLists.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@
55

66
public class FlattenNestedLists {
77

8-
public static List<Integer> flattenNestedLists(List<List<Integer>> nestedLists) {
9-
return null;
10-
}
11-
128
public static void main(String[] args) {
139
List<List<Integer>> nestedLists = new ArrayList<>();
1410
nestedLists.add(List.of(1, 2, 3));
1511
nestedLists.add(List.of(4, 5));
1612
nestedLists.add(List.of(6, 7, 8));
1713

18-
List<Integer> flattenedList = flattenNestedLists(nestedLists);
19-
System.out.println("Flattened list: " + flattenedList);
14+
// List<Integer> flattenedList = flattenNestedLists(nestedLists);
15+
// System.out.println("Flattened list: " + flattenedList);
2016
}
2117

2218
}

src/main/java/practice/streamapi/GroupStudentsByAge.java

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,22 @@
44
import java.util.Map;
55
import java.util.stream.Collectors;
66

7-
class Student {
8-
9-
private final String name;
10-
private final int age;
11-
12-
public Student(String name, int age) {
13-
this.name = name;
14-
this.age = age;
15-
}
16-
17-
public String getName() {
18-
return name;
19-
}
20-
21-
public int getAge() {
22-
return age;
23-
}
24-
25-
}
26-
277
public class GroupStudentsByAge {
288

29-
public static Map<Integer, List<Student>> groupStudentsByAge(List<Student> students) {
30-
return null;
31-
}
32-
339
public static void main(String[] args) {
34-
List<Student> students = List.of(
35-
new Student("Alice", 20),
36-
new Student("Bob", 22),
37-
new Student("Charlie", 20),
38-
new Student("David", 22)
39-
);
40-
41-
Map<Integer, List<Student>> groupedByAge = groupStudentsByAge(students);
42-
groupedByAge.forEach((age, studentList) -> {
43-
System.out.println("Age " + age + ": " + studentList.stream()
44-
.map(Student::getName)
45-
.toList());
46-
});
10+
// List<Student> students = List.of(
11+
// new Student("Alice", 20),
12+
// new Student("Bob", 22),
13+
// new Student("Charlie", 20),
14+
// new Student("David", 22)
15+
// );
16+
//
17+
// Map<Integer, List<Student>> groupedByAge = groupStudentsByAge(students);
18+
// groupedByAge.forEach((age, studentList) -> {
19+
// System.out.println("Age " + age + ": " + studentList.stream()
20+
// .map(Student::getName)
21+
// .toList());
22+
// });
4723
}
4824

4925
}

0 commit comments

Comments
 (0)