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

📄 list.java

📁 商品库存管理系统JAVA程序,不需要数据库.很小源程序可使用Jdk1.3以上的任何版本编译和运行
💻 JAVA
字号:
package chapter1;

public class List {
	//定义数组可以包含对象的最大个数
	private int maxItems = 100;

	//此数组包含对象的实际个数
	private int numItems = 0;

	//定义此类中用来存储对象的数组
	protected Object[] list = null;

	//类的构造函数
	public List() {
		//初始化数组
		list = new Object[maxItems];
	}

	//类的构造函数,在此构造函数中,可以修改数组可以包含对象的最大个数
	public List(int _maxItems) {
		maxItems = _maxItems;
		list = new Object[maxItems];
	}

	public void add(Object obj) {
		// 假定还有空间增加一个对象,即假定numItems < maxItems.
		list[numItems] = obj;
		numItems++;
	}

	public void delete(int pos) {
		// 假设pos在0与numItems之间
		for (int i = pos + 1; i < numItems; i++) {
			list[i - 1] = list[i];
		}
		numItems--;
	}

	//检索数组中pos 位置的对象
	public Object get(int pos) {
		return list[pos];
	}

	//返回数组中包含对象的个数
	public int getSize() {
		return numItems;
	}

	//判断数组是否满
	public boolean isFull() {
		return (numItems >= maxItems);
	}

	//以String的形式返回List类
	public String toString() {
		String s = new String();
		for (int i = 0; i < numItems; i++)
			s += "\n" + list[i].toString();
		return s + "\n";
	}
}

⌨️ 快捷键说明

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