Skip to content

Commit

Permalink
010 added some sources for chapter 5, added a gradle compiler option …
Browse files Browse the repository at this point in the history
…to try to get rid of the deprecation warnings
  • Loading branch information
Iuliana-Cosmina Grajdeanu authored and iuliana committed Sep 20, 2018
1 parent b6237ee commit 108440a
Show file tree
Hide file tree
Showing 44 changed files with 820 additions and 97 deletions.
6 changes: 6 additions & 0 deletions chapter00/chapter00.gradle
Expand Up @@ -8,6 +8,10 @@ buildscript {

}

plugins {
id 'java-library'
}

group 'com.apress.bgn.ch0'
ext.moduleName = 'chapter.zero'

Expand Down Expand Up @@ -40,6 +44,7 @@ afterEvaluate {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'-proc:none',
'--module-path', classpath.asPath,
]
classpath = files()
Expand All @@ -50,6 +55,7 @@ afterEvaluate {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'-proc:none',
'--module-path', classpath.asPath,
'--add-modules', 'org.junit.jupiter.engine',
'--add-reads', "$moduleName=org.junit.jupiter.engine",
Expand Down
7 changes: 7 additions & 0 deletions chapter00/src/main/java/com/apress/bgn/ch0/HelloWorld.java
@@ -0,0 +1,7 @@
package com.apress.bgn.ch0;

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
6 changes: 6 additions & 0 deletions chapter01/chapter01.gradle
Expand Up @@ -8,6 +8,10 @@ buildscript {

}

plugins {
id 'java-library'
}

group 'com.apress.bgn.ch1'
ext.moduleName = 'chapter.one'

Expand Down Expand Up @@ -40,6 +44,7 @@ afterEvaluate {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'-proc:none',
'--module-path', classpath.asPath,
]
classpath = files()
Expand All @@ -50,6 +55,7 @@ afterEvaluate {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'-proc:none',
'--module-path', classpath.asPath,
'--add-modules', 'org.junit.jupiter.engine',
'--add-reads', "$moduleName=org.junit.jupiter.engine",
Expand Down
6 changes: 6 additions & 0 deletions chapter03/chapter03.gradle
Expand Up @@ -7,6 +7,10 @@ buildscript {
}

}
plugins {
id 'java-library'
}


group 'com.apress.bgn.ch3'
ext.moduleName = 'chapter.three'
Expand Down Expand Up @@ -41,6 +45,7 @@ afterEvaluate {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'-proc:none',
'--module-path', classpath.asPath,
]
classpath = files()
Expand All @@ -51,6 +56,7 @@ afterEvaluate {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'-proc:none',
'--module-path', classpath.asPath,
'--add-modules', 'org.junit.jupiter.engine',
'--add-reads', "$moduleName=org.junit.jupiter.engine",
Expand Down
2 changes: 2 additions & 0 deletions chapter04/chapter04.gradle
Expand Up @@ -40,6 +40,7 @@ afterEvaluate {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'-proc:none',
'--module-path', classpath.asPath,
]
classpath = files()
Expand All @@ -50,6 +51,7 @@ afterEvaluate {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'-proc:none',
'--module-path', classpath.asPath,
'--add-modules', 'org.junit.jupiter.engine',
'--add-reads', "$moduleName=org.junit.jupiter.engine",
Expand Down
45 changes: 45 additions & 0 deletions chapter04/src/main/java/com/apress/bgn/ch4/basic/Actor.java
@@ -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);
}
}
Expand Up @@ -8,18 +8,18 @@
public class BasicHumanDemo {

public static void main(String... args) {
Human john = new Human();
john.name = "John";

Musician human = new Musician("John", 40, 1.91f, Gender.MALE,
"self taught", "country");

Human jane = new Human();
jane.name = "Jane";
System.out.println("name: " + human.getName());
System.out.println("age: " + human.getAge());
System.out.println("height: " + human.getHeight());
System.out.println("gender: " + human.getGender().name());
System.out.println("music school: " + human.getMusicSchool());
System.out.println("genre: " + human.getGenre());
System.out.println("ttl: " + human.getTimeToLive());

System.out.println("John's lifespan = " + john.LIFESPAN);
System.out.println("Jane's lifespan = " + jane.LIFESPAN);


System.out.println("Human lifespan = " + Human.LIFESPAN);
}

}
37 changes: 37 additions & 0 deletions chapter04/src/main/java/com/apress/bgn/ch4/basic/Gender.java
@@ -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;
}
}
36 changes: 31 additions & 5 deletions chapter04/src/main/java/com/apress/bgn/ch4/basic/Human.java
Expand Up @@ -5,14 +5,32 @@
* @date 11/04/2018
* @since 1.0
*/
public class Human {
static final int LIFESPAN = 100;
public abstract class Human {
public static final int LIFESPAN = 100;

private String name;
protected String name;

private int age;
protected int age;

private float height;
protected float height;

private Gender gender;

public Human(String name, int age, Gender gender) {
this.name = name;
this.age = age;
this.gender = gender;
}

public Human(String name, int age, float height, Gender gender) {
this(name, age, gender);
this.height = height;
}

/**
* @return time to live
*/
public abstract int getTimeToLive();

public String getName() {
return name;
Expand All @@ -37,4 +55,12 @@ public float getHeight() {
public void setHeight(float height) {
this.height = height;
}

public Gender getGender() {
return gender;
}

public void setGender(Gender gender) {
this.gender = gender;
}
}
55 changes: 55 additions & 0 deletions chapter04/src/main/java/com/apress/bgn/ch4/basic/Musician.java
@@ -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 chapter04/src/main/java/com/apress/bgn/ch4/basic/Sample.java
@@ -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);
}
}

@@ -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 chapter04/src/main/java/com/apress/bgn/ch4/ex/ExceptionsDemo.java
@@ -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!");
}
}
}
@@ -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);
}
}

0 comments on commit 108440a

Please sign in to comment.