File tree Expand file tree Collapse file tree 4 files changed +84
-0
lines changed Expand file tree Collapse file tree 4 files changed +84
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : format and commit all java files
2
+
3
+ on :
4
+ workflow_dispatch :
5
+ push :
6
+ branches :
7
+ - ' exercises/**'
8
+ - ' solutions/**'
9
+
10
+ jobs :
11
+ formatting :
12
+ runs-on : ubuntu-latest
13
+ steps :
14
+ - uses : actions/checkout@v2
15
+ - uses : actions/setup-java@v3
16
+ with :
17
+ java-version : ' 17'
18
+ distribution : ' temurin'
19
+ - uses : axel-op/googlejavaformat-action@v3
Original file line number Diff line number Diff line change
1
+ # Compiled class file
2
+ * .class
3
+
4
+ # Log file
5
+ * .log
6
+
7
+ # BlueJ files
8
+ * .ctxt
9
+
10
+ # Mobile Tools for Java (J2ME)
11
+ .mtj.tmp /
12
+
13
+ # Package Files #
14
+ * .jar
15
+ * .war
16
+ * .nar
17
+ * .ear
18
+ * .zip
19
+ * .tar.gz
20
+ * .rar
21
+
22
+ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23
+ hs_err_pid *
Original file line number Diff line number Diff line change
1
+ public class Exercise {
2
+
3
+ public static void main (String [] args ) {
4
+ TelephoneBook telephoneBook = new TelephoneBook ();
5
+
6
+ telephoneBook .addEntry (
7
+ new TelephoneBook .Person ("Hans Maier" ),
8
+ new TelephoneBook .TelephoneNumber ("+49 67234 887261" ));
9
+ telephoneBook .addEntry (
10
+ new TelephoneBook .Person ("Peter Mueller" ),
11
+ new TelephoneBook .TelephoneNumber ("+49 7529 87612" ));
12
+ telephoneBook .addEntry (
13
+ new TelephoneBook .Person ("Lisa Schmidt" ),
14
+ new TelephoneBook .TelephoneNumber ("+49 8762 52081" ));
15
+
16
+ System .out .println (telephoneBook .getTelephoneNumberByName ("Hans Maier" ));
17
+ }
18
+ }
Original file line number Diff line number Diff line change
1
+ import java .util .HashMap ;
2
+ import java .util .Map .Entry ;
3
+
4
+ public class TelephoneBook {
5
+
6
+ private HashMap <Person , TelephoneNumber > entries = new HashMap <>();
7
+
8
+ public void addEntry (Person person , TelephoneNumber telephoneNumber ) {
9
+ entries .put (person , telephoneNumber );
10
+ }
11
+
12
+ public TelephoneNumber getTelephoneNumberByName (String name ) {
13
+ for (Entry <Person , TelephoneNumber > entry : entries .entrySet ()) {
14
+ if (entry .getKey ().name ().equals (name )) {
15
+ return entry .getValue ();
16
+ }
17
+ }
18
+ return null ;
19
+ }
20
+
21
+ public record Person (String name ) {}
22
+
23
+ public record TelephoneNumber (String value ) {}
24
+ }
You can’t perform that action at this time.
0 commit comments