Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The class Demo is defined as follows: class Demo { private int vall; private int val2; public void setValues(int num1, int num2) { val1
The class Demo is defined as follows: class Demo { private int vall; private int val2; public void setValues(int num1, int num2) { val1 = num1; val2 = num2; } public int getValue1() { return (val1); } public int getValue2() { return (val2); } public int getAverage() { return( (valu1 + valu2) / 2); } // the first data member // the second data member Define the class Exercise 01 with the following methods: A. Static method add Demo () that receives as arguments two objects of the class Demo and then builds and returns another object of the class Demo such that the value of each of its member variables is the sum of the values of the corresponding member variables of its arguments. B. Static method incrDemo2 that receives as argument an object of the class Demo and increments the value of each of its member variables by 5. c. method main does the following: 1. Declare object item of the class Demo. 2. Read the values for the instance variables of object item, and set their values. 3. Compute the average of the values of the instance variables of object item and print it. 4. Declare object obj1 and set its instance variables to 5 and 7 respectively. 5. Declare object obj2 and set its instance variables to 14 and 9 respectively. 6. Create a third object named objR such that the value of each of its instance variables is the sum of the values of the corresponding instance variables of objects obj1 and obj2 by calling addDemo (). Activate Windows Go to Settings to activate Windows. 7. Increment the value of each instance variable of object obj1 by 5 by calling incrDemo(). 8. Print the values of the instance variables of the objects objR and obj1.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
class Demo private int val1 private int val2 public void setValuesint num1 int num2 val1 num1 val2 n...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started