Docsity

Java Programming Course, Summaries of Global studies

Toggle sidebar
bg1
Java Programming Course
Java Class Methods
we now have a student name and an exam name. Both are stored
in the field names in the StudentResults class. We can now add an
exam score.
Add the following new method to your class, just after your
examName method:
This new method has the name!examScore, with an int variable
called!aScore!between its round brackets. It's set to return a String
value. The method itself just combines the score with the string " out
of 50". So if the value in aScore is 30, the text "30 out of 50" will be
stored in the Exam_Score field.
In your ExamDetails class, add the following line:
String score = aStudent.examScore(30);
So we call the new!examScore!method and hand it a value of 30.
The value in the!Exam_Score!field is returned, and then stored in a
string variable that we've called score.
pf3

Partial preview of the text

Download Java Programming Course and more Summaries Global studies in PDF only on Docsity!

Java Programming Course

Java Class Methods

we now have a student name and an exam name. Both are stored in the field names in the StudentResults class. We can now add an exam score. Add the following new method to your class, just after your examName method: This new method has the name examScore , with an int variable called aScore between its round brackets. It's set to return a String value. The method itself just combines the score with the string " out of 50". So if the value in aScore is 30, the text "30 out of 50" will be stored in the Exam_Score field. In your ExamDetails class, add the following line: String score = aStudent.examScore(30); So we call the new examScore method and hand it a value of 30. The value in the Exam_Score field is returned, and then stored in a string variable that we've called score.

Add a new print line method so that your code looks like ours below: When the programme is run, the Output window now looks like this: So we have the student name, the exam name, and the score out of

  1. We can now add a grade to the output. We'll use a single letter for the grade: A, B, C, D, or E. If the students gets 41 or over, we'll an award an A; if the score is between 31 and 40, the grade will be B; for a score of 21 to 30 a C grade will be awarded; a D grade is between 11 and 20; and an E is for scores between 0 and 10.