Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
010 added some sources for chapter 5, added a gradle compiler option …
…to try to get rid of the deprecation warnings
- Loading branch information
Showing
44 changed files
with
820 additions
and
97 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
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,7 @@ | ||
package com.apress.bgn.ch0; | ||
|
||
public class HelloWorld { | ||
public static void main(String[] args) { | ||
System.out.println("Hello World!"); | ||
} | ||
} |
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
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
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
45 changes: 45 additions & 0 deletions
45
chapter04/src/main/java/com/apress/bgn/ch4/basic/Actor.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,45 @@ | ||
package com.apress.bgn.ch4.basic; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author iuliana.cosmina | ||
* @date 11/04/2018 | ||
* @since 1.0 | ||
*/ | ||
public class Actor extends Human { | ||
|
||
private String actingSchool; | ||
|
||
private List<String> films; | ||
|
||
public Actor(String name, int age, float height, Gender gender, String actingSchool) { | ||
super(name, age, height, gender); | ||
this.actingSchool = actingSchool; | ||
} | ||
|
||
@Override | ||
public int getTimeToLive() { | ||
return LIFESPAN - getAge(); | ||
} | ||
|
||
public String getActingSchool() { | ||
return actingSchool; | ||
} | ||
|
||
public void setActingSchool(String actingSchool) { | ||
this.actingSchool = actingSchool; | ||
} | ||
|
||
public List<String> getFilms() { | ||
return films; | ||
} | ||
|
||
public void setFilms(List<String> films) { | ||
this.films = films; | ||
} | ||
|
||
public void addFilm(String filmName){ | ||
this.films.add(filmName); | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
chapter04/src/main/java/com/apress/bgn/ch4/basic/Gender.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,37 @@ | ||
package com.apress.bgn.ch4.basic; | ||
|
||
/** | ||
* @author iuliana.cosmina | ||
* @date 11/04/2018 | ||
* @since 1.0 | ||
*/ | ||
public enum Gender { | ||
FEMALE(1, "f"), | ||
MALE(2, "m") , | ||
UNDEFINED(3, "u"){ | ||
@Override | ||
public String comment() { | ||
return "to be decided later: " + getRepr() + ", " + getDescr(); | ||
} | ||
}; | ||
|
||
private final int repr; | ||
private final String descr; | ||
|
||
Gender(int repr, String descr) { | ||
this.repr = repr; | ||
this.descr = descr; | ||
} | ||
|
||
public int getRepr() { | ||
return repr; | ||
} | ||
|
||
public String getDescr() { | ||
return descr; | ||
} | ||
|
||
public String comment() { | ||
return repr + ": " + descr; | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
chapter04/src/main/java/com/apress/bgn/ch4/basic/Musician.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,55 @@ | ||
package com.apress.bgn.ch4.basic; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author iuliana.cosmina | ||
* @date 11/04/2018 | ||
* @since 1.0 | ||
*/ | ||
public class Musician extends Human { | ||
|
||
private String musicSchool; | ||
|
||
private String genre; | ||
|
||
private List<String> songs; | ||
|
||
public Musician(String name, int age, float height, Gender gender, String musicSchool, String genre) { | ||
super(name, age, height, gender); | ||
this.musicSchool = musicSchool; | ||
this.genre = genre; | ||
} | ||
|
||
public int getTimeToLive() { | ||
return (LIFESPAN - getAge()) / 2; | ||
} | ||
|
||
public String getMusicSchool() { | ||
return musicSchool; | ||
} | ||
|
||
public void setMusicSchool(String musicSchool) { | ||
this.musicSchool = musicSchool; | ||
} | ||
|
||
public List<String> getSongs() { | ||
return songs; | ||
} | ||
|
||
public void setSongs(List<String> songs) { | ||
this.songs = songs; | ||
} | ||
|
||
public void addSong(String song){ | ||
this.songs.add(song); | ||
} | ||
|
||
public String getGenre() { | ||
return genre; | ||
} | ||
|
||
public void setGenre(String genre) { | ||
this.genre = genre; | ||
} | ||
} |
13 changes: 8 additions & 5 deletions
13
chapter04/src/main/java/com/apress/bgn/ch4/basic/Sample.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 |
---|---|---|
@@ -1,14 +1,17 @@ | ||
package com.apress.bgn.ch4.basic; | ||
|
||
import java.lang.Math; | ||
|
||
/** | ||
* @author iuliana.cosmina | ||
* @date 11/04/2018 | ||
* @since 1.0 | ||
*/ | ||
public class Sample extends Object { | ||
public static void main(String... args) { | ||
System.out.println("PI value =" + Math.PI); | ||
System.out.println(Gender.FEMALE.comment()); | ||
System.out.println(Gender.MALE.comment()); | ||
System.out.println(Gender.UNDEFINED.comment()); | ||
|
||
double result = Math.sqrt(5.0); | ||
|
||
System.out.println("SQRT value =" + result); | ||
} | ||
} | ||
|
7 changes: 7 additions & 0 deletions
7
chapter04/src/main/java/com/apress/bgn/ch4/ex/EmptyPerformerException.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,7 @@ | ||
package com.apress.bgn.ch4.ex; | ||
|
||
public class EmptyPerformerException extends Exception { | ||
public EmptyPerformerException(String message) { | ||
super(message); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
chapter04/src/main/java/com/apress/bgn/ch4/ex/ExceptionsDemo.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,17 @@ | ||
package com.apress.bgn.ch4.ex; | ||
|
||
import com.apress.bgn.ch4.hierarchy.Performer; | ||
|
||
public class ExceptionsDemo { | ||
|
||
public static void main(String... args) { | ||
try { | ||
Performer p = PerformerGenerator.get("John"); | ||
System.out.println("TTL: " + p.getTimeToLive()); | ||
} catch (EmptyPerformerException e) { | ||
System.out.println("Cannot use an empty performer!"); | ||
} finally { | ||
System.out.println("All went as expected!"); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
chapter04/src/main/java/com/apress/bgn/ch4/ex/PerformerGenerator.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,11 @@ | ||
package com.apress.bgn.ch4.ex; | ||
|
||
import com.apress.bgn.ch4.hierarchy.Gender; | ||
import com.apress.bgn.ch4.hierarchy.Performer; | ||
|
||
public class PerformerGenerator { | ||
|
||
public static Performer get(String name) throws EmptyPerformerException { | ||
return new Performer(name,40, 1.91f, Gender.MALE); | ||
} | ||
} |
Oops, something went wrong.