Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constants #46

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
bin/
target/
2 changes: 1 addition & 1 deletion src/main/java/edu/kis/vh/nursery/FIFORhymer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class FIFORhymer extends defaultCountingOutRhymer {

public defaultCountingOutRhymer temp = new defaultCountingOutRhymer();
public final defaultCountingOutRhymer temp = new defaultCountingOutRhymer();

@Override
public int countOut() {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/edu/kis/vh/nursery/HanoiRhymer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

public class HanoiRhymer extends defaultCountingOutRhymer {

int totalRejected = 0;
int totalRejected = 0;

public int reportRejected() {
return totalRejected;
}

@Override
public void countIn(int in) {
if (!callCheck() && in > peekaboo())
if (!callCheck() && in > peekaboo())
totalRejected++;
else
super.countIn(in);
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/edu/kis/vh/nursery/defaultCountingOutRhymer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,36 @@

public class defaultCountingOutRhymer {

private int[] NUMBERS = new int[12];
public static final int EMPTY = -1;
public static final int CAPACITY = 12;
public static final int FULL = CAPACITY-1;
private final int[] NUMBERS = new int[CAPACITY];

public int total = EMPTY;

public int total = -1;

public void countIn(int in) {
if (!isFull())
NUMBERS[++total] = in;
}

public boolean callCheck() {
return total == -1;
return total == EMPTY;
}

public boolean isFull() {
return total == 11;
return total == FULL;
}

protected int peekaboo() {
if (callCheck())
return -1;
return EMPTY;;
return NUMBERS[total];
}

public int countOut() {
if (callCheck())
return -1;
return EMPTY;
return NUMBERS[total--];
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/edu/kis/vh/nursery/list/IntLinkedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public class IntLinkedList {

public static final int EMPTY = -1;

Node last;
int i;

Expand All @@ -25,13 +27,13 @@ public boolean isFull() {

public int top() {
if (isEmpty())
return -1;
return EMPTY;
return last.value;
}

public int pop() {
if (isEmpty())
return -1;
return EMPTY;
int ret = last.value;
last = last.prev;
return ret;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/kis/vh/nursery/list/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class Node {

public int value;
public final int value;
public Node prev, next;

public Node(int i) {
Expand Down