Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dev-oo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ethan Robert
dev-oo
Commits
b2867537
Commit
b2867537
authored
1 month ago
by
Ethan Robert
Browse files
Options
Downloads
Patches
Plain Diff
Added Student and UseStudent classes
parent
6691db5b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/tp04/Student.java
+120
-0
120 additions, 0 deletions
src/tp04/Student.java
src/tp04/UseStudent.java
+14
-0
14 additions, 0 deletions
src/tp04/UseStudent.java
with
134 additions
and
0 deletions
src/tp04/Student.java
0 → 100644
+
120
−
0
View file @
b2867537
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package
tp04
;
import
java.util.Arrays
;
/**
*
* @author ethan
*/
public
class
Student
{
private
Person
pers
;
private
double
[]
grades
;
private
int
realGradeLength
()
{
int
count
=
0
;
for
(
int
i
=
0
;
i
<
this
.
grades
.
length
;
i
++)
{
if
(
this
.
grades
[
i
]
!=
-
1.0
)
{
count
++;
}
}
return
count
;
}
public
Student
(
Person
pers
,
double
[]
grades
)
{
this
.
pers
=
pers
;
this
.
grades
=
grades
;
}
public
Student
(
String
forename
,
String
name
,
double
[]
grades
)
{
this
.
pers
=
new
Person
(
forename
,
name
);
this
.
grades
=
grades
;
}
public
Student
(
String
forename
,
String
name
,
double
grade
)
{
this
.
pers
=
new
Person
(
forename
,
name
);
this
.
grades
=
new
double
[]{
grade
};
}
public
String
getName
()
{
return
this
.
pers
.
getName
();
}
public
String
getForename
()
{
return
this
.
pers
.
getForename
();
}
public
void
setName
(
String
newName
)
{
this
.
pers
.
setName
(
newName
);
}
public
void
setForename
(
String
newForename
)
{
this
.
pers
.
setForename
(
newForename
);
}
public
int
getID
()
{
return
this
.
pers
.
getID
();
}
public
String
toString
()
{
String
gradesString
=
"["
;
for
(
int
i
=
0
;
i
<
this
.
grades
.
length
;
i
++)
{
gradesString
+=
this
.
grades
[
i
];
if
(
i
<
this
.
grades
.
length
-
1
)
{
gradesString
+=
", "
;
}
}
gradesString
+=
"]]"
;
return
"Student["
+
this
.
pers
+
" = "
+
gradesString
;
}
public
double
[]
getGrades
()
{
return
this
.
grades
;
}
public
boolean
equals
(
Object
other
)
{
if
(
other
==
null
)
{
return
false
;
}
if
(
other
.
getClass
()
==
this
.
getClass
())
{
Student
otherStudent
=
(
Student
)
other
;
boolean
arrayEquals
=
true
;
double
[]
otherStudentGrades
=
otherStudent
.
getGrades
();
if
(
otherStudentGrades
.
length
==
this
.
grades
.
length
)
{
for
(
int
i
=
0
;
i
<
this
.
grades
.
length
;
i
++)
{
arrayEquals
=
this
.
grades
[
i
]
!=
otherStudentGrades
[
i
];
}
}
return
otherStudent
.
getID
()
==
this
.
pers
.
getID
()
&&
arrayEquals
;
}
return
false
;
}
public
double
getAverage
()
{
double
sum
=
0.0
;
for
(
int
i
=
0
;
i
<
this
.
grades
.
length
;
i
++)
{
if
(
this
.
grades
[
i
]
!=
-
1.0
)
{
sum
+=
this
.
grades
[
i
];
}
}
return
sum
/
this
.
realGradeLength
();
}
public
void
addGrade
(
double
grade
)
{
if
(
this
.
grades
.
length
!=
this
.
realGradeLength
())
{
for
(
int
i
=
0
;
i
<
this
.
grades
.
length
;
i
++)
{
if
(
this
.
grades
[
i
]
==
-
1.0
)
{
this
.
grades
[
i
]
=
grade
;
}
}
}
else
{
this
.
grades
=
Arrays
.
copyOf
(
this
.
grades
,
this
.
grades
.
length
+
1
);
this
.
grades
[
this
.
grades
.
length
-
1
]
=
grade
;
}
}
}
This diff is collapsed.
Click to expand it.
src/tp04/UseStudent.java
0 → 100644
+
14
−
0
View file @
b2867537
package
tp04
;
public
class
UseStudent
{
public
static
void
main
(
String
[]
args
)
{
Person
person1
=
new
Person
(
"John"
,
"Doe"
);
Student
student1
=
new
Student
(
person1
,
new
double
[]{
12.5
,
14.0
});
Student
student2
=
new
Student
(
person1
,
new
double
[]{
12.5
,
14.5
});
Student
student3
=
new
Student
(
"Jane"
,
"Smith"
,
14.0
);
System
.
out
.
println
(
"student1 == student2: "
+
student1
.
equals
(
student2
));
System
.
out
.
println
(
"student1 == student3: "
+
student1
.
equals
(
student3
));
System
.
out
.
println
(
"student2 == student3: "
+
student2
.
equals
(
student3
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment