Skip to content

Commit d16938a

Browse files
authored
Add files via upload
1 parent 0651e94 commit d16938a

26 files changed

+488
-0
lines changed

Lab2/Lab2.iml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

Lab2/Lab2Radzik.zip

22.3 KB
Binary file not shown.
Binary file not shown.
231 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Lab2/out/production/Lab2/Main.class

1.73 KB
Binary file not shown.
1.76 KB
Binary file not shown.
6 KB
Binary file not shown.
1.73 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

Lab2/src/Interfaces/Iterator1b.java

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package Interfaces;
2+
3+
public interface Iterator1b<T> {
4+
void first();
5+
void next();
6+
boolean isDone();
7+
T currentItem();
8+
}

Lab2/src/Interfaces/Predicate.java

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package Interfaces;
2+
3+
public interface Predicate<T>{
4+
boolean accept(T arg);
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package Iterators1a;
2+
3+
import Interfaces.Predicate;
4+
5+
import java.util.Iterator;
6+
7+
public class FilterStudentIterator<T> implements Iterator<T> {
8+
private Iterator<T> iterator;
9+
private Predicate<T> predicate;
10+
private T elemNext = null;
11+
private boolean bHasNext = true;
12+
13+
public FilterStudentIterator(Iterator<T> iterator, Predicate<T> predicate) {
14+
super();
15+
this.iterator = iterator;
16+
this.predicate = predicate;
17+
findNextValid();
18+
}
19+
private void findNextValid() {
20+
while (iterator.hasNext()) {
21+
elemNext = iterator.next();
22+
if (predicate.accept(elemNext)) {
23+
return;
24+
}
25+
}
26+
bHasNext=false;
27+
elemNext=null;
28+
}
29+
30+
@Override
31+
public boolean hasNext() {
32+
return bHasNext;
33+
}
34+
35+
@Override
36+
public T next() {
37+
T nextValue = elemNext;
38+
findNextValid();
39+
return nextValue;
40+
}
41+
42+
}
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package Iterators1a;
2+
3+
import Model.Student;
4+
5+
import java.util.Iterator;
6+
import java.util.function.Predicate;
7+
8+
public class StudentsIterator implements Iterator<Student> {
9+
10+
private Student[] tab;
11+
private int first;
12+
private int last;
13+
private int current = 0;
14+
15+
public StudentsIterator(Student[] tab) {
16+
super();
17+
this.tab = tab;
18+
this.first = 0;
19+
this.last = tab.length-1;
20+
}
21+
22+
public StudentsIterator(Student[] tab, Predicate<Student> predicate) {
23+
super();
24+
this.tab = tab;
25+
this.first = 0;
26+
this.last = tab.length-1;
27+
}
28+
29+
@Override
30+
public boolean hasNext() {
31+
return tab.length>current;
32+
}
33+
34+
@Override
35+
public Student next() {
36+
return tab[current++];
37+
}
38+
39+
@Override
40+
public void remove() {
41+
throw new UnsupportedOperationException("Cannot remove an element of an array.");
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package Iterators1b;
2+
3+
import Interfaces.Iterator1b;
4+
import Interfaces.Predicate;
5+
6+
public class StudentInteratorFilter1B<T> implements Iterator1b{
7+
private Iterator1b<T> iter;
8+
private Predicate<T> predicate;
9+
10+
@Override
11+
public void first() {
12+
iter.first();
13+
}
14+
15+
@Override
16+
public void next() {
17+
iter.next();
18+
}
19+
20+
@Override
21+
public boolean isDone() {
22+
return iter.isDone();
23+
}
24+
25+
@Override
26+
public T currentItem() {
27+
return iter.currentItem();
28+
}
29+
30+
public void findNextValid(){
31+
while(!isDone()){
32+
next();
33+
if(predicate.accept(currentItem())){
34+
return;
35+
}
36+
}
37+
}
38+
39+
public StudentInteratorFilter1B(Iterator1b<T> iter, Predicate<T> predicate) {
40+
this.iter = iter;
41+
this.predicate = predicate;
42+
iter.first();
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package Iterators1b;
2+
3+
import Interfaces.Iterator1b;
4+
import Model.Student;
5+
6+
public class StudentIterator1B implements Iterator1b<Student> {
7+
private Student[] tab;
8+
private int position = -1;
9+
int first;
10+
int last;
11+
private Student currentItem= null;
12+
13+
@Override
14+
public void first() {
15+
position = 0;
16+
currentItem = tab[position];
17+
}
18+
@Override
19+
public void next() {
20+
position++;
21+
if(!isDone()){
22+
currentItem = tab[position];
23+
}
24+
}
25+
26+
@Override
27+
public boolean isDone() {
28+
return position<first || position>=tab.length;
29+
}
30+
31+
@Override
32+
public Student currentItem() {
33+
return currentItem;
34+
}
35+
36+
public StudentIterator1B(Student[] tab) {
37+
this.tab = tab;
38+
first();
39+
last = tab.length-1;
40+
}
41+
}

Lab2/src/Main.java

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Model.Student;
2+
3+
public class Main {
4+
5+
public static Student[] students = new Student[5];
6+
7+
public static void main(String[] args) {
8+
students[0] = new Student("260366", "Jakub", "Radzik", 5);
9+
students[1] = new Student("123345", "Andrzej", "Patalas", 2);
10+
students[2] = new Student("123456", "Jakub", "Oleszczuk", 2);
11+
students[3] = new Student("111222", "Paweł", "Nowak", 3);
12+
students[4] = new Student("232311", "Karol", "Krawczyk", 4);
13+
14+
15+
System.out.println("1B");
16+
Operations.changeMarkForIndex1b(students, "260366", 3);
17+
Operations.displayAll1b(students);
18+
System.out.println("avg: "+Operations.avgForPositive1b(students));
19+
System.out.println("nie zdali");
20+
Operations.displayNegativeStudent1b(students);
21+
Operations.divideStudents1b(students);
22+
}
23+
}

Lab2/src/Model/Student.java

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package Model;
2+
3+
import javax.lang.model.element.Name;
4+
import java.util.StringJoiner;
5+
6+
public class Student {
7+
private String index;
8+
private String fName;
9+
private String lName;
10+
private int mark;
11+
12+
public Student(String index, String fName, String lName, int mark) {
13+
this.index = index;
14+
this.fName = fName;
15+
this.lName = lName;
16+
this.mark = mark;
17+
}
18+
19+
public String getIndex() {
20+
return index;
21+
}
22+
23+
public void setIndex(String index) {
24+
this.index = index;
25+
}
26+
27+
public String getfName() {
28+
return fName;
29+
}
30+
31+
public void setfName(String fName) {
32+
this.fName = fName;
33+
}
34+
35+
public String getlName() {
36+
return lName;
37+
}
38+
39+
public void setlName(String lName) {
40+
this.lName = lName;
41+
}
42+
43+
public int getMark() {
44+
return mark;
45+
}
46+
47+
public void setMark(int mark) {
48+
this.mark = mark;
49+
}
50+
51+
@Override
52+
public String toString() {
53+
return index + " " + fName+ " " + lName+ " " + mark;
54+
}
55+
}

0 commit comments

Comments
 (0)