java编写一个程序_计算已知长和宽的长方形的周长,请教一下大佬们,我们java留了一个作业,编写程序,定义一个接口Comput,声明计算周长和面积的方法...
//編寫程序,定義一個(gè)接口Compute,聲明計(jì)算周長(zhǎng)calgirth()和面積calarea?()的方法,然后定義一個(gè)長(zhǎng)方形類RRect和圓類Circle,兩個(gè)類都實(shí)現(xiàn)接口Compute,最后進(jìn)行測(cè)試。
package?edu.slm.test;
/**
*?編寫程序,定義一個(gè)接口Compute,聲明計(jì)算周長(zhǎng)calgirth()和面積calarea?()的方法,
*?然后定義一個(gè)長(zhǎng)方形類RRect和圓類Circle,兩個(gè)類都實(shí)現(xiàn)接口Compute,最后進(jìn)行測(cè)試。
*?@author?slm
*/
//******************************
/**
*?定義Computer接口
*?聲明計(jì)算周長(zhǎng)方法calgirth()和求面積方法calarea()
*?@author?Administrator
*/
//******************************
//******************************
/**
*
*?定義RRect類,實(shí)現(xiàn)Computer接口
*
*/
class?RRect?{
private?int?w;
private?int?h;
public?double?s;//?存儲(chǔ)面積
public?RRect(int?_w,?int?_h)?{
w?=?_w;
h?=?_h;
}
//******************************
//添加并實(shí)現(xiàn)接口的方法
//******************************
}
/**
*?定義Circle,實(shí)現(xiàn)Computer接口
*?@author?Administrator
*/
class?Circle?{
private?int?r;
public?double?s;//?存儲(chǔ)面積
public?Circle(int?_r)?{
r?=?_r;
}
//******************************
//添加并實(shí)現(xiàn)接口的方法
//******************************
}
public?class?Exam293?implements?MyInterface?{
@Override
public?Object?method(Object[]?params)?{
int?rs?=?0;
int?w?=?Integer.parseInt(params[0].toString());
int?h?=?Integer.parseInt(params[1].toString());
int?r?=?Integer.parseInt(params[2].toString());
//?測(cè)試功能,請(qǐng)勿修改
RRect?rect?=?new?RRect(w,?h);
Circle?c?=?new?Circle(r);
System.out.println("功能測(cè)試...");
System.out.println("矩形面積:"?+?rect.calarea());
System.out.println("圓面積:"?+?c.calarea());
rs?=?(int)?((int)?rect.calarea()?+?c.calarea());
return?rs;
}
public?static?void?main(String[]?args)?{
Exam293?pro?=?new?Exam293();
pro.method(new?Object[]?{?200,?300,?500?});
}
}
總結(jié)
以上是生活随笔為你收集整理的java编写一个程序_计算已知长和宽的长方形的周长,请教一下大佬们,我们java留了一个作业,编写程序,定义一个接口Comput,声明计算周长和面积的方法...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c#中使用mysql查询语句_遇到@符合
- 下一篇: Qt实现全屏下玫瑰花(含详细注释)