Those years, learn together Java 4-1

Source: Internet
Author: User

/**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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.