Challenge 3: Calculate the Student's Total Marks
In this exercise, you have to calculate the student's total marks using the concept of Classes
We'll cover the following...
We'll cover the following...
Problem Statement
Write a Java class called Student with
-
privatefields:-
name(Stringtype) -
mark1andmark2(double type)
-
And methods:
-
getMarks(int markNumber), a method which should returnmark1ifmarkNumberequals 1 andmark2otherwise. -
calcTotal()method should take the two marks entered and return their sum.
Also define two constructors:
- A default constructor that takes no parameters and initializes the values to zeros and
null. - A constructor that takes the three variables and sets them as the values of the appropriate fields.
Input
Name of the student and the marks obtained in the first and second tests
Output
Sum of both marks
Sample Input
Student student = new Student("Jack", 60, 70);
Sample Output
getMarks(1) => 60
getMarks(2) => 70
calcTotal() => 130.0