Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

4. Describe the role of narratives in constructing history.

Answered: 1 week ago

Question

1. Identify six different types of history.

Answered: 1 week ago