[Instructions] [Search] [Current] [Changes] [Syllabus] [Handouts] [Outlines] [Labs] [Assignments] [Examples] [Bailey Docs] [SamR Docs] [Tutorial] [API]
Held: Friday, January 23, 1998
Complex ClassComplex class
to represent complex numbers.
public and class class and is followed
by the name of the class and the body of the class, surrounded in
curly braces.
public class Complex
{
} // Complex
double real_part; double imaginary_part;
protected
or the keyword private. (They mean different things;
use protected until you understand the difference.)
protected double real_part; protected double imaginary_part;
/** * A simple implementation of complex numbers supporting a small * set of operations. * * @author Samuel A. Rebelsky * @version 1.0 of January 1998. */
/** * The real part of a complex number which is represented in * traditional "x + y*i" format. */ protected double real_part; /** * The imaginary part of a complex number which is represented * in traditional "x + y*i" format. */ protected double imaginary_part;
// +------------+-------------------------------------------------------- // | Attributes | // +------------+
public)
void if it returns nothing)
/**
* Get the real part of this complex number.
*/
public double getReal()
{
return real_part;
} // getReal()
Integer and Boolean classes that Java
supplies do not allow you to modify the underlying integer.
/**
* Set/change the value of this complex number to x + y*i.
*/
public void setValue(double x, double y)
{
real_part = x;
imaginary_part = y;
} // setValue()
/**
* Get the radius of the vector corresponding to this complex number.
*/
public double getRadius()
{
return Math.sqrt(real_part*real_part + imaginary_part*imaginary_part);
} // getRadius()
On to More on Objects and Classes
Back to More Java Basics
Outlines:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Current position in syllabus
[Instructions] [Search] [Current] [Changes] [Syllabus] [Handouts] [Outlines] [Labs] [Assignments] [Examples] [Bailey Docs] [SamR Docs] [Tutorial] [API]
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS152/98S/home/rebelsky/public_html/Courses/CS152/98S/Outlines/outline.04.html
Source text last modified Tue Jan 12 11:52:16 1999.
This page generated on Mon Jan 25 09:48:43 1999 by SiteWeaver. Validate this page.
Contact our webmaster at rebelsky@math.grin.edu