/**4-1 according to the fifth chapter of the textbook exercise 5-12 of the requirements of programming to achieve the assigned plural class complexnumber*/
public class adu {public static void main (String[] args) {}}class complexnumber{private int m_drealpart;//Real Department private int m_dimaginpart;// Imaginary part 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 ()//Gets the real part of the current object {Return m_drealpart;} Int getimaginarypart ()//Gets the imaginary part of the current object {Return m_dimaginpart;} void setrealprat (DOUBLE D)//sets the real part of the current object to the number {m_drealpart = (int) d of the given formal parameter;} void setimaginarypart (DOUBLE D)//sets the imaginary part of the current object to the number {m_dimaginpart = (int) d of the given formal parameter;} complexnumber complexadd (complexnumber c) //the current complex object and the formal parameter complex object, the result is a complex value, returned to the caller of this method {This.m_ Dimaginpart += c.m_dimaginpart;this.m_drealpart += c.m_drealpart;return this;} complexnumber complexadd (DoUBLE C)//The current complex object is added to the formal parameter real object, and the resulting result is still a complex value, returned to the caller of this method {this.m_drealpart += c;return this;} complexnumber complexminus (COMPLEXNUMBER C)//The current complex object is subtracted from the formal parameter complex object, the resulting result is still a complex value, returned to the caller of this method {This.m_ Dimaginpart -= c.m_dimaginpart;this.m_drealpart -= c.m_drealpart;return this;} complexnumber complexmiuns (DOUBLE C)//The current complex object is subtracted from the formal parameter real object, and the resulting result is still a complex value returned to the caller of this method {This.m_drealpart -= c;return this;} complexnumber complexmulti (COMPLEXNUMBER C)//The current complex object is multiplied by the formal parameter complex object, and the resulting result is still a complex value returned to the caller of this method {This.m_ Dimaginpart *= c.m_dimaginpart;this.m_drealpart *= c.m_drealpart;return this;} complexnumber complexmulti (DOUBLE C)//The current complex object is multiplied by the formal parameter real object, and the resulting result is still a complex value returned to the caller of this method {This.m_drealpart *= c;return this;} complexnumber complexdiv (COMPLEXNUMBER C)//The current complex object is divided by the plural object of the parameter, the result is still a complex value, returned to the caller of this method {This.m_ dimaginpart /= c.m_dimaginpart;this.m_drealpart /= c.m_drealpart;return&Nbsp;this;} complexnumber complexdiv (DOUBLE C)//The current complex object is divided with the formal parameter real object, the result is still a complex value, returned to the caller of this method {This.m_drealpart /= c;return this;}}
This article is from the "hacker" blog, make sure to keep this source http://anglecode.blog.51cto.com/5628271/1619848
Those years, learn together Java 4-1