add examples in java 8 (#12)

* code for chapters 3-9 in Java

* code for chapters 1 in Java

* code for chapter 2 in Java

* missing CheckVoter for chapter 5 in Java

* add missing sample output for SetCovering as a comment
This commit is contained in:
Oleh Novikov
2017-03-20 17:06:45 +01:00
committed by Aditya Bhargava
parent 12265a8c61
commit 4631b7a156
17 changed files with 502 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
import java.util.HashMap;
import java.util.Map;
public class PriceOfGroceries {
public static void main(String[] args) {
Map<String, Double> book = new HashMap<>();
// an apple costs 67 cents
book.put("apple", 0.67);
// milk costs $1.49
book.put("milk", 1.49);
book.put("avocado", 1.49);
System.out.println(book); // {apple=0.67, avocado=1.49, milk=1.49}
}
}

View File

@@ -0,0 +1,21 @@
import java.util.HashMap;
import java.util.Map;
public class CheckVoter {
private static Map<String, Boolean> voted = new HashMap<>();
private static void checkVoter(String name) {
if (voted.containsKey(name)) {
System.out.println("kick them out!");
} else {
voted.put(name, true);
System.out.println("let them vote!");
}
}
public static void main(String[] args) {
checkVoter("tom"); // let them vote!
checkVoter("mike"); // let them vote!
checkVoter("mike"); // kick them out!
}
}