Loading .gitignore +2 −0 Changes for .gitignore: 2 added lines, 0 removed lines. Original line number Diff line number Diff line /.gradle /build /out *.ser Foo.txt src/main/java/ch16/GameCharacter.java +11 −14 Changes for src/main/java/ch16/GameCharacter.java: 11 added lines, 14 removed lines. Original line number Diff line number Diff line package ch16; import java.io.*; import java.util.Arrays; public class GameCharacter implements Serializable { int power; String type; String[] weapons; public GameCharacter(int p, String t, String[] w) { power = p; type = t; weapons = w; private final int power; private final String type; private final String[] weapons; public GameCharacter(int power, String type, String[] weapons) { this.power = power; this.type = type; this.weapons = weapons; } public int getPower() { Loading @@ -22,13 +23,9 @@ public class GameCharacter implements Serializable { } public String getWeapons() { String weaponList = ""; for (int i = 0; i < weapons.length; i++) { weaponList += weapons[i] + " "; } return weaponList; return Arrays.toString(weapons); } } Loading src/main/java/ch16/GameSaverTest.java +9 −11 Changes for src/main/java/ch16/GameSaverTest.java: 9 added lines, 11 removed lines. Original line number Diff line number Diff line Loading @@ -4,9 +4,12 @@ import java.io.*; public class GameSaverTest { public static void main(String[] args) { GameCharacter one = new GameCharacter(50, "Elf", new String[]{"bow", "sword", "dust"}); GameCharacter two = new GameCharacter(200, "Troll", new String[]{"bare hands", "big ax"}); GameCharacter three = new GameCharacter(120, "Magician", new String[]{"spells", "invisibility"}); GameCharacter one = new GameCharacter(50, "Elf", new String[]{"bow", "sword", "dust"}); GameCharacter two = new GameCharacter(200, "Troll", new String[]{"bare hands", "big ax"}); GameCharacter three = new GameCharacter(120, "Magician", new String[]{"spells", "invisibility"}); // imagine code that does things with the characters that might change their state values Loading @@ -19,10 +22,6 @@ public class GameSaverTest { } catch (IOException ex) { ex.printStackTrace(); } one = null; two = null; three = null; try { ObjectInputStream is = new ObjectInputStream(new FileInputStream("Game.ser")); Loading @@ -30,13 +29,12 @@ public class GameSaverTest { GameCharacter twoRestore = (GameCharacter) is.readObject(); GameCharacter threeRestore = (GameCharacter) is.readObject(); System.out.println("One’s type: " + oneRestore.getType()); System.out.println("Two’s type: " + twoRestore.getType()); System.out.println("Three’s type: " + threeRestore.getType()); System.out.println("One's type: " + oneRestore.getType()); System.out.println("Two's type: " + twoRestore.getType()); System.out.println("Three's type: " + threeRestore.getType()); } catch (Exception ex) { ex.printStackTrace(); } } } No newline at end of file src/main/java/ch16/Pond.java +0 −3 Changes for src/main/java/ch16/Pond.java: 0 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ package ch16; import java.io.*; public class Pond implements Serializable { private Duck duck = new Duck(); public static void main(String[] args) { Loading @@ -11,10 +10,8 @@ public class Pond implements Serializable { try { FileOutputStream fs = new FileOutputStream("Pond.ser"); ObjectOutputStream os = new ObjectOutputStream(fs); os.writeObject(myPond); os.close(); } catch (Exception ex) { ex.printStackTrace(); } Loading src/main/java/ch16/QuizCard.java +7 −3 Changes for src/main/java/ch16/QuizCard.java: 7 added lines, 3 removed lines. Original line number Diff line number Diff line package ch16; public class QuizCard { public QuizCard(String text, String text1) { private final String question; private final String answer; public QuizCard(String question, String answer) { this.question = question; this.answer = answer; } public String getQuestion() { return 0; return question; } public String getAnswer() { return 0; return answer; } } Loading
.gitignore +2 −0 Changes for .gitignore: 2 added lines, 0 removed lines. Original line number Diff line number Diff line /.gradle /build /out *.ser Foo.txt
src/main/java/ch16/GameCharacter.java +11 −14 Changes for src/main/java/ch16/GameCharacter.java: 11 added lines, 14 removed lines. Original line number Diff line number Diff line package ch16; import java.io.*; import java.util.Arrays; public class GameCharacter implements Serializable { int power; String type; String[] weapons; public GameCharacter(int p, String t, String[] w) { power = p; type = t; weapons = w; private final int power; private final String type; private final String[] weapons; public GameCharacter(int power, String type, String[] weapons) { this.power = power; this.type = type; this.weapons = weapons; } public int getPower() { Loading @@ -22,13 +23,9 @@ public class GameCharacter implements Serializable { } public String getWeapons() { String weaponList = ""; for (int i = 0; i < weapons.length; i++) { weaponList += weapons[i] + " "; } return weaponList; return Arrays.toString(weapons); } } Loading
src/main/java/ch16/GameSaverTest.java +9 −11 Changes for src/main/java/ch16/GameSaverTest.java: 9 added lines, 11 removed lines. Original line number Diff line number Diff line Loading @@ -4,9 +4,12 @@ import java.io.*; public class GameSaverTest { public static void main(String[] args) { GameCharacter one = new GameCharacter(50, "Elf", new String[]{"bow", "sword", "dust"}); GameCharacter two = new GameCharacter(200, "Troll", new String[]{"bare hands", "big ax"}); GameCharacter three = new GameCharacter(120, "Magician", new String[]{"spells", "invisibility"}); GameCharacter one = new GameCharacter(50, "Elf", new String[]{"bow", "sword", "dust"}); GameCharacter two = new GameCharacter(200, "Troll", new String[]{"bare hands", "big ax"}); GameCharacter three = new GameCharacter(120, "Magician", new String[]{"spells", "invisibility"}); // imagine code that does things with the characters that might change their state values Loading @@ -19,10 +22,6 @@ public class GameSaverTest { } catch (IOException ex) { ex.printStackTrace(); } one = null; two = null; three = null; try { ObjectInputStream is = new ObjectInputStream(new FileInputStream("Game.ser")); Loading @@ -30,13 +29,12 @@ public class GameSaverTest { GameCharacter twoRestore = (GameCharacter) is.readObject(); GameCharacter threeRestore = (GameCharacter) is.readObject(); System.out.println("One’s type: " + oneRestore.getType()); System.out.println("Two’s type: " + twoRestore.getType()); System.out.println("Three’s type: " + threeRestore.getType()); System.out.println("One's type: " + oneRestore.getType()); System.out.println("Two's type: " + twoRestore.getType()); System.out.println("Three's type: " + threeRestore.getType()); } catch (Exception ex) { ex.printStackTrace(); } } } No newline at end of file
src/main/java/ch16/Pond.java +0 −3 Changes for src/main/java/ch16/Pond.java: 0 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ package ch16; import java.io.*; public class Pond implements Serializable { private Duck duck = new Duck(); public static void main(String[] args) { Loading @@ -11,10 +10,8 @@ public class Pond implements Serializable { try { FileOutputStream fs = new FileOutputStream("Pond.ser"); ObjectOutputStream os = new ObjectOutputStream(fs); os.writeObject(myPond); os.close(); } catch (Exception ex) { ex.printStackTrace(); } Loading
src/main/java/ch16/QuizCard.java +7 −3 Changes for src/main/java/ch16/QuizCard.java: 7 added lines, 3 removed lines. Original line number Diff line number Diff line package ch16; public class QuizCard { public QuizCard(String text, String text1) { private final String question; private final String answer; public QuizCard(String question, String answer) { this.question = question; this.answer = answer; } public String getQuestion() { return 0; return question; } public String getAnswer() { return 0; return answer; } }