Question: Part A Lets consider the following java class. c lass Student { String name; public i nt grade; // grade between 0 and 100 (condition

Part A

Lets consider the following java class.

class Student

{

String name;

public int grade; // grade between 0 and 100 (condition on Grade);

public void increment ()

{

grade ++;

}

public void decrement ()

{

// (condition on Grade)

grade - -;

}

public int getGrade()

{

return grade;

}

public void setGrade(int G)

{

// (condition on Grade)

grade = g;

}

Public addGrade(int x)

{

// (condition on Grade)

grade +=x;

}

void DisplayGrade()

{

System.out.println ("Grade = +grade);

}

}

Complete the following table

Main function

S1.grade

S2.grade

Public static void main()

{

Student s1= new Student();

s1.DisplayGrade()

Student s2=new Student();

s1.grade = 59;

s1.increment();

s1.increment();

s1.decrement(); s2.addGrade(10);

s1.setGrade(55);

s1.setgrade(s2.getGrade());

for(int i=1;i<=10:i++)

s1.increment();

s2.decrement();

}

Version 2

Here we change grade from public to private

public int grade;

S1.grade

S2.grade

Error or remark if any

public static void main()

{

Student s1= new Student();

Student s2=new Student();

s1.grade = 59;

s1.setgrade(100);

s1.incrementgrade();

s2.addgrade(s1.getGrade());

s1.setgrade(0);

s1.decrement();

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!