Skip to content

Commit d8c0ebe

Browse files
committed
made some notes in the code examples
1 parent 5e54d1e commit d8c0ebe

File tree

6 files changed

+14
-4
lines changed

6 files changed

+14
-4
lines changed
File renamed without changes.
File renamed without changes.

reader/ReadingJava/Programs/Dungeon.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
// The code is not well documented, and it is hard to use.
1616
// So clean it up, and make it better.
1717
//
18+
19+
// look for patterns in the code, areas where you can replace duplicated code with method calls.
20+
// look for ways to put blocks of string data into a central data structure.
21+
// look for ways to make the Attack data into a data structure.
22+
1823
import java.util.*;
1924
public class Dungeon {
2025
public static void main(String args[]) {
@@ -49,6 +54,7 @@ public static void main(String args[]) {
4954
int maxMoney3 = 20;
5055
int maxMoney4 = 30;
5156

57+
// Attacks
5258
String enemyAtks1[] = new String[]{"Awkward Stare","Spit","Bite","Thrash","Tackle"};
5359
int enemyAtks1dmg[] = new int[]{6,16,19,14,15};
5460
String enemyAtks2[] = new String[]{"Poison","Toxic Fungi","Soul Decay","Symbiosis"};

reader/ReadingJava/Programs/EmployeeMgmt.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
// What's the problem with this program?
1010
// How should it be organized?
1111

12+
// Would you use just files storing the data?
13+
// How could you upgrade it to being a Database app?
1214

15+
// reduce the number of printlns scattered thru the code, how could you
16+
// make more use of templates
1317
class MainMenu
1418
{
1519
public void menu()

reader/ReadingJava/Programs/Stack.java renamed to reader/ReadingJava/Programs/GenericStack.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Execution: java Stack < input.txt
44
* Data files: https://introcs.cs.princeton.edu/java/43stack/tobe.txt
55
*
6-
* A generic stack, implemented using a linked list. Each stack
6+
* A GENERIC stack, implemented using a linked list. Each stack
77
* element is of type Item.
88
*
99
* % more tobe.txt
@@ -39,7 +39,7 @@
3939
*
4040
* @param <Item> the generic type of each item in this stack
4141
*/
42-
public class Stack<Item> implements Iterable<Item> {
42+
public class GenericStack<Item> implements Iterable<Item> {
4343
private int n; // size of the stack
4444
private Node first; // top of stack
4545

@@ -52,7 +52,7 @@ private class Node {
5252
/**
5353
* Initializes an empty stack.
5454
*/
55-
public Stack() {
55+
public GenericStack() {
5656
first = null;
5757
n = 0;
5858
}
@@ -157,7 +157,7 @@ public Item next() {
157157
* @param args the command-line arguments
158158
*/
159159
public static void main(String[] args) {
160-
Stack<String> stack = new Stack<String>();
160+
GenericStack<String> stack = new GenericStack<String>();
161161
while (!StdIn.isEmpty()) {
162162
String item = StdIn.readString();
163163
if (!item.equals("-")) stack.push(item);

0 commit comments

Comments
 (0)