Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
Session 2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9931074
Session 2
Commits
3d3d577e
Commit
3d3d577e
authored
Mar 12, 2021
by
9931074
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Version 1.0
parent
940e513f
Pipeline
#5825
failed with stages
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
314 additions
and
0 deletions
+314
-0
Lab.java
Lab.java
+129
-0
Run.java
Run.java
+49
-0
Student.java
Student.java
+76
-0
Uni.java
Uni.java
+60
-0
No files found.
Lab.java
0 → 100644
View file @
3d3d577e
/**
* This in a class which represents a lab.
* this class includes a number of students
* in itself which are given to the defined
* lab by a method and sores them in a neat way
* @author Reza Farahbakhsh
* @since 12/3/2021
* @version 1.0
*/
public
class
Lab
{
private
int
avg
=
0
;
private
String
day
;
private
int
capacity
;
private
int
currentSize
;
private
Student
[]
students
=
new
Student
[
capacity
];
public
Lab
(
int
cap
,
String
d
)
{
capacity
=
cap
;
day
=
d
;
}
/**
* method to update the maximum capacity of lab after defining it
*/
public
void
updateSize
()
{
students
=
new
Student
[
capacity
];
}
/**
* a method to add the given student to the defined lab
* @param std
*/
public
void
enrollStudent
(
Student
std
)
{
if
(
currentSize
<
capacity
)
{
students
[
currentSize
]
=
std
;
currentSize
++;
}
else
{
System
.
out
.
println
(
"Lab is full!!!"
);
}
}
/**
* a method to print the stored information in neat way
*/
public
void
print
()
{
for
(
int
i
=
0
;
i
<
currentSize
;
i
++)
{
String
name
=
students
[
i
].
getFirstName
();
String
id
=
students
[
i
].
getId
();
int
grade
=
students
[
i
].
getGrade
();
System
.
out
.
println
(
"std first name: "
+
name
+
" std id:"
+
id
+
" std grade:"
+
grade
);
}
System
.
out
.
println
(
"Grade average: "
+
avg
);
}
/**
* method to get the current size of students from across other classes
* @return currentSize
*/
public
int
getSize
()
{
return
currentSize
;
}
/**
* method to get the array of all the students from across other classes
* @return students
*/
public
Student
[]
getStudents
()
{
return
students
;
}
/**
* method to replace an array of students from other classes to this class
* @param std
*/
public
void
setStudents
(
Student
[]
std
)
{
students
=
std
;
}
/**
* method to get the average of students' grades from across other classes
* @return avg
*/
public
int
getAvg
()
{
return
avg
;
}
/**
* method to calculate the average of grades
*/
public
void
calculateAvg
()
{
for
(
int
i
=
0
;
i
<
currentSize
;
i
++)
{
avg
+=
students
[
i
].
getGrade
();
}
avg
/=
currentSize
;
}
/**
* method to know what day the lab is starting by other classes
* @return day
*/
public
String
getDay
()
{
return
day
;
}
/**
* method to change what day lab starts by other classes
* @param d
*/
public
void
setDay
(
String
d
)
{
day
=
d
;
}
/**
* method to get the maximum capacity of students in a lab by other classes
* @return capacity
*/
public
int
getCapacity
()
{
return
capacity
;
}
/**
* method to change the maximum capacity of students by other classes
* @param cap
*/
public
void
setCapacity
(
int
cap
)
{
capacity
=
cap
;
}
}
Run.java
0 → 100644
View file @
3d3d577e
/**
* Class to run the program
* @author Reza Farahbakhsh
* @since 12/3/2021
* @version 1.0
*/
public
class
Run
{
/**
* main method to run the program
* @param args
*/
public
static
void
main
(
String
[]
args
)
{
Student
std1
=
new
Student
(
"Ehsan"
,
"Edalat"
,
"9031066"
);
Student
std2
=
new
Student
(
"Seyed"
,
"Ahmadpanah"
,
"9031806"
);
Student
std3
=
new
Student
(
"Ahmad"
,
"Asadi"
,
"9031054"
);
Student
std4
=
new
Student
(
"Reza"
,
"Farah"
,
"9931074"
);
Student
std5
=
new
Student
(
"Saman"
,
"Hoseini"
,
"9731012"
);
std1
.
print
();
std1
.
setGrade
(
15
);
std1
.
print
();
std2
.
print
();
std2
.
setGrade
(
11
);
std2
.
print
();
std3
.
print
();
std3
.
setFirstName
(
"HamidReza"
);
std3
.
setGrade
(
12
);
std3
.
print
();
std4
.
setGrade
(
18
);
std5
.
setGrade
(
20
);
Lab
lab1
=
new
Lab
(
30
,
"Saturday"
);
lab1
.
updateSize
();
Lab
lab2
=
new
Lab
(
25
,
"Sunday"
);
lab2
.
updateSize
();
lab1
.
enrollStudent
(
std1
);
lab1
.
enrollStudent
(
std2
);
lab1
.
enrollStudent
(
std3
);
lab2
.
enrollStudent
(
std4
);
lab2
.
enrollStudent
(
std5
);
lab1
.
calculateAvg
();
lab2
.
calculateAvg
();
lab1
.
print
();
lab2
.
print
();
Uni
uni1
=
new
Uni
(
"CE"
,
100
);
uni1
.
updateSize
();
uni1
.
enrollLab
(
lab1
);
uni1
.
enrollLab
(
lab2
);
uni1
.
print
();
}
}
Student.java
0 → 100644
View file @
3d3d577e
/**
* The Student class represents a student in a student
administration system.
* It holds the student details relevant in our context.
*
* @author Reza Farahbakhsh
* @version 1.0
*/
public
class
Student
{
// the student’s first name
private
String
firstName
;
// the student’s last name
private
String
lastName
;
// the student ID
private
String
id
;
//the grade
private
int
grade
;
/**
* get the first name of student
* @return firstName field
*/
public
String
getFirstName
()
{
return
firstName
;
}
/**
* get the grade of student
*/
public
void
setGrade
(
int
newGrade
)
{
grade
=
newGrade
;
}
/**
* @param fName set first name of a student
*/
public
void
setFirstName
(
String
fName
)
{
firstName
=
fName
;
}
/**
* Print the student’s last name and ID number to the
* output terminal.
*/
public
void
print
()
{
System
.
out
.
println
(
lastName
+
", student ID: "
+
id
+
", grade: "
+
grade
);
}
/**
* Get student grade
* @return Grd
*/
public
int
getGrade
()
{
return
grade
;
}
/**
* Get student ID
* @return ID
*/
public
String
getId
()
{
return
id
;
}
/**
* Create a new student with a given name and ID number.
*
* @param fName first name of student
* @param lName last name of student
* @param sID student ID
*/
public
Student
(
String
fName
,
String
lName
,
String
sID
){
firstName
=
fName
;
lastName
=
lName
;
id
=
sID
;
grade
=
0
;
}
}
Uni.java
0 → 100644
View file @
3d3d577e
/**
* This is a class that represents a university
* which in this case is consisted of one or more labs
* that each have a number of students in them.
* @author Reza Frahabkhsh
* @since 12/3/2021
* @version 1.0
*/
public
class
Uni
{
private
String
uniName
;
private
int
Size
;
private
int
current
;
private
Lab
[]
labs
=
new
Lab
[
Size
];
public
Uni
(
String
name
,
int
size
)
{
uniName
=
name
;
Size
=
size
;
}
/**
* a method to add a given lab to the uni class
* @param lab
*/
public
void
enrollLab
(
Lab
lab
)
{
labs
[
current
++]
=
lab
;
}
/**
* a method to update the size of the class after defining it
*/
public
void
updateSize
()
{
labs
=
new
Lab
[
Size
];
}
/**
* a method to print all the information stored in the class
*/
public
void
print
()
{
System
.
out
.
println
(
"----------------------------------------------------------------------------"
);
System
.
out
.
println
(
"Uni Name: "
+
uniName
);
for
(
int
i
=
0
;
i
<
current
;
i
++)
{
int
labSize
=
labs
[
i
].
getSize
();
int
labCap
=
labs
[
i
].
getCapacity
();
labs
[
i
].
calculateAvg
();
int
avg
=
labs
[
i
].
getAvg
();
String
day
=
labs
[
i
].
getDay
();
System
.
out
.
println
(
"Lab "
+
(
i
+
1
)
+
": Cap: "
+
labCap
+
" Day: "
+
day
);
for
(
int
j
=
0
;
j
<
labSize
;
j
++)
{
Student
[]
sdt
=
labs
[
i
].
getStudents
();
String
name
=
sdt
[
j
].
getFirstName
();
String
id
=
sdt
[
j
].
getId
();
int
grade
=
sdt
[
j
].
getGrade
();
System
.
out
.
println
(
"std first name: "
+
name
+
" std id:"
+
id
+
" std grade:"
+
grade
);
}
System
.
out
.
println
(
"Lab AVG: "
+
avg
);
System
.
out
.
println
(
"----------------------------------------------------------------------------"
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment