Java Reference
In-Depth Information
percentGain
—value-returning method to return the change in the
stock value from the previous closing price and today's closing price as a
percentage
shareValues
—value-returning method to calculate and return the
total values of the shares owned
default constructor—the default value of
name
is the empty string
""
;the
default values of
previousPrice
,
closingPrice
,and
numberOfShares
are
0
.
constructor with parameters—sets the values of the instance variables
name
,
previousPrice
,
closingPrice
, and
numberOfShares
to the
values specified by the user
d.
Write the definitions of the methods and constructors of the
class
Stock
as described in part c.
26.
Consider the following definition of the
class
MyClass
:
class
MyClass
{
private int
x;
private static int
count;
//default constructor
//Postcondition: x = 0
public
MyClass()
{
8
//write the definition
}
//constructor with a parameter
//Postcondition: x = a
public
MyClass(
int
a)
{
//write the definition
}
//Method to set the value of x
//Postcondition: x = a
public void
setX(
int
a);
{
//write the definition
}
//Method to output x.
public void
printX()
{
//write the definition
}
Search WWH ::
Custom Search