-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4269b96
commit 08364ec
Showing
5 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
plugins { | ||
id 'java' | ||
} | ||
|
||
group = 'com.kodilla' | ||
version = '1.0-SNAPSHOT' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation platform('org.junit:junit-bom:5.10.0') | ||
testImplementation 'org.junit.jupiter:junit-jupiter' | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} |
42 changes: 42 additions & 0 deletions
42
...llections-advanced/src/main/java/com/kodilla/collections/adv/maps/homework/Principal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.kodilla.collections.adv.maps.homework; | ||
|
||
import java.util.Objects; | ||
|
||
public class Principal { | ||
String firstName; | ||
String lastName; | ||
|
||
public Principal(String firstName, String lastName) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Principal principal = (Principal) o; | ||
return Objects.equals(firstName, principal.firstName) && Objects.equals(lastName, principal.lastName); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(firstName, lastName); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Principal{" + | ||
"firstName='" + firstName + '\'' + | ||
", lastName='" + lastName + '\'' + | ||
'}'; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...-collections-advanced/src/main/java/com/kodilla/collections/adv/maps/homework/School.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.kodilla.collections.adv.maps.homework; | ||
|
||
import java.util.List; | ||
|
||
public class School { | ||
String name; | ||
List<Integer> classes; | ||
|
||
public School(String name, List<Integer> students) { | ||
this.name = name; | ||
this.classes = students; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public List<Integer> getStudents() { | ||
return classes; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "School{" + | ||
"name='" + name + '\'' + | ||
", students=" + classes + | ||
'}'; | ||
} | ||
|
||
public int getAllStudentsCount() { | ||
int studentsCount = 0; | ||
|
||
for (int students : classes) { | ||
studentsCount += students; | ||
} | ||
|
||
return studentsCount; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ons-advanced/src/main/java/com/kodilla/collections/adv/maps/homework/SchoolDirectory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.kodilla.collections.adv.maps.homework; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class SchoolDirectory { | ||
public static void main(String[] args) { | ||
HashMap<Principal, School> schools = new HashMap<>(); | ||
|
||
schools.put( | ||
new Principal("Omar", "Mccoy"), | ||
new School("Winters Secondary School", Arrays.asList(23, 22, 24)) | ||
); | ||
|
||
schools.put( | ||
new Principal("Charlotte", "Lawson"), | ||
new School("Pioneer Technical School", Arrays.asList(28, 31, 27)) | ||
); | ||
|
||
schools.put( | ||
new Principal("Sulaiman", "Macdonald"), | ||
new School("Silver Valley Academy", Arrays.asList(17, 14, 16)) | ||
); | ||
|
||
for (HashMap.Entry<Principal, School> school : schools.entrySet()) { | ||
System.out.println("Principal: " + school.getKey().getFirstName() + " " + school.getKey().getLastName()); | ||
System.out.println("School name: " + school.getValue().getName()); | ||
System.out.println("Number of students: " + school.getValue().getAllStudentsCount()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters