Access over 20 million homework & study documents

A) Write a Java class Student with three fields name, mark and maxs

Content type
User Generated
Rating
Showing Page:
1/7
a) Write a Java class Student with three fields: name, mark
and maxscore representing a student who has scored mark
out of maxscore. The class has a constructor and two
methods:
addBonus adds a given bonus score to the students mark;
toString returns a String summarising the current state of
the Student. You should select suitable types and
parameters for your class its constructor and methods.
b) Using your Student class from a), write an efficient
method
public Student topStudent(ArrayList cits1001) that returns
the Student object with the highest percentage score from
a given ArrayList of Students called cits1001. Write a
suitable helper method that returns a students mark as a
percentage rounded to the nearest integer. Javadoc
comments are not required for this question.
Solution
Student.java
import java.util.ArrayList;
public class Student {
private String name;
private double mark;
private double maxscore;

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/7
public Student(){
}
public Student(String name, double mark, double
maxmark){
this.name = name;
this.mark = mark;
this.maxscore = maxmark;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getMark() {
return mark;
}
public void setMark(double mark) {
this.mark = mark;
}
public double getMaxscore() {
return maxscore;
}
public void setMaxscore(double maxscore) {
this.maxscore = maxscore;

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/7

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 7 pages?
Access Now
Unformatted Attachment Preview
a) Write a Java class Student with three fields: name, mark and maxscore representing a student who has scored mark out of maxscore. The class has a constructor and two methods: addBonus adds a given bonus score to the student’s mark; toString returns a String summarising the current state of the Student. You should select suitable types and parameters for your class its constructor and methods. b) Using your Student class from a), write an efficient method public Student topStudent(ArrayList ci ts1001) that returns the Student object with the highest percentage score from a given ArrayList of Students called cits1001. Write a suitable helper method that returns a student’s mark as a percentage rounded to the nearest integer. Javadoc comments are not required for this question. Solution Student.java import java.util.ArrayList; public class Student { private String name; private double mark; private double maxscore; public Student(){ } public Student(String name, double mark, double maxmark){ this.name = name; this.mark = mark; this.maxscore = maxmark; } public String getName() { return name; } public void setName(String name) { this.name = name; } public double getMark() { return mark; } public void setMark(double mark) { this.mark = mark; } public double getMaxscore() { return maxscore; } public void setMaxscore(double maxscore) { this.maxscore = maxscore; } public void addBonus(double bonus){ double newmarks = getMark() + bonus; if(newmarks ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Really great stuff, couldn't ask for more.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4