File: example-texjava.java

package info (click to toggle)
tcode 0.1.20080918-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 504 kB
  • sloc: perl: 831; xml: 84; sh: 52; java: 47; csh: 16; makefile: 13
file content (52 lines) | stat: -rw-r--r-- 1,412 bytes parent folder | download
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
\defclass{Complex}
This class allows one to work with complex numbers of
the form $a + bi$, where $a$ is the \emph{real} part of
the number, \emph{b} is the imaginary part and
$i=\sqrt{-1}$.
\bigskip\hrule\bigskip
\begin{code}
public class Complex\begin{hide} {
private double realPart;
private double imagPart;\end{hide}
public Complex (double realPart, double imagPart)\begin{hide} {
this.realPart = realPart;
this.imagPart = imagPart;
}\end{hide}
\end{code}
\begin{tabb} Constructs a new {\tt Complex} number.
\param{realPart}{The real part corresponding to $a$}
\param{imagPart}{The imaginary part corresponding to $b$}
\end{tabb}
\begin{code}
public Complex add (Complex c)\begin{hide} {
realPart += c.realPart;
imagPart += c.realPart;
return this;
}\end{hide}

\end{code}
\begin{tabb} Adds two complex numbers.
\param{c}{The complex number to add to this one.}
\return{This object, allowing to perform more than one operation
on a single line of code.}
\end{tabb}
\begin{code}
// other methods...
public String toString()\begin{hide} {
return "(" + realPart + " + " + imagPart + "i)";
}
// Test code
public static void main(String[] args) {
	Complex c1 = new Complex(1, 2);
	Complex c2 = new Complex(2, 3);
	assert c1.add(c2).toString().equals("(3.0 + 4.0i)");
	System.out.println("PASS");
}
}\end{hide}
\end{code}
\begin{tabb}
 Converts the number to a {\tt String} of
the form {\tt a + bi}.
\end{tabb}