Example Student class. The student class has four properties namely roll number, name, standard and total marks. All these properties have respective methods to get and set object values.
The student class has two constructors, one is the default, and another one is overloaded to accept all four properties and set them to object properties. Student class also has overridden the toString
method from Object class which prints the nice summary when student object is printed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
package com.javacodeexamples.common; public class Student { /* Student properties */ private String rollNumber; private String name; private String standard; private int totalMarks; //default constructor public Student(){ } /* * overloaded constructor to set all * student object properties at once */ public Student(String rollNumber, String name, String standard, int totalMarks){ /* * this.variable_name always refer to class level properties */ //set object properties from the arguments/parameters this.rollNumber = rollNumber; this.name = name; this.standard = standard; this.totalMarks = totalMarks; } /* Methods to get and set the student properties */ public String getRollNumber() { return rollNumber; } public void setRollNumber(String rollNumber) { this.rollNumber = rollNumber; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getStandard() { return standard; } public void setStandard(String standard) { this.standard = standard; } public int getTotalMarks() { return totalMarks; } public void setTotalMarks(int totalMarks) { this.totalMarks = totalMarks; } /* * This method will product nice summary of Student object * when printed using System.out.println in the format below * * [01 : Raj : 10th : 200] */ public String toString(){ StringBuilder sbStudent = new StringBuilder(); sbStudent.append("["); sbStudent.append(getRollNumber()); sbStudent.append(" : "); sbStudent.append(getName()); sbStudent.append(" : "); sbStudent.append(getStandard()); sbStudent.append(" : "); sbStudent.append(getTotalMarks()); sbStudent.append("]"); return sbStudent.toString(); } } |
The student class has been referred to by many of the website examples.
Please let me know your views in the comments section below.
Output is not found
HI kindly help me with this question
a- Create a class named Student, the class must contain the following:
1- Variables of the student’s grades
2- A constructor that will identify these grades
3- A method that will find the GPA for the students
b- Create client code to test the classes.
c- Draw the UML diagram for these two classes
getting this error
Error: Could not find or load main class Student
Caused by: java.lang.ClassNotFoundException: Student