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

Review - oddanie zadań github. #5

Open
wants to merge 22 commits into
base: review
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
43df7f7
1. Dodanie pliku .gitignore
PiotrNakonowski Apr 15, 2024
7d0856d
2. Poprawa błędów z formatowaniem kodu w pliku HanoiRhymer
PiotrNakonowski Apr 15, 2024
52f287c
2. Poprawa błędów z formatowaniem kodu w pliku HanoiRhymer
PiotrNakonowski Apr 15, 2024
0859e65
2. Poprawa błędów z formatowaniem kodu w pliku HanoiRhymer
PiotrNakonowski Apr 15, 2024
7aef39d
3. Scalenie gałęzi master z gałęzią format
PiotrNakonowski Apr 15, 2024
bc402d0
5. Zmiana konwencji nazewnictwa zmiennych
PiotrNakonowski Apr 15, 2024
1d94721
4.1 Poprawa nazw klas
PiotrNakonowski Apr 15, 2024
57ab523
4.2 Zmiana konwencji nazewniczej metod
PiotrNakonowski Apr 15, 2024
0a137db
Merge branch 'class-method-naming'
PiotrNakonowski Apr 15, 2024
d904f14
6.Zmiana literałów deklaracjami stałych
Romeq41 May 28, 2024
02771ae
7. Ustawienie final przy nie niemutowalnych atrybutach klas
Romeq41 May 28, 2024
7988fa5
8. Dodanie annotacji @Override przy metodach gdzie jest to możliwe
Romeq41 May 28, 2024
af01184
Merge pull request #2 from PiotrNakonowski/constants
PiotrNakonowski May 28, 2024
32c34ca
9. Poprawa widoczności atrybutów klas.
PiotrNakonowski May 28, 2024
79009b4
10. Dodanie gettera dla pola total.
PiotrNakonowski May 28, 2024
31a49b2
11. Hermetyzacja nieprywatnych atrybutów.
PiotrNakonowski May 28, 2024
bb774f2
12. Usunięcie nieużywanego gettera.
PiotrNakonowski May 28, 2024
c5214d0
Merge pull request #3 from PiotrNakonowski/Accessory_i_hermetyzacja
PiotrNakonowski May 28, 2024
7911bfb
13. Rozbicie metody main w RhymersDemo (metoda statyczna)
May 29, 2024
c7a49b0
15. Poprawna walidacja projektu testami jednostkowymi
May 29, 2024
fe8988e
17. Wykonanie dokumentacji klasy DefaultCountingOutRhymer.java
May 29, 2024
65f2ca7
Merge pull request #4 from PiotrNakonowski/docs
PiotrNakonowski May 29, 2024
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/
target/
bin/
70 changes: 70 additions & 0 deletions src/main/java/edu/kis/vh/nursery/DefaultCountingOutRhymer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package edu.kis.vh.nursery;

/**
* The DefaultCountingOutRhymer class represents a simple counter that can
* store and manage integer values in a stack-like structure. It provides
* methods to add, remove, and inspect the integers in the stack.
*/

public class DefaultCountingOutRhymer {

private static final int NUMBERS_SIZE = 12;
private static final int EMPTY = -1;
private static final int FULL = 11;
private final int[] numbers = new int[NUMBERS_SIZE];

private int total = EMPTY;

/**
* Adds an integer to the stack if it is not full.
*
* @param in the integer to add to the stack
*/
public void countIn(int in) {
if (!isFull())
numbers[++total] = in;
}

/**
* Checks if the stack is empty.
*
* @return true if the stack is empty, false otherwise
*/
public boolean callCheck() {
return total == EMPTY;
}

/**
* Checks if the stack is full.
*
* @return true if the stack is full, false otherwise
*/
public boolean isFull() {
return total == FULL;
}

/**
* Peeks at the top integer in the stack without removing it.
*
* @return the top integer in the stack if it is not empty;
* EMPTY (-1) if the stack is empty
*/
protected int peekaboo() {
if (callCheck())
return EMPTY;
return numbers[total];
}

/**
* Removes and returns the top integer from the stack.
*
* @return the top integer in the stack if it is not empty;
* EMPTY (-1) if the stack is empty
*/
public int countOut() {
if (callCheck())
return EMPTY;
return numbers[total--];
}

}
4 changes: 2 additions & 2 deletions src/main/java/edu/kis/vh/nursery/FIFORhymer.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package edu.kis.vh.nursery;

