java面向对象董小圆版第二~三章课后习题答案(自己编写的,有问题的宝宝可以私聊)

温馨提示:因为是这几天边复习边写的所以更新有点慢,不过需要答案的小可爱们放心,会很快补上哒^ - ^

第二章

1

package com.xiujie.part_2;

import java.util.Scanner;
/**
 * 
 * @author lxj
 *
 */
public class BoxOfValue {
   
	public static void main(String[] args) {
   
		System.out.println("请输入长方体的长、宽、高:");
		Scanner scanner = new Scanner(System.in);
		int length = scanner.nextInt();
		int width = scanner.nextInt();
		int height = scanner.nextInt();
		Box box = new Box();
		box.setInfo(length, width, height);
		box.toString();
		scanner.close();
	}
}

class Box {
   
	private int length;
	private int width;
	private int height;

	public void setInfo(int x, int y, int z) {
   
		length = x;
		width = y;
		height = z;
	}
	public int volumn() {
   
		return length * width * height;

	}

	public int area() {
   
		return 2*(length * width + length * height + width * height);
	}

	public String toString() {
   
		System.out.println("长方体的长、宽、高分别是:" + length + "," + width + "," + height + ",表面积是:"
				+ area() + "体积是:" + volumn());
	  return "计算完毕";
	}
}

2、

package com.xiujie.part_2;

public class CircleTest {
   
	public static void main(String[] args) {
   
		Circle circle1 = new Circle();
		Circle circle2 = new Circle();
		circle1.setR(3);
		circle2.setR(4);
		circle1.showInfo();
		circle2.showInfo();
	}
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值