A GradeBook Example : In this example ,GradeBook class has one attribute and some methods to access this attribute data: public class GradeBook { private String cname; public void setName(String name){ cname=name; } public String getName(){ return cname; } public void showMessage(){ System.out.printf("Welcome to the Grade Book of %s \n", getName()); } } //End of Class Test Class Example that uses GradeBook class: public class GradeBookTest { public static void main(String[] args) { GradeBook b1=new GradeBook(); GradeBook b2=new GradeBook(); System.out.printf("Course Name %s \n",b1.getName()); System.out.printf("Course Name %s \n",b2.getName()); b1.setName("Object Oriented Programming"); b2.setName("Data Structure using Java"); System.out.printf("Course Name %s \n",b1.getName()); System.out.printf("Course Name %s \n",b2.getName()); b1.showMessage(); b2.showMessage(); } }//End class Exercise: You need to include another two attribute with name “marks” and “totalstudents” in GradeBook Class, Use functions to set and get its value and write another function “CalculateGrade()” [function can return Boolean value true or false, for example if marks are >50 it should return true, otherwise return false. Use this function in main method to test Pass and fail condition. Use them in GradeBookTest Class
A GradeBook Example : In this example ,GradeBook class has one attribute
and some methods to access this attribute data:
public class GradeBook {
private String cname;
public void setName(String name){
cname=name;
}
public String getName(){
return cname;
}
public void showMessage(){
System.out.printf("Welcome to the Grade Book of %s \n", getName());
}
} //End of Class
Test Class Example that uses GradeBook class:
public class GradeBookTest {
public static void main(String[] args) {
GradeBook b1=new GradeBook();
GradeBook b2=new GradeBook();
System.out.printf("Course Name %s \n",b1.getName());
System.out.printf("Course Name %s \n",b2.getName());
b1.setName("Object Oriented
b2.setName("Data Structure using Java");
System.out.printf("Course Name %s \n",b1.getName());
System.out.printf("Course Name %s \n",b2.getName());
b1.showMessage();
b2.showMessage();
}
}//End class
Exercise:
You need to include another two attribute with name
“marks” and “totalstudents” in GradeBook Class, Use
functions to set and get its value and write another
function “CalculateGrade()” [function can return Boolean
value true or false, for example if marks are >50 it
should return true, otherwise return false. Use this
function in main method to test Pass and fail condition.
Use them in GradeBookTest Class.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images