⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plane.java

📁 高质量Java程序设计 源代码
💻 JAVA
字号:
package net.betterjava.design.aggregation;

import java.util.Iterator;
import java.util.Vector;

class Plane {

	private Fuselage aFuselage;
	private Tail aTail;
	private Wing leftWing;
	private Wing rightWing;

	public Plane(
		int fuselageWeight,
		int tailWeight,
		int leftWIngWeight,
		int rightWingWeight) {
		this.aFuselage = new Fuselage(fuselageWeight);
		this.aTail = new Tail(tailWeight);
		this.leftWing = new Wing(leftWIngWeight);
		this.rightWing = new Wing(rightWingWeight);
	}

	public int getWeight() {
		return aFuselage.getWeight()
			+ aTail.getWeight()
			+ leftWing.getWeight()
			+ rightWing.getWeight();
	}

}

class Fuselage {

	private int weight;

	public Fuselage(int myWeight) {
		this.weight = myWeight;
	}

	public int getWeight() {
		return this.weight;
	}

}

class Tail {

	private int weight;

	public Tail(int myWeight) {
		this.weight = myWeight;
	}

	public int getWeight() {
		return this.weight;
	}

}

class Wing {

	private int weight;

	public Wing(int myWeight) {
		this.weight = myWeight;
	}

	public int getWeight() {
		return this.weight;
	}

}

class Airport {
	private Vector planes;

	public Airport() {
		planes = new Vector();
	}

	public void addPlane(Plane p) {
		planes.add(p);
	}

	public int getWeight() {
		Iterator it = planes.iterator();
		int totalWeight = 0;
		while (it.hasNext()) {
			totalWeight = ((Plane) it.next()).getWeight();
		}
		return totalWeight;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -