Skip to content

Commit

Permalink
maps.homework package
Browse files Browse the repository at this point in the history
  • Loading branch information
kacper-cholewinski committed Dec 7, 2024
1 parent 4269b96 commit 08364ec
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 0 deletions.
19 changes: 19 additions & 0 deletions kodilla-collections-advanced/build.gradle
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()
}
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 + '\'' +
'}';
}
}
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;
}
}
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());
}
}
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ include 'kodilla-intro'
include 'kodilla-basic-tests'
include 'kodilla-collections'
include 'kodilla-collections'
include 'kodilla-collections-advanced'

0 comments on commit 08364ec

Please sign in to comment.