Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Java class Demo is defined as follows: class Demo { private double val1; // the first data member private double val2; // the second

The Java class Demo is defined as follows:

class Demo {

private double val1; // the first data member

private double val2; // the second data member

public void setValues(double num1, double num2){

val1 = num1;

val2 = num2;

}

public double getValue1(void){

return (val1);

}

public double getValue2(void) {

return (val2);

}

public double getAverage(void){

return( (valu1 + valu2) / 2);

}

}

Define the class DemoTest1 with the following methods:

A. Static method addDemo ( ) 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 that 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 ( ).

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

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

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions

Question

=+f) Let P(A) = I (wo) for A Fo, and assume (wg) E o($).

Answered: 1 week ago