java 第七周课后作业0417
2024-09-05 01:08:20
定义一个矩形类Rectangle:(知识点:对象的创建和使用)
1 定义三个方法:getArea()求面积、getPer()求周长,showAll()分别在控制台输出长、宽、面积、周长。
2 有2个属性:长length、宽width
3 创建一个Rectangle对象,并输出相关信息
package homework; import java.util.Scanner; public class Rectangle {
public static void main(String[] args) { } Scanner sc = new Scanner(System.in);
double length = sc.nextDouble();
double width = sc.nextDouble();
double area = length * width;
double per = 2 * (length + width); public void getArea() {
System.out.println("长方形的面积为:" + area);
} public void getPer() {
System.out.println("长方形的周长为:" + per);
} public void showAll() {
System.out.println("长方形的面积为" + area + ", " + "长方形的周长为:" + per+" ;");
System.out.println("长方形的长为:" + length + ", " + "长方形的宽为:" + width);
}
}
package homework; import java.util.Scanner; public class TestRectangle { public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入长方形的长和宽:");
Rectangle r = new Rectangle();
r.getArea();
r.getPer();
r.showAll(); }
}
最新文章
- iOS HTTP访问网络受限
- IIS注册.netframework4.0指令
- Spark源码学习1.4——MapOutputTracker.scala
- 向txt文件中写入换行
- 写一个ActionFilter检测WebApi接口请求和响应
- ACM题目————The Blocks Problem
- C# odbc
- 字符串匹配算法——KMP、BM、Sunday
- ceph 参数说明<;转>;
- java 子类继承父类成员变量的隐藏、实现方法的重写
- linux下的Shell编程(7)使用-x和-n调试shell程序
- 隔壁老主精讲web页面性能优化。
- 设计模式---接口隔离模式之代理模式(Proxy)
- BZOJ3022 : [Balkan2012]The Best Teams
- 1.汇编指令介绍(arm)
- GNU coreutils
- PHP中单引号与双引号的区别分析
- 基础笔记1(进制,浮点,递归,floor,round和ceil)
- linux定时任务:crontab命令
- nyoj 737 石子合并 http://blog.csdn.net/wangdan11111/article/details/45032519
热门文章
- no parameterless constructor define for type 解决一例
- java-Deque
- 用svg+css 或者js制作打钩的动画
- Building Applications with Force.com and VisualForce (DEV401)(五):Application Essential: Introducing Business Logic
- PyTorch 实战-用 Numpy 热身
- TensorFlow系列专题(八):七步带你实现RNN循环神经网络小示例
- iOS hash
- 简述MySQL数据库中的Date,DateTime,TimeStamp和Time类型
- Windows 7 NVMe补丁(包括官网下载链接)
- JMeter中聚合报告的各项参数详解