Class SlideE2

java.lang.Object
  |
  +--SlideE2

public class SlideE2
extends java.lang.Object

SlideE2 contains more little bits and pieces of example code for lecture E, Variables. The focus is on understanding how casting works, and various other details of using data values and variables in Java.


Field Summary
(package private)  double addend
          a double value for adding
(package private)  int baseA
          an integer base value
(package private)  double baseB
          a double base value
(package private)  double factor
          a double value for multiplying
(package private)  int sumA
          the current int sum
(package private)  double sumB
          the current double sum
 
Constructor Summary
SlideE2()
          Initialize the various bits that we need in the example methods.
 
Method Summary
 void caster()
          This method updates the two sum values, using a variety of casts to convert values from one type to another.
 double getCumulativeValue()
          Get the cumulative value of whatever it is we are keeping track of.
 int getSumA()
          Get the current integer sum.
 double getSumB()
          Get the current double sum.
static void main(java.lang.String[] args)
          A test harness for the code in this class.
 void notLikeThis(java.lang.String aName)
          This method has some problems.
 void reset()
          Do the actual reset of the variable values to their default values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

addend

double addend
a double value for adding


baseA

int baseA
an integer base value


baseB

double baseB
a double base value


factor

double factor
a double value for multiplying


sumA

int sumA
the current int sum


sumB

double sumB
the current double sum

Constructor Detail

SlideE2

public SlideE2()
Initialize the various bits that we need in the example methods. You can use the "Inspect" command from the right-click menu in BlueJ to see what these values are in an object that has been created using this constructor.

Method Detail

caster

public void caster()
This method updates the two sum values, using a variety of casts to convert values from one type to another. sumA is the "int" sum, and sumB is the "double" sum.


getCumulativeValue

public double getCumulativeValue()
Get the cumulative value of whatever it is we are keeping track of. Note that it is a good idea to try to isolate the callers of your method from the details of the implementation, so you might define this general purpose method to return a double value, even if the implementation happens to use ints right now. That way, if the implementation changes later, your callers are not affected.

Returns:
the current value of the accumulated sum.

getSumA

public int getSumA()
Get the current integer sum.

Returns:
the current value of the integer sum.

getSumB

public double getSumB()
Get the current double sum.

Returns:
the current value of the double sum.

main

public static void main(java.lang.String[] args)
A test harness for the code in this class.

Parameters:
args - ignored

notLikeThis

public void notLikeThis(java.lang.String aName)
This method has some problems.

The list of Java keywords is provided in the Java Language Specification, section 3.9, Keywords. The online URL is java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#229308.

Parameters:
aName - a String parameter variable that has a name collision with a local variable

reset

public void reset()
Do the actual reset of the variable values to their default values. This method can be called by a constructor, by a method in this class, or by a method in another class.



Generated by BlueJ