3。编写一个名为“Temperature”的类来存储 温度数据。它应该以摄氏度存储温度,并且有两 个方法——get摄氏()和getFahrenheit(),它们分 别返回摄氏和华氏的温度
*4.编写一个新的程序来打印一个摄氏-华氏转换 表,使用你的“温度”类。
这两个程序不会写,求解答
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- CSDN专家-深度学习进阶 2021-10-02 13:49关注
这么写
class Temperature{ float t1; float t2; public float gets(){//用get方法得到学号(下同) return t1; } public void sets( float t1){//用set方法去设置学号(下同) this.t1=t1; } public float getf(){ return t2; } public void setf(float t2){ this.t2=t2; } public static void main(String agrs[]){ Temperature t=new Temperature(); int temp; for(int i=0;i<=300;i+=20){ temp=(int)(((5.0/9.0)*(((double)i)-32.0))*10); t.sets(i); t.setf(temp); System.out.println(t.gets()+"\t"+((double)t.getf())/10.0 ); } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥20 神经网络Sequential name=sequential, built=False
- ¥16 Qphython 用xlrd读取excel报错
- ¥15 单片机学习顺序问题!!
- ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
- ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
- ¥15 相敏解调 matlab
- ¥15 求lingo代码和思路
- ¥15 公交车和无人机协同运输
- ¥15 stm32代码移植没反应
- ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效