java集合小练习(bug没有改)

没有改bug,大家可以自己试着改哦

package per.llldf.house;

import java.util.*;

public class Main {
	public void menu() {
		System.out.println("*******************************");
		System.out.println("           房源中心");
		System.out.println("         1--添加房源");
		System.out.println("       2--查看具体房源信息");
		System.out.println("       3--区间查看房源信息");
		System.out.println("       0--退出房源中心");
		System.out.println("*******************************");
	}
	public static void main(String[] args) {
		Main lxlx = new Main();
		int i = 0, n = 0;
		Scanner lx = new Scanner(System.in);
		List houseList = new ArrayList();
		while (true) {
			lxlx.menu();
			System.out.println("请输入对应数字进行操作:");
			n = lx.nextInt();
			if (n == 0) {
				System.out.println("结束程序");
				break;
			}
			switch(n) {
			case 1:i = lxlx.addHouse(i, houseList);break;
			case 2:lxlx.houseInfo(houseList); break;
			case 3:lxlx.houseInfoSec(houseList); break;
			default:System.out.println("输入数据不匹配,请重新输入");
			}
			
		}
	}
	public int addHouse(int i, List list) {
		Scanner lx = new Scanner(System.in);
		int m = 0;
		String s1, s2, s3;
		System.out.println("添加房源");
		System.out.println("输入房源编号:");
		System.out.println("编号从0开始,并为连续数值,如:0, 1, 2, 3");
		m = lx.nextInt();
		if (m != i) {
			System.out.println("请输入连续的编号!");
			return i;
		}
		System.out.println("输入房源名称:");
		s1 = lx.next();
		System.out.println("输入房源地址:");
		s2 = lx.next();
		System.out.println("输入房源户型:");
		s3 = lx.next();
		House house = new House(m, s1, s2, s3);
		list.add(house);
		return i + 1;
	}
	public void houseInfo(List list) {
		Scanner lx = new Scanner(System.in);
		int m = 0;
		System.out.println("全部房源信息");
		System.out.println("房源编号            房源名称");
		for (int i = 0; i < list.size(); i++)
		System.out.println(((House)list.get(i)).getHouseId() + "               " + ((House)(list.get(i))).getHouseName());
		System.out.println("请输入要查看的具体房源编号:");
		m = lx.nextInt();
		System.out.println(((House)(list.get(m))).toString());
	}
	public void houseInfoSec(List list) {
		Scanner lx = new Scanner(System.in);
		int m = 0, n = 0;
		System.out.println("全部房源信息");
		System.out.println("房源编号            房源名称");
		for (int i = 0; i < list.size(); i++)
		System.out.println(((House)list.get(i)).getHouseId() + "               " + ((House)(list.get(i))).getHouseName());
		System.out.println("请输入要查看房源信息的第一个编号:");
		m = lx.nextInt();
		System.out.println("请输入要查看房源信息的第二个编号:");
		n = lx.nextInt();
		for (; m < n; m++)
			System.out.println(((House)(list.get(m))).toString());
	}
}
package per.llldf.house;

public class House {
	private int houseId;
	private String houseName;
	private String houseAddress;
	private String houseType;

	public House() {

	}

	public House(int houseId, String houseName, String houseAddress, String houseType) {
		this.setHouseId(houseId);
		this.setHouseName(houseName);
		this.setHouseAddress(houseAddress);
		this.setHouseType(houseType);
	}

	public int getHouseId() {
		return houseId;
	}

	public void setHouseId(int houseId) {
		this.houseId = houseId;
	}

	public String getHouseName() {
		return houseName;
	}

	public void setHouseName(String houseName) {
		this.houseName = houseName;
	}

	public String getHouseAddress() {
		return houseAddress;
	}

	public void setHouseAddress(String houseAddress) {
		this.houseAddress = houseAddress;
	}

	public String getHouseType() {
		return houseType;
	}

	public void setHouseType(String houseType) {
		this.houseType = houseType;
	}

	@Override
	public String toString() {
		String str = "房源编号:" + this.getHouseId() + "\n房源名称:" + this.getHouseName() + "\n房源地址:" + this.getHouseAddress() + "\n房屋类型:" + this.getHouseType();
		return str;
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

顺安晓迪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值