当前位置: 首页 > news >正文

网站建设公司问答营销案例开源企业网站源码

网站建设公司问答营销案例,开源企业网站源码,网站建设怎么分类,福田网站建设方案服务本文章就讲的是很基础的类的使用 重点大概就是类的构造函数以及一些很基础的东西。 实验内容是些老生常谈的东西,Complex类,在当初学C面向对象的时候也是这个样子展开的。 内容如以下: public class Complex {float real;float imag;public…

本文章就讲的是很基础的类的使用
重点大概就是类的构造函数以及一些很基础的东西。

实验内容是些老生常谈的东西,Complex类,在当初学C++面向对象的时候也是这个样子展开的。
内容如以下:

public class Complex {float real;float imag;public Complex(){real = 0;imag = 0;}public Complex(float real, float imag){this.real = real;this.imag = imag;}public Complex add(float real){this.real += real;return this;}public Complex add(Complex complex){this.real += complex.real;this.imag += complex.imag;return this;}public Complex sub(float real){this.real -= real;return this;}public Complex sub(Complex complex){this.real -= complex.real;this.imag -= complex.imag;return this;}public Complex mul(float real){this.real *= real;this.imag *= real;return this;}public Complex mul(Complex complex){float TheReal = this.real;float TheImag = this.imag;this.real = TheReal * complex.real - TheImag*complex.imag;this.imag = TheReal * complex.imag + TheImag*complex.real;return this;}public String toString(){String str="";if(this.imag == 0){str += this.real;}else if(this.imag > 0 ){if(this.real==0){str += this.imag + "i";}else str += this.real + "+" + this.imag + "i";}else{if(this.real==0){str += this.imag + "i";}else str += this.real + "" + this.imag + "i";}return str;}}

这里也不得不说一丁点相关知识–重载 overload
如这里的:

	public Complex(){real = 0;imag = 0;}public Complex(float real, float imag){this.real = real;this.imag = imag;}public Complex add(float real){this.real += real;return this;}public Complex add(Complex complex){this.real += complex.real;this.imag += complex.imag;return this;}

这里的Complex()Complex(float real, float imag)构造函数也就用了一些重载的知识。
所谓重载,就是函数名不变但是函数内部的参数变化,我们调用函数时通过函数里面的参数决定我们要调用哪个函数。
同理的,Complex add(float real),Complex add(Complex complex)也是如此,当add()的括号里面是一个float值的时候调用Complex add(float real),括号里面是一个Complex对象的时候调用Complex add(Complex complex)
我当时认为这不是理所当然的吗?其实不是的,这里是用到了重载(overload)的知识。
总代码:
在这里插入图片描述

包com.Class.Work3里的Complex类:

package com.Class.Work3;public class Complex {float real;float imag;public Complex(){real = 0;imag = 0;}public Complex(float real, float imag){this.real = real;this.imag = imag;}public Complex add(float real){this.real += real;return this;}public Complex add(Complex complex){this.real += complex.real;this.imag += complex.imag;return this;}public Complex sub(float real){this.real -= real;return this;}public Complex sub(Complex complex){this.real -= complex.real;this.imag -= complex.imag;return this;}public Complex mul(float real){this.real *= real;this.imag *= real;return this;}public Complex mul(Complex complex){float TheReal = this.real;float TheImag = this.imag;this.real = TheReal * complex.real - TheImag*complex.imag;this.imag = TheReal * complex.imag + TheImag*complex.real;return this;}public String toString(){String str="";if(this.imag == 0){str += this.real;}else if(this.imag > 0 ){if(this.real==0){str += this.imag + "i";}else str += this.real + "+" + this.imag + "i";}else{if(this.real==0){str += this.imag + "i";}else str += this.real + "" + this.imag + "i";}return str;}}

调用Complex类的TestWork3类:

import com.Class.Work3.Complex;public class TestWork3 {public static void main(String[] args) {Complex c = new Complex(1, 2);
//        c.add(5);
//        Complex w = new Complex(4,1);
//        c.sub(w);
//        Complex w2 = new Complex(1,2);
//        c.mul(w2);
//        c.mul(5);System.out.println(c);}
}

就这样了~

http://www.yayakq.cn/news/953727/

相关文章:

  • 十大电子游戏平台网站做救助流浪动物网站的产生背景
  • 购物网站开发文档页面设计的宗旨是什么
  • 北京建设信息港网站为什么建设网银网站打不开
  • 家居企业网站建设咨询国外最火的网站
  • xxx网站策划书个人政务公开网站建设工作总结
  • eclipse jsp 网站开发杭州品牌设计公司排名前十
  • 做外贸建网站需要多少钱顺德做网站公司哪家好
  • 做网站有什么语言好海洋做网站
  • 制作html网站模板安徽住房建设厅官网信息查询
  • 大航母网站建设服务WordPress付费下载源码
  • 北京网站建设的公司做网站工作好么
  • 太原网站优化可信网站验证价格
  • 网站服务器返回状态码404带后台的网站模板下载
  • 气动科技东莞网站建设ps网页版在线制作
  • 做服装广告素材网站网站推广服务算中介吗
  • 套模版做网站济南建网站送400电话
  • 确定网站界面杭州建设信用平台
  • ps做网站的效果图各位大哥给个网站
  • 做网站联系方式怎么做网站的界面
  • 珠宝网站模板免费下载商城网站模板 免费
  • 一诺互联 网站建设wordpress主页图片不显示
  • 滨海县建设局网站响应式网站用什么做
  • 中山哪里有做网站如何制作app软件下载
  • 大米网站模板在那些网站做宣传更好
  • 安徽网站公司网站云和数据培训机构怎么样
  • 开网络公司做网站挣钱么杭州网络科技设计中心
  • cn域名有名的网站东营市建设信息网站
  • 创意网站设计模板厦门网站建设手机
  • 下载网站 源码清河企业做网站
  • 石家庄网站定制制作建设执业注册中心网站