forked from Hnoianko/prog.kiev.ua-JavaOOP-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Homework3.iml | ||
.idea/ | ||
out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.gmail.gnoianko; | ||
|
||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
|
||
public class Group { | ||
private Student[] group = new Student[10]; | ||
|
||
public Group() { | ||
super(); | ||
} | ||
|
||
public void addStudent(Student newStudent)throws GroupIsFullException{ | ||
if(newStudent == null){ | ||
throw new IllegalArgumentException("Student cannot be null"); | ||
} | ||
for (int i = 0; i < group.length; i++){ | ||
if(group[i]==null){ | ||
group[i]=newStudent; | ||
return; | ||
} | ||
}throw new GroupIsFullException(); | ||
} | ||
|
||
public boolean deleteStudent(int index) { | ||
if ((index >= 0) & (index <= group.length)) { | ||
group[index - 1] = null; | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
public Student searchStudent(String surname) { | ||
for (int i = 0; i < group.length; i++) { | ||
if (group[i] != null && group[i].getSureName() != null && group[i].getSureName().equalsIgnoreCase(surname)) { | ||
return group[i]; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
Arrays.sort(group, new Comparator<Student>() { | ||
@Override | ||
public int compare(Student o1, Student o2) { | ||
if (o1 == null || o1.getSureName() == null) { | ||
return 1; | ||
} | ||
if (o2 == null || o2.getSureName() == null) { | ||
return -1; | ||
} | ||
if (o1 == null && o2 == null || (o1.getSureName() == null || o2.getSureName() == null)) { | ||
return 0; | ||
} | ||
return o1.getSureName().compareTo(o2.getSureName()); | ||
} | ||
}); | ||
for (int i = 0; i < group.length; i++) { | ||
if (group[i] != null) { | ||
sb.append(group[i].toString()); | ||
} | ||
} | ||
return "Group:" + sb.toString(); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.gmail.gnoianko; | ||
|
||
public class GroupIsFullException extends Exception { | ||
@Override | ||
public String getMessage(){ | ||
return "Group is full"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.gmail.gnoianko; | ||
|
||
public class Human { | ||
private String name; | ||
private String sureName; | ||
private int age; | ||
private boolean sex; | ||
|
||
public Human(String name, String sureName, int age, boolean sex) { | ||
this.name = name; | ||
this.sureName = sureName; | ||
this.age = age; | ||
this.sex = sex; | ||
} | ||
public Human(){ | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getSureName() { | ||
return sureName; | ||
} | ||
|
||
public void setSureName(String sureName) { | ||
this.sureName = sureName; | ||
} | ||
|
||
public int getAge() { | ||
return age; | ||
} | ||
|
||
public void setAge(int age) { | ||
this.age = age; | ||
} | ||
|
||
public boolean isSex() { | ||
return sex; | ||
} | ||
|
||
public void setSex(boolean sex) { | ||
this.sex = sex; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Human{" + | ||
"name='" + name + '\'' + | ||
", sureName='" + sureName + '\'' + | ||
", age=" + age + | ||
", sex=" + sex + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.gmail.gnoianko; | ||
|
||
public class Main { | ||
public static void main (String[]args){ | ||
Student bohdan = new Student("Bohdan", "Hnoianko", 22, true, "KNUTE",75); | ||
Student ivan = new Student("Ivan", "Ivanov", 21, true, "KNUTE",75); | ||
Student roma = new Student("Roman", "Ermak", 22, true, "KNUTE",75); | ||
Student anna = new Student("Ann", "Klop", 21, true, "KNUTE",75); | ||
Student vlad = new Student("Vlad", "Bosh", 23, true, "KNUTE",75); | ||
Student inna = new Student("Inna", "Movchan", 22, true, "KNUTE",75); | ||
Student artem = new Student("Artem", "Kas`ka", 22, true, "KNUTE",75); | ||
Student dima = new Student("Dima", "Varva", 24, true, "KNUTE",75); | ||
Student john = new Student("John", "Robston", 22, true, "KNUTE",75); | ||
Student den = new Student("Den", "Tsaryk", 21, true, "KNUTE",75); | ||
|
||
Group group = new Group(); | ||
try{ | ||
group.addStudent(bohdan); | ||
group.addStudent(ivan); | ||
group.addStudent(roma); | ||
group.addStudent(anna); | ||
group.addStudent(vlad); | ||
group.addStudent(inna); | ||
group.addStudent(artem); | ||
group.addStudent(dima); | ||
group.addStudent(john); | ||
group.addStudent(den); | ||
}catch (GroupIsFullException e){ | ||
e.printStackTrace(); | ||
} | ||
System.out.println(group); | ||
group.deleteStudent(5); | ||
group.deleteStudent(6); | ||
System.out.println(group); | ||
System.out.println(group.searchStudent("Robston")); | ||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.gmail.gnoianko; | ||
|
||
public class Student extends Human { | ||
private String university; | ||
private double totalMark; | ||
|
||
public Student(String name, String sureName, int age, boolean sex, String university, double totalMark) { | ||
super(name, sureName, age, sex); | ||
this.university = university; | ||
this.totalMark = totalMark; | ||
} | ||
|
||
public Student() { | ||
} | ||
|
||
public String getUniversity() { | ||
return university; | ||
} | ||
|
||
public void setUniversity(String university) { | ||
this.university = university; | ||
} | ||
|
||
public double getTotalMark() { | ||
return totalMark; | ||
} | ||
|
||
public void setTotalMark(double totalMark) { | ||
this.totalMark = totalMark; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Student{" + | ||
"university='" + university + '\'' + | ||
", totalMark=" + totalMark+", " + super.toString() + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Diagram> | ||
<ID>JAVA</ID> | ||
<OriginalElement /> | ||
<nodes> | ||
<node x="47.62466086647727" y="160.0">com.gmail.gnoianko.Group</node> | ||
<node x="127.75278586647725" y="80.0">com.gmail.gnoianko.GroupIsFullException</node> | ||
<node x="29.87466086647727" y="240.0">com.gmail.gnoianko.Main</node> | ||
<node x="16.752785866477254" y="80.0">com.gmail.gnoianko.Student</node> | ||
<node x="17.252785866477254" y="0.0">com.gmail.gnoianko.Human</node> | ||
</nodes> | ||
<notes /> | ||
<edges> | ||
<edge source="com.gmail.gnoianko.Student" target="com.gmail.gnoianko.Human"> | ||
<point x="0.0" y="-15.0" /> | ||
<point x="0.0" y="15.0" /> | ||
</edge> | ||
<edge source="com.gmail.gnoianko.Main" target="com.gmail.gnoianko.Student"> | ||
<point x="-15.399999999999999" y="-15.0" /> | ||
<point x="52.97466086647727" y="210.0" /> | ||
<point x="37.12466086647727" y="210.0" /> | ||
<point x="37.12466086647727" y="135.0" /> | ||
<point x="44.052785866477265" y="135.0" /> | ||
<point x="-18.19999999999999" y="15.0" /> | ||
</edge> | ||
<edge source="com.gmail.gnoianko.Main" target="com.gmail.gnoianko.Group"> | ||
<point x="15.400000000000006" y="-15.0" /> | ||
<point x="83.77466086647728" y="210.0" /> | ||
<point x="109.87466086647727" y="210.0" /> | ||
<point x="20.75" y="15.0" /> | ||
</edge> | ||
<edge source="com.gmail.gnoianko.Group" target="com.gmail.gnoianko.GroupIsFullException"> | ||
<point x="31.125" y="-15.0" /> | ||
<point x="120.24966086647727" y="135.0" /> | ||
<point x="168.00278586647727" y="135.0" /> | ||
<point x="-40.25" y="15.0" /> | ||
</edge> | ||
<edge source="com.gmail.gnoianko.Main" target="com.gmail.gnoianko.GroupIsFullException"> | ||
<point x="30.799999999999997" y="-15.0" /> | ||
<point x="99.17466086647727" y="220.0" /> | ||
<point x="248.50278586647727" y="220.0" /> | ||
<point x="40.250000000000014" y="15.0" /> | ||
</edge> | ||
<edge source="com.gmail.gnoianko.Group" target="com.gmail.gnoianko.Student"> | ||
<point x="-10.375" y="-15.0" /> | ||
<point x="78.74966086647727" y="135.0" /> | ||
<point x="80.45278586647727" y="135.0" /> | ||
<point x="18.200000000000017" y="15.0" /> | ||
</edge> | ||
</edges> | ||
<settings layout="Hierarchic Group" zoom="1.2000000000000002" x="154.81818181818159" y="136.75757575757567" /> | ||
<SelectedNodes> | ||
<node>com.gmail.gnoianko.GroupIsFullException</node> | ||
</SelectedNodes> | ||
<Categories /> | ||
<SCOPE>All</SCOPE> | ||
<VISIBILITY>private</VISIBILITY> | ||
</Diagram> | ||
|