Java第二次实训

/*3、按要求编写一个Java应用程序:
(1)定义一个类,描述一个矩形,包含有长、宽两种属性,和计算面积方法。
(2)编写一个类,继承自矩形类,同时该类描述长方体,具有长、宽、高属性,
和计算体积的方法。
(3)编写一个测试类,对以上两个类进行测试,创建一个长方体,定义其长、
宽、高,输出其底面积和体积。
*/
package bbb;
import java.util.*;
 class  rectangle{
	 int length,width;
	 public void count(int length,int width){
		 int s;
		 s=length*width;
		 System.out.println("面积为:"+s);
	 }
}
class cuboid extends rectangle{
	int high;
	public void bulk(int length,int width,int high){
		int v;
		v=high*width*length;
		System.out.println("体积为:"+v);
	}
	public static int nextInt() {
		// TODO 自动生成的方法存根
		return 0;
	}

}
public class Circle {
	public static void main(String[]args){
      Scanner a=new Scanner(System.in);
		Scanner b=new Scanner(System.in);
		Scanner c=new Scanner(System.in);
		System.out.println("请输入长:");
		int length=a.nextInt();
		System.out.println("请输入宽:");
		int high=b.nextInt();
		System.out.println("请输入高:");
		int width=c.nextInt();
		rectangle s1=new  rectangle();
		cuboid s2=new cuboid();
		s1.count(length,width);
		s2.bulk(length,width,high);
	}
}

  

转载于:https://www.cnblogs.com/lusilin/p/11050564.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值