Skip to content

Commit 09ab903

Browse files
authored
Add Exam 2011 java A files
1 parent e813d9c commit 09ab903

File tree

5 files changed

+407
-0
lines changed

5 files changed

+407
-0
lines changed

Exam2011JavaA/Clsrm.java

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/**
2+
* Clsrm.java
3+
* the class reprsents a clsrm
4+
* Author: liron mizrhai
5+
*/
6+
public class Clsrm
7+
{
8+
private int _classNum;
9+
private int _classPlaces;
10+
private boolean _isAvailable;
11+
/**
12+
* constrctor of the class Clsrm
13+
* @param: int num, int maxPlaces, boolean isAvail
14+
* @return: None
15+
*/
16+
public Clsrm(int num, int maxPlaces, boolean isAvail)
17+
{
18+
_classNum = num;
19+
_classPlaces = maxPlaces;
20+
_isAvailable = isAvail;
21+
}// end of method Clsrm
22+
/**
23+
* copy constrctor of the class
24+
* @param: Clsrm c
25+
* @return: None
26+
*/
27+
public Clsrm(Clsrm c)
28+
{
29+
_classNum = c._classNum;
30+
_classPlaces = c._classPlaces;
31+
_isAvailable = c._isAvailable;
32+
}// end of method Clsrm
33+
/**
34+
* the method return the class number
35+
* @param: None
36+
* @return: int
37+
*/
38+
public int getClassNum()
39+
{
40+
return _classNum;
41+
}// end of method getClassNum
42+
/**
43+
* the method return the class places
44+
* @param: None
45+
* @return: int
46+
*/
47+
public int getClassPlaces()
48+
{
49+
return _classPlaces;
50+
}
51+
/**
52+
* the method return if the class avilable or not
53+
* @param: None
54+
* @return: boolean
55+
*/
56+
public boolean getAvailable()
57+
{
58+
return _isAvailable;
59+
}// end of method getAvilable
60+
/**
61+
* the method set if the class is avilable
62+
* @param: boolean avail
63+
* @return: None
64+
*/
65+
public void setAvilable(boolean avail)
66+
{
67+
_isAvailable = avail;
68+
}// end of method setAvilable
69+
/**
70+
* the method return if the class handicapped suitable
71+
* @param: None
72+
* @return: boolean
73+
*/
74+
public boolean handicappedSuitable()
75+
{
76+
if(_classNum < 100)
77+
{
78+
return true;
79+
}
80+
return false;
81+
}// end of method hadicappedSutable
82+
/**
83+
* the method return if the two clsrm is equals
84+
* equals classes is when the number of class places is equal
85+
* @param: Clsrm other
86+
* @return: boolean
87+
*/
88+
public boolean equals(Clsrm other)
89+
{
90+
if(_classPlaces == other.getClassPlaces())
91+
{
92+
return true;
93+
}
94+
return false;
95+
}// end of method equals
96+
/**
97+
* the method return true if the class places is bigger than the class places in the given paramter
98+
* @param: Clsrm other
99+
* @return: boolean
100+
*/
101+
public boolean isBigger(Clsrm other)
102+
{
103+
if(_classPlaces > other.getClassPlaces())
104+
{
105+
return true;
106+
}
107+
return false;
108+
}// end of method isBigger
109+
/**
110+
* the method return true if the class is smaller than the class given as paramter
111+
* @param: Clsrm other
112+
* @return: boolean
113+
*/
114+
public boolean isSmaller(Clsrm other)
115+
{
116+
if(other.isBigger(this))
117+
{
118+
return true;
119+
}
120+
return false;
121+
}// end of method isSmaller
122+
/**
123+
* the method return true if the class is higher then the class given as paramter
124+
* @param: Clsrm other
125+
* @return: boolean
126+
*/
127+
public boolean isHigher(Clsrm other)
128+
{
129+
if(_classNum < 100 && other.getClassNum() < 100)
130+
{
131+
return false;
132+
}
133+
else if(_classNum > 99 && other.getClassNum() < 100)
134+
{
135+
return true;
136+
}
137+
else if(_classNum < 100 && other.getClassNum() > 99)
138+
{
139+
return false;
140+
}
141+
else if(_classNum > 99 && other.getClassNum() > 99)
142+
{
143+
int lastDigit = _classNum / 100;
144+
int secondLastDigit = other.getClassNum() / 100;
145+
if(lastDigit > secondLastDigit)
146+
{
147+
return true;
148+
}
149+
return false;
150+
}
151+
return false;
152+
}// end of method isHigher
153+
/**
154+
* the method return the floor number of the class
155+
* @param: None
156+
* @return: int
157+
*/
158+
public int getFloorNumber()
159+
{
160+
if(this.getClassNum() < 100)
161+
{
162+
return 0;
163+
}
164+
else
165+
{
166+
return this.getClassNum() / 100;
167+
}
168+
}// end of method getFloorNumber
169+
}// end of class Clsrm