public class FIFORhymer extends defaultCountingOutRhymer {
public class FIFORhymer extends DefaultCountingOutRhymer {

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

@Override
public int countOut() {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/edu/kis/vh/nursery/HanoiRhymer.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package edu.kis.vh.nursery;

public class HanoiRhymer extends defaultCountingOutRhymer {
public class HanoiRhymer extends DefaultCountingOutRhymer {

int totalRejected = 0;
private 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);
else
super.countIn(in);
}
}
}
34 changes: 0 additions & 34 deletions src/main/java/edu/kis/vh/nursery/defaultCountingOutRhymer.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
package edu.kis.vh.nursery.factory;

import edu.kis.vh.nursery.defaultCountingOutRhymer;
import edu.kis.vh.nursery.DefaultCountingOutRhymer;
import edu.kis.vh.nursery.FIFORhymer;
import edu.kis.vh.nursery.HanoiRhymer;
import edu.kis.vh.nursery.factory.Rhymersfactory;

public class DefaultRhymersFactory implements Rhymersfactory {
public class DefaultRhymersFactory implements RhymersFactory {

@Override
public defaultCountingOutRhymer GetStandardRhymer() {
return new defaultCountingOutRhymer();
public DefaultCountingOutRhymer getStandardRhymer() {
return new DefaultCountingOutRhymer();
}

@Override
public defaultCountingOutRhymer GetFalseRhymer() {
return new defaultCountingOutRhymer();
public DefaultCountingOutRhymer getFalseRhymer() {
return new DefaultCountingOutRhymer();
}

@Override
public defaultCountingOutRhymer GetFIFORhymer() {
public DefaultCountingOutRhymer getFIFORhymer() {
return new FIFORhymer();
}

@Override
public defaultCountingOutRhymer GetHanoiRhymer() {
public DefaultCountingOutRhymer getHanoiRhymer() {
return new HanoiRhymer();
}

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/edu/kis/vh/nursery/factory/RhymersFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package edu.kis.vh.nursery.factory;

import edu.kis.vh.nursery.DefaultCountingOutRhymer;

public interface RhymersFactory {

public DefaultCountingOutRhymer getStandardRhymer();

public DefaultCountingOutRhymer getFalseRhymer();

public DefaultCountingOutRhymer getFIFORhymer();

public DefaultCountingOutRhymer getHanoiRhymer();

}
15 changes: 0 additions & 15 deletions src/main/java/edu/kis/vh/nursery/factory/Rhymersfactory.java

This file was deleted.

21 changes: 11 additions & 10 deletions src/main/java/edu/kis/vh/nursery/list/IntLinkedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

public class IntLinkedList {

Node last;
int i;
private static final int EMPTY = -1;
private Node last;
private int i;

public void push(int i) {
if (last == null)
last = new Node(i);
else {
last.next = new Node(i);
last.next.prev = last;
last = last.next;
last.setNext(new Node(i));
last.getNext().setPrev(last);
last = last.getNext();
}
}

Expand All @@ -25,15 +26,15 @@ public boolean isFull() {

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

public int pop() {
if (isEmpty())
return -1;
int ret = last.value;
last = last.prev;
return EMPTY;
int ret = last.getValue();
last = last.getPrev();
return ret;
}

Expand Down
26 changes: 23 additions & 3 deletions src/main/java/edu/kis/vh/nursery/list/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,31 @@

public class Node {

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

public Node(int i) {
value = i;
}


public Node getPrev() {
return prev;
}

public void setPrev(Node prev) {
this.prev = prev;
}

public Node getNext() {
return next;
}

public void setNext(Node next) {
this.next = next;
}

public int getValue() {
return value;
}
}
28 changes: 15 additions & 13 deletions src/test/java/edu/kis/vh/nursery/RhymersDemo.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
package edu.kis.vh.nursery;

import edu.kis.vh.nursery.defaultCountingOutRhymer;
import edu.kis.vh.nursery.HanoiRhymer;
import edu.kis.vh.nursery.factory.DefaultRhymersFactory;
import edu.kis.vh.nursery.factory.Rhymersfactory;
import edu.kis.vh.nursery.factory.RhymersFactory;

class RhymersDemo {

public static void main(String[] args) {
Rhymersfactory factory = new DefaultRhymersFactory();

defaultCountingOutRhymer[] rhymers = { factory.GetStandardRhymer(), factory.GetFalseRhymer(),
factory.GetFIFORhymer(), factory.GetHanoiRhymer()};

RhymersFactory factory = new DefaultRhymersFactory();

testRhymers(factory);

}

private static void testRhymers(RhymersFactory factory) {
DefaultCountingOutRhymer[] rhymers = { factory.getStandardRhymer(), factory.getFalseRhymer(),
factory.getFIFORhymer(), factory.getHanoiRhymer()};

for (int i = 1; i < 15; i++)
for (int j = 0; j < 3; j++)
rhymers[j].countIn(i);

java.util.Random rn = new java.util.Random();
for (int i = 1; i < 15; i++)
rhymers[3].countIn(rn.nextInt(20));

for (int i = 0; i < rhymers.length; i++) {
while (!rhymers[i].callCheck())
System.out.print(rhymers[i].countOut() + " ");
System.out.println();
}

System.out.println("total rejected is "
+ ((HanoiRhymer) rhymers[3]).reportRejected());

}

}
10 changes: 5 additions & 5 deletions src/test/java/edu/kis/vh/nursery/RhymersJUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class RhymersJUnitTest {

@Test
public void testCountIn() {
defaultCountingOutRhymer rhymer = new defaultCountingOutRhymer();
DefaultCountingOutRhymer rhymer = new DefaultCountingOutRhymer();
int testValue = 4;
rhymer.countIn(testValue);

Expand All @@ -17,7 +17,7 @@ public void testCountIn() {

@Test
public void testCallCheck() {
defaultCountingOutRhymer rhymer = new defaultCountingOutRhymer();
DefaultCountingOutRhymer rhymer = new DefaultCountingOutRhymer();
boolean result = rhymer.callCheck();
Assert.assertEquals(true, result);

Expand All @@ -29,7 +29,7 @@ public void testCallCheck() {

@Test
public void testIsFull() {
defaultCountingOutRhymer rhymer = new defaultCountingOutRhymer();
DefaultCountingOutRhymer rhymer = new DefaultCountingOutRhymer();
final int STACK_CAPACITY = 12;
for (int i = 0; i < STACK_CAPACITY; i++) {
boolean result = rhymer.isFull();
Expand All @@ -43,7 +43,7 @@ public void testIsFull() {

@Test
public void testPeekaboo() {
defaultCountingOutRhymer rhymer = new defaultCountingOutRhymer();
DefaultCountingOutRhymer rhymer = new DefaultCountingOutRhymer();
final int EMPTY_STACK_VALUE = -1;

int result = rhymer.peekaboo();
Expand All @@ -60,7 +60,7 @@ public void testPeekaboo() {

@Test
public void testCountOut() {
defaultCountingOutRhymer rhymer = new defaultCountingOutRhymer();
DefaultCountingOutRhymer rhymer = new DefaultCountingOutRhymer();
final int EMPTY_STACK_VALUE = -1;

int result = rhymer.countOut();
Expand Down