Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
AP-lab-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
9931099
AP-lab-2
Commits
29fc00fc
Commit
29fc00fc
authored
Mar 11, 2021
by
9931099
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dastoor kar 2 added
parents
Pipeline
#5815
failed with stages
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
354 additions
and
0 deletions
+354
-0
Department.java
Department.java
+102
-0
Lab.java
Lab.java
+119
-0
Run.java
Run.java
+46
-0
Student.java
Student.java
+87
-0
No files found.
Department.java
0 → 100644
View file @
29fc00fc
public
class
Department
{
//number of labs
private
int
lab
;
//labs
private
Lab
[]
labs
;
//number of classes
private
int
classes
;
//number of vending machines
private
int
vendingMachines
;
// array of masters names
private
String
[]
masters
;
//recentsize
private
int
recentSize
;
/**
* constructor
* creates a Department w given params
* @param lab
* @param masters
*/
public
Department
(
int
lab
,
String
[]
masters
)
{
this
.
lab
=
lab
;
this
.
masters
=
masters
;
classes
=
0
;
vendingMachines
=
0
;
recentSize
=
0
;
labs
=
new
Lab
[
lab
];
}
/**
* method to add a lab to a department
* @param lb
*/
public
void
addLab
(
Lab
lb
)
{
if
(
recentSize
<
lab
)
{
labs
[
recentSize
]
=
lb
;
recentSize
++;
}
else
System
.
out
.
println
(
"Lab is full!!!"
);
}
/**
* classes setter
* @param classes
*/
public
void
setClasses
(
int
classes
)
{
this
.
classes
=
classes
;
}
/**
* gets classes
* @return
*/
public
int
getClasses
()
{
return
classes
;
}
/**
* sets vending machines
* @param vendingMachines
*/
public
void
setVendingMachines
(
int
vendingMachines
)
{
this
.
vendingMachines
=
vendingMachines
;
}
/**
* gets vendingmachines
* @return
*/
public
int
getVendingMachines
()
{
return
vendingMachines
;
}
/**
* just a method to print some info
*/
public
void
printer
()
{
int
students
=
0
;
for
(
int
i
=
0
;
i
<
lab
;
i
++)
students
+=
labs
[
i
].
getCurrentSize
();
System
.
out
.
println
(
"Number of Students : "
+
students
);
int
scoresum
=
0
;
for
(
int
i
=
0
;
i
<
lab
;
i
++)
scoresum
+=
labs
[
i
].
getAvg
()*
labs
[
i
].
getCurrentSize
();
int
average
=
scoresum
/
students
;
System
.
out
.
println
(
"average of all students id : "
+
average
);
System
.
out
.
println
(
"There are "
+
vendingMachines
+
" vending machines in department"
);
System
.
out
.
println
(
"There are "
+
classes
+
" classes in department"
);
System
.
out
.
println
(
"Masters are:"
);
for
(
int
i
=
0
;
i
<
masters
.
length
;
i
++)
System
.
out
.
println
(
masters
[
i
]);
}
}
Lab.java
0 → 100644
View file @
29fc00fc
public
class
Lab
{
//an array of type Student
private
Student
[]
students
;
//average grades
private
int
avg
;
//week's days
private
String
day
;
// class capacity
private
int
capacity
;
//currentsize
private
int
currentSize
;
/**
* create a lab with given capacity and day name
* @param cap for capacity
* @param d for day
*/
public
Lab
(
int
cap
,
String
d
)
{
capacity
=
cap
;
day
=
d
;
avg
=
0
;
currentSize
=
0
;
students
=
new
Student
[
capacity
];
}
/**
* method to add students to a lab
* @param std
*/
public
void
enrollStudent
(
Student
std
)
{
if
(
currentSize
<
capacity
)
{
students
[
currentSize
]
=
std
;
currentSize
++;
}
else
{
System
.
out
.
println
(
"Lab is full!!!"
);
}
}
/**
* printing labs students info!
*/
public
void
print
()
{
for
(
int
i
=
0
;
i
<
currentSize
;
i
++)
{
System
.
out
.
println
(
"Name: "
+
students
[
i
].
getFirstName
()+
" "
+
students
[
i
].
getLastNameName
()+
", Id: "
+
students
[
i
].
getId
()+
" ,grade: "
+
students
[
i
].
getGrade
());
}
System
.
out
.
println
(
"average of class is:"
+
avg
);
}
/**
* get the array of type Student
* @return students
*/
public
Student
[]
getStudents
()
{
return
students
;
}
/**
* set students
* @param students
*/
public
void
setStudents
(
Student
[]
students
)
{
this
.
students
=
students
;
}
/**
* get average
* @return avg
*/
public
int
getAvg
()
{
return
avg
;
}
/**
* method to calcuate average grades
*/
public
void
calculateAvg
()
{
int
sum
=
0
;
for
(
int
i
=
0
;
i
<
currentSize
;
i
++)
sum
+=
students
[
i
].
getGrade
();
avg
=
sum
/
currentSize
;
}
/**
* get day
* @return the day
*/
public
String
getDay
()
{
return
day
;
}
/**
* day set method
* @param day
*/
public
void
setDay
(
String
day
)
{
this
.
day
=
day
;
}
/**
*
* @return capacity
*/
public
int
getCapacity
()
{
return
capacity
;
}
/**
* sets capacity
* @param capacity
*/
public
void
setCapacity
(
int
capacity
)
{
this
.
capacity
=
capacity
;
}
public
int
getCurrentSize
()
{
return
currentSize
;
}
}
Run.java
0 → 100644
View file @
29fc00fc
/**
* this class is made to define a lab consisting of a bunch of students
* @author Amirfazel
* @version 0.0
*/
public
class
Run
{
public
static
void
main
(
String
[]
args
)
{
Student
std1
=
new
Student
(
"ali"
,
"rezaii"
,
"9931065"
);
Student
std2
=
new
Student
(
"mohamad"
,
"karami"
,
"9923054"
);
Student
std3
=
new
Student
(
"kazem"
,
"kazemi"
,
"9923012"
);
Student
std4
=
new
Student
(
"kazem"
,
"kazemi"
,
"9923012"
);
Student
std5
=
new
Student
(
"mahdi"
,
"azizi"
,
"9923013"
);
Student
std6
=
new
Student
(
"khorshid"
,
"gholami"
,
"9923015"
);
std1
.
setGrade
(
12
);
std2
.
setGrade
(
15
);
std3
.
setGrade
(
19
);
std4
.
setGrade
(
16
);
std5
.
setGrade
(
17
);
std6
.
setGrade
(
20
);
Lab
lab1
=
new
Lab
(
12
,
"monday"
);
lab1
.
enrollStudent
(
std1
);
lab1
.
enrollStudent
(
std2
);
lab1
.
enrollStudent
(
std3
);
lab1
.
calculateAvg
();
Lab
lab2
=
new
Lab
(
10
,
"wednesday"
);
lab2
.
enrollStudent
(
std4
);
lab2
.
enrollStudent
(
std5
);
lab2
.
enrollStudent
(
std6
);
lab2
.
calculateAvg
();
lab1
.
print
();
lab2
.
print
();
String
[]
masters
={
"zeinali"
,
"kalabsi"
,
"edalat"
};
Department
dep1
=
new
Department
(
2
,
masters
);
dep1
.
addLab
(
lab1
);
dep1
.
addLab
(
lab2
);
dep1
.
setClasses
(
13
);
dep1
.
setVendingMachines
(
2
);
// dep1.printer();
}
}
Student.java
0 → 100644
View file @
29fc00fc
/**
* The Student class represents a student in a student administration system.
*
* * It holds the student details relevant in our context.
* * * @author fazel * @version 0.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
;
/*
Create a student with given name and id
@param fname first name of student
@param lname last name of student
@param Sid first students ID
*/
public
Student
(
String
fname
,
String
lname
,
String
Sid
)
{
firstName
=
fname
;
lastName
=
lname
;
id
=
Sid
;
grade
=
0
;
}
/**
* @param grade set student's grade
*/
public
void
setGrade
(
int
grade
){
this
.
grade
=
grade
;
}
/**
* get students grade
* @return grade
*/
public
int
getGrade
()
{
return
grade
;
}
/**
* get students grade
* @return grade
*/
public
String
getId
()
{
return
id
;
}
/**
* @param fname set first name of student
*/
public
void
nameSet
(
String
fname
)
{
firstName
=
fname
;
}
/**
* get first name of student
* @return firstname field
*/
public
String
getFirstName
()
{
return
firstName
;
}
/**
* get last first name of student
* @return last name field
*/
public
String
getLastNameName
()
{
return
lastName
;
}
/**
* printing students last name and ID
*/
public
void
print
()
{
System
.
out
.
println
(
lastName
+
", student ID: "
+
id
+
", grade: "
+
grade
);
}
}
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