Exam2011JavaA/College.java

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* College.java
3+
* the class reprsents a College
4+
* Author : liron mizrhai
5+
*/
6+
public class College
7+
{
8+
public final static int NUM_OF_COURSES_OR_CLSRM = 20;
9+
private Course[] _courses;
10+
private Clsrm[] _clsrms;
11+
/**
12+
* the methd return the most popular course in the college
13+
* @param: None
14+
* @return: Course
15+
*/
16+
public Course mostPopular()
17+
{
18+
int index = 0;
19+
for(int i = 1; i < _courses.length; i++)// 4
20+
{
21+
if(_courses[i].getNumOfStudents() > _courses[index].getNumOfStudents())
22+
{
23+
index = i;
24+
}
25+
}
26+
return _courses[index];
27+
}// end of method mostPopular
28+
/**
29+
* the method return the beggest clsss in the college
30+
* @param: None
31+
* @return: Clsrm
32+
*/
33+
public Clsrm biggestClsrm()
34+
{
35+
int index = 0;
36+
for(int i = 1; i < _clsrms.length; i++)
37+
{
38+
if(_clsrms[i].getClassPlaces() > _clsrms[index].getClassPlaces())
39+
{
40+
index = i;
41+
}
42+
}
43+
return _clsrms[index];
44+
}// end of method biggestClsrm
45+
/**
46+
* the method return how many clsrms are suitable for handicapped people
47+
* @param: None
48+
* @return: int
49+
*/
50+
public int howManyHandi()
51+
{
52+
int num = 0;
53+
for(int i = 0; i < _clsrms.length; i++)
54+
{
55+
if(_clsrms[i].handicappedSuitable() && _clsrms[i].getAvailable())
56+
{
57+
num++;
58+
}
59+
}
60+
return num;
61+
}// end of method howManyHandi
62+
/**
63+
* the method return how many clsrms are suitable for handicapped people
64+
* @param: None
65+
* @return: int
66+
*/
67+
public int howManyOnTopFloor()
68+
{
69+
int biggestFloor = getBiggestFloor();
70+
int numTopFloor = 0;
71+
for(int i = 0; i < _clsrms.length; i++)
72+
{
73+
if(_clsrms[i].getFloorNumber() == biggestFloor)
74+
{
75+
numTopFloor++;
76+
}
77+
}
78+
return numTopFloor;
79+
}// end of method howManyOnTopFloor
80+
81+
private int getBiggestFloor()
82+
{
83+
int index = 0;
84+
for(int i = 1; i < _clsrms.length; i++)
85+
{
86+
if(_clsrms[i].isHigher(_clsrms[index]))
87+
{
88+
index = i;
89+
}
90+
}
91+
return _clsrms[index].getFloorNumber();
92+
}// end of method getBiggestFloor
93+
94+
}// end of class College

Exam2011JavaA/Course.java

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/**
2+
* Course.java
3+
* the class reprsents a course
4+
* Author: liron mizrhai
5+
*/
6+
public class Course
7+
{
8+
private String _courseName;
9+
private int _numOfStudents;
10+
private Clsrm _courseClsrm;
11+
/**
12+
* constractor of the class course
13+
* @param: String courseName, int numOfStudents
14+
* @retrurn: None
15+
*/
16+
public Course(String courseName, int numOfStudents)
17+
{
18+
_courseName = courseName;
19+
if( numOfStudents > -1)
20+
{
21+
_numOfStudents = numOfStudents;
22+
}
23+
else
24+
{
25+
_numOfStudents = -1;
26+
}
27+
_courseClsrm = null;
28+
}// end of method Course
29+
/**
30+
* the method return the num of students in the course
31+
* @param: None
32+
* @retrurn: int
33+
*/
34+
public int getNumOfStudents()
35+
{
36+
return _numOfStudents;
37+
}// end of method getNumOfStudents
38+
/**
39+
* the method return name of the course
40+
* @param: None
41+
* @retrurn: String
42+
*/
43+
public String getCourseName()
44+
{
45+
return _courseName;
46+
}// end of method getCourseName
47+
/**
48+
* the method return the clsrm of the course
49+
* @param: None
50+
* @retrurn: Clsrm (null)
51+
*/
52+
public Clsrm getClsrm()
53+
{
54+
if(_courseClsrm == null)
55+
{
56+
return null;
57+
}
58+
return _courseClsrm;
59+
}// end of method getClsrm
60+
/**
61+
* the method set the clsrm of the course
62+
* @param: Clsrm cls
63+
* @retrurn: None
64+
*/
65+
public void setClsrm(Clsrm cls)
66+
{
67+
if(_numOfStudents <= cls.getClassPlaces() && cls.getAvailable())
68+
{
69+
_courseClsrm = new Clsrm(cls);
70+
cls.setAvilable(false);
71+
}
72+
}// end of method setClsrm
73+
/**
74+
* the method return if the course is suitable for handicapped
75+
* @param: boolean handi
76+
* @retrurn: boolean
77+
*/
78+
public boolean clsrmSuitable(boolean handi)
79+
{
80+
if(!handi)
81+
{
82+
return true;
83+
}
84+
else if(_courseClsrm == null)
85+
{
86+
return false;
87+
}
88+
else if(handi && _courseClsrm.handicappedSuitable())
89+
{
90+
return true;
91+
}
92+
return false;
93+
}// end of method clsrmSuitable
94+
/**
95+
* the method return if the class is morePopular
96+
* class is more popular if the number of students in the course is higher
97+
* @param: Course c
98+
* @retrurn: boolean
99+
*/
100+
public boolean morePopular(Course c)
101+
{
102+
if(_numOfStudents > c._numOfStudents)
103+
{
104+
return true;
105+
}
106+
return false;
107+
}// end of method morePopular
108+
}// end of class Course

0 commit comments

Comments
 (0)