あれらの年、いっしょに学ぶJava 4-1
/*4-1教科書第五章練習問題5-12の要求に従ってプログラミングしてテーマ指定の複数種類のComplexNumber*/
public class adu
{
public static void main (String[] args)
{
}
}
class ComplexNumber
{
private int m_dRealPart; //
private int m_dImaginPart; //
ComplexNumber ()
{
this.m_dRealPart = 0;
this.m_dImaginPart = 0;
}
ComplexNumber (double r, double i)
{
this.m_dRealPart = (int)r;
this.m_dImaginPart = (int)i;
}
int getRealPart () //
{
return m_dRealPart;
}
int getImaginaryPart() //
{
return m_dImaginPart;
}
void setRealPrat (double d) //
{
m_dRealPart = (int)d;
}
void setImaginaryPart (double d) //
{
m_dImaginPart = (int)d;
}
ComplexNumber complexAdd (ComplexNumber c) // , ,
{
this.m_dImaginPart += c.m_dImaginPart;
this.m_dRealPart += c.m_dRealPart;
return this;
}
ComplexNumber complexAdd (double c)// , ,
{
this.m_dRealPart += c;
return this;
}
ComplexNumber complexMinus (ComplexNumber c)// , ,
{
this.m_dImaginPart -= c.m_dImaginPart;
this.m_dRealPart -= c.m_dRealPart;
return this;
}
ComplexNumber complexMiuns (double c)// , ,
{
this.m_dRealPart -= c;
return this;
}
ComplexNumber complexMulti (ComplexNumber c)// , ,
{
this.m_dImaginPart *= c.m_dImaginPart;
this.m_dRealPart *= c.m_dRealPart;
return this;
}
ComplexNumber complexMulti (double c)// , ,
{
this.m_dRealPart *= c;
return this;
}
ComplexNumber complexDiv (ComplexNumber c)// , ,
{
this.m_dImaginPart /= c.m_dImaginPart;
this.m_dRealPart /= c.m_dRealPart;
return this;
}
ComplexNumber complexDiv (double c)// , ,
{
this.m_dRealPart /= c;
return this;
}
}