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

📄 ch9ex2.java

📁 JAVA程序设计 丁岳伟 彭敦陆编 高等教育出版社 第7---11章程序
💻 JAVA
字号:
class Counter{
	private int count;
	public Counter(){
		count=0;
	}
	public void incCount(){
		count++;
	}
	public void decCount(){
		if(count>0)
	  		count--;
	}
	public int getCount(){
		return count;
	}
}
class ExhibitionMonitor extends Counter{
	private int capacity;
	public ExhibitionMonitor(int c){
		super(); 
		capacity=c;
	}
	public int getCapacity(){return capacity;}
	public boolean enter(){
		if(getCount()<capacity){
	    	incCount();
	       	return true;
	    }
	    else
			return false;
	}
	public void leave(){
		if(getCount()>0)
			decCount();
	}
}
public class ch9ex2{
	public static void main(String[]args){
		ExhibitionMonitor cap=new ExhibitionMonitor(100);
		System.out.println("Exhibition Capacity :"+cap.getCapacity());
		for(int j=0;j<60;j++)
			cap.enter();
		System.out.println("Attendance :"+cap.getCount());
		for(int j=0;j<20;j++)
			cap.leave();
		System.out.println("Attendance :"+cap.getCount());
		
	}
}

⌨️ 快捷键说明

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