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
9831001
Session 2
Commits
d675003e
Commit
d675003e
authored
Feb 29, 2020
by
Roholla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial commit
parents
Pipeline
#2056
canceled with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
182 additions
and
0 deletions
+182
-0
Main.java
Main.java
+164
-0
Run.java
Run.java
+18
-0
No files found.
Main.java
0 → 100644
View file @
d675003e
public
class
Main
{
/**
* The Student class represents a student in a student administration system.
* It holds the student details relevant in our context.
*
* @author Roholla
* @version 0.0
*/
public
static
class
Student
{
/**
* student’s first name
*/
private
String
firstName
;
/**
* student’s last name
*/
private
String
lastName
;
/**
* student's ID
*/
private
String
id
;
/**
* student's grade
*/
private
int
grade
;
/**
* Create a new student with a given name and ID number.
*
* @param fName student's first name
* @param lName student's last name
* @param sID student's ID
*/
public
Student
(
String
fName
,
String
lName
,
String
sID
)
{
firstName
=
fName
;
lastName
=
lName
;
id
=
sID
;
grade
=
0
;
}
/**
* @return student's first name
*/
public
String
getFirstName
()
{
return
firstName
;
}
/**
* @return student's last name
*/
public
String
getLastName
()
{
return
lastName
;
}
/**
* @return student's id
*/
public
String
getId
()
{
return
id
;
}
/**
* @return student's grade
*/
public
int
getGrade
()
{
return
grade
;
}
/**
* @param firstName student's first name to be set
*/
public
void
setFirstName
(
String
firstName
)
{
this
.
firstName
=
firstName
;
}
/**
* @param lastName student's last name to be set
*/
public
void
setLastName
(
String
lastName
)
{
this
.
lastName
=
lastName
;
}
/**
* @param id student's id to be set
*/
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
/**
* @param grade student's grade to be set
*/
public
void
setGrade
(
int
grade
)
{
this
.
grade
=
grade
;
}
/**
* 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
);
}
}
public
static
class
Lab
{
private
Student
[]
students
;
private
int
avg
;
private
String
day
;
private
int
capacity
;
private
int
currentSize
;
public
Lab
(
int
capacity
,
String
day
)
{
students
=
new
Student
[
capacity
];
this
.
capacity
=
capacity
;
this
.
day
=
day
;
currentSize
=
0
;
avg
=
0
;
}
public
void
enrollStudent
(
Student
std
)
{
if
(
currentSize
<
capacity
)
students
[
currentSize
++]
=
std
;
else
System
.
out
.
println
(
"Lab is full!!!"
);
}
public
void
print
()
{
for
(
int
i
=
0
;
i
<
currentSize
;
i
++)
{
System
.
out
.
print
((
i
+
1
)
+
". "
);
students
[
i
].
print
();
}
}
public
Student
[]
getStudents
()
{
return
students
;
}
public
void
setStudents
(
Student
[]
students
)
{
for
(
Student
si:
students
)
enrollStudent
(
si
);
}
public
int
getAvg
()
{
return
avg
;
}
public
void
calculateAvg
()
{
int
sum
=
0
;
for
(
int
i
=
0
;
i
<
currentSize
;
i
++)
sum
+=
students
[
i
].
getGrade
();
avg
=
sum
/
currentSize
;
}
public
String
getDay
()
{
return
day
;
}
public
void
setDay
(
String
day
)
{
this
.
day
=
day
;
}
public
int
getCapacity
()
{
return
capacity
;
}
public
void
setCapacity
(
int
capacity
)
{
this
.
capacity
=
capacity
;
}
}
}
Run.java
0 → 100644
View file @
d675003e
public
class
Run
{
public
static
void
main
(
String
[]
args
)
{
Main
.
Student
std1
=
new
Main
.
Student
(
"Ehsan"
,
"Edalat"
,
"9031066"
);
Main
.
Student
std2
=
new
Main
.
Student
(
"Seyed"
,
"Ahmadpanah"
,
"9031806"
);
Main
.
Student
std3
=
new
Main
.
Student
(
"Ahmad"
,
"Asadi"
,
"9031054"
);
std1
.
setGrade
(
15
);
std2
.
setGrade
(
11
);
std3
.
setFirstName
(
"HamidReza"
);
Main
.
Student
[]
students
=
{
std1
,
std2
,
std3
};
Main
.
Lab
lab
=
new
Main
.
Lab
(
3
,
"MON"
);
lab
.
setStudents
(
students
);
lab
.
print
();
}
}
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