一
House1
public class House1 {
private String houseId; //房源编号
private String villageName; //小区名称
private String companyName; //公司名称
private String houseType; //房源类型
private String houseSet; //幢/座 编号
private int houseState; //状态 0:未出租 1:已出租
private String houseFavor; //房屋朝向 //南北通透
private String houseMethod; //房屋用途
private double housePrice; //房屋价格
private double rentPrice; //出租价格
private String houseFloor; //楼层
private String houseBuilYear; //建筑年限
private String houseFacility; //房屋设施
private String houseRemark; //评价
public House1() {
super();
}
public String getHouseId() {
return houseId;
}
public void setHouseId(String houseId) {
this.houseId = houseId;
}
public String getVillageName() {
return villageName;
}
public void setVillageName(String villageName) {
this.villageName = villageName;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public String getHouseType() {
return houseType;
}
public void setHouseType(String houseType) {
this.houseType = houseType;
}
public String getHouseSet() {
return houseSet;
}
public void setHouseSet(String houseSet) {
this.houseSet = houseSet;
}
public int getHouseState() {
return houseState;
}
public void setHouseState(int houseState) {
this.houseState = houseState;
}
public String getHouseFavor() {
return houseFavor;
}
public void setHouseFavor(String houseFavor) {
this.houseFavor = houseFavor;
}
public String getHouseMethod() {
return houseMethod;
}
public void setHouseMethod(String houseMethod) {
this.houseMethod = houseMethod;
}
public double getHousePrice() {
return housePrice;
}
public void setHousePrice(double housePrice) {
this.housePrice = housePrice;
}
public double getRentPrice() {
return rentPrice;
}
public void setRentPrice(double rentPrice) {
this.rentPrice = rentPrice;
}
public String getHouseFloor() {
return houseFloor;
}
public void setHouseFloor(String houseFloor) {
this.houseFloor = houseFloor;
}
public String getHouseBuilYear() {
return houseBuilYear;
}
public void setHouseBuilYear(String houseBuilYear) {
this.houseBuilYear = houseBuilYear;
}
public String getHouseFacility() {
return houseFacility;
}
public void setHouseFacility(String houseFacility) {
this.houseFacility = houseFacility;
}
public String getHouseRemark() {
return houseRemark;
}
public void setHouseRemark(String houseRemark) {
this.houseRemark = houseRemark;
}
}
接下来
二
HouseDAO1
import java.util.List;
import unit_5.House1;
/**
* 房屋信息接口
* @author Administrator
*
*/
public interface HouseDAO1 {
//判断房源存在与否
public boolean isExist(House1 house1);
//添加房源信息
public boolean insertHouse(House1 house1);
//显示所有房源信息
public void showall();
}
然后
三
HouseDaoImpUseOfCollection1
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
public class HouseDaoImpUseOfCollection1 implements HouseDAO1{
Collection collection;
public HouseDaoImpUseOfCollection1() {
collection =new ArrayList();
}
public Collection getCollection() {
return collection;
}
public void setCollection(Collection collection) {
this.collection = collection;
}
@Override
public boolean isExist(House1 house1) {
// TODO Auto-generated method stub
boolean flag=false;
if (collection.contains(house1)) {
flag=true;
}
return flag;
}
@Override
public boolean insertHouse(House1 house1) {
// TODO Auto-generated method stub
boolean flag=false;
if (this.isExist(house1)) {
System.out.println("该房源已经存在,不能添加");
}else {
collection.add(house1);
flag=true;
}
return flag;
}
@Override
public void showall() {
// TODO Auto-generated method stub
Iterator it=collection.iterator();
while (it.hasNext()) {
House1 house1=(House1)it.next();
System.out.println(house1.getVillageName()+" |"
+ house1.getHouseType()+" |"
+house1.getHouseSet()+" |"
+house1.getHouseFloor()+" |"
+house1.getHouseState()+" |"
+house1.getHouseFavor()+" |"
+house1.getHousePrice()+" |"
+house1.getHouseFacility());
}
}
}
在然后
四
HouseManager1
import java.util.Scanner;
public class HouseManager1 {
//HouseManager1 houseManager1 =new HouseManager1();
//private HouseDaoImpUseOfCollection1 hdic=new HouseDaoImpUseOfCollection1();
//显示房源信息管理功能
public void showFuction() {
System.out.println("**********************************************");
System.out.println("* 欢迎使用房源信息管理系统 *");
System.out.println("* *");
System.out.println("* 请选择要操作的功能 *");
System.out.println("* 房源信息管理: *");
System.out.println("* 1:查看所有房源 2:增加房源信息 *");
System.out.println("* 3:修改房源信息 3:删除房源信息 *");
System.out.println("* *");
System.out.println("* 房源信息查询: *");
System.out.println("* 1:房租价格 2:房源状态 *");
System.out.println("* 3:小区名称 4:房屋楼层 *");
System.out.println("**********************************************");
}
public void ShowAction() {
Scanner sc=new Scanner(System.in);
quit:
while(true) {
int action=sc.nextInt();
switch (action) {
// case 1:
// houseManager1.showAllHouseInfo();
// break;
// case 2:
// houseManager1.addHouse1();
// break;
case 1:
System.out.println("查询所有房源信息");
break;
case 2:
System.out.println("增加房源信息");
break;
case 3:
System.out.println("修改房源信息");
break;
case 4:
System.out.println("删除房源信息");
break;
case 5:
System.out.println("根据房租价格查询房源信息");
break;
case 6:
System.out.println("根据房源状态查询房源信息");
break;
case 7:
System.out.println("根据房源名称查询房源信息");
break;
case 8:
System.out.println("根据房源楼层查询房源信息");
break;
default:
break;
}
System.out.println("请选择下一步动作:a:继续 b:退出");
String nextAction=sc.next();
if (nextAction.equals("a")) {
System.out.println("请继续选择操作类型:");
continue;
}else {
break quit;
}
}
System.out.println("你已经成功退出了!");
}
//输入房源信息
public void addHouse1() {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
System.out.println("请输入房源信息:");
String houseId=sc.next();
System.out.println("请输入小区名称:");
String villageName=sc.next();
System.out.println("物业公司名称");
String companyName=sc.next();
System.out.println("请输入房屋类型:");
String houseType=sc.next();
System.out.println("请输入房屋位置");
String houseSet=sc.next();
System.out.println("请输入房屋状态");
int houseState=sc.nextInt();
System.out.println("请输入房屋朝向");
String houseFavor=sc.next();
System.out.println("请输入房屋用途:");
String houseMethod=sc.next();
System.out.println("请输入房屋价格:");
double housePrice=sc.nextDouble();
System.out.println("请输入出租价格:");
double rentPrice=sc.nextDouble();
System.out.println("请输入楼层:");
String houseFloor=sc.next();
System.out.println("请输入建筑年限:");
String houseBuilYear=sc.next();
System.out.println("请输入房源设施:");
String houseFacility=sc.next();
System.out.println("请输入评价:");
String houseRemark=sc.next();
//创建房源信息对象
House1 house1=new House1();
house1.setHouseId(houseId);
house1.setVillageName(villageName);
house1.setCompanyName(companyName);
house1.setHouseBuilYear(houseBuilYear);
house1.setHouseFavor(houseFavor);
house1.setHouseFloor(houseFloor);
house1.setHouseMethod(houseMethod);
house1.setHousePrice(housePrice);
house1.setRentPrice(rentPrice);
house1.setHouseRemark(houseRemark);
house1.setHouseSet(houseSet);
house1.setHouseState(houseState);
house1.setHouseType(houseType);
house1.setHouseFacility(houseFacility);
HouseDaoImpUseOfCollection1 houseDAO1 = new HouseDaoImpUseOfCollection1();
//判断房源信息是否存在
boolean isExist=houseDAO1.isExist(house1);
if (isExist) {
System.out.println("请重新输入,该房源信息已经存在啦!");
}else {
//保存成功
boolean iresult=houseDAO1.insertHouse(house1);
if (iresult) {
System.out.println("恭喜你,增加房源信息成功!");
}else {
System.out.println("添加房源信息失败!");
}
}
}
//查看所有房源
// public void showAllHouseInfo() {
// // TODO Auto-generated method stub
// hdic.showall();
// }
public static void main(String[] args) {
HouseManager1 houseManager1=new HouseManager1();
houseManager1.showFuction();
houseManager1.ShowAction();
houseManager1.addHouse1();
}
}
在然后
五
TestWorker1
import java.util.ArrayList;
import java.util.Collection;
public class TestWorker1 {
public static void (String[] args) {
// TODO Auto-generated method stub
//创建工人类对象
Worker1 worker1=new Worker1();
worker1.setWorkerName("张三");
worker1.setWorkerOld(18);
worker1.setWage(3000);
Worker1 worker2=new Worker1();
worker2.setWorkerName("李四");
worker2.setWorkerOld(25);
worker2.setWage(3500);
Worker1 worker3=new Worker1();
worker3.setWorkerName("王五");
worker3.setWorkerOld(22);
worker3.setWage(3200);
//创建集合对象
Collection collection=new ArrayList<>();//列表类型
//添加对象 将worker1和worker2放到collection里面去
collection.add(worker1);
collection.add(worker2);
collection.add(worker3);
System.out.println("after add object");
System.out.println("collectiion.size()="+collection.size());
//删除对象
collection.remove(worker1);
System.out.println("after remove worker1");
System.out.println("collectiion.size()="+collection.size());
//判断集合是否为空
boolean isEmpty=collection.isEmpty();
System.out.println("集合是否为空:"+isEmpty);
//判断集合是否包含某个对象
boolean isContains=collection.contains(worker2);
System.out.println("判断集合是否包含worker2"+isContains);
//清除集合内对象
collection.clear();
System.out.println("sfter clear:");
System.out.println("collectiion.size()="+collection.size());
}
}
最后
六
Worker1
public class Worker1 {
private String workerName; //姓名
private int workerOld; //年龄
private int wage; //工资
public Worker1() {
super();
}
public String getWorkerName() {
return workerName;
}
public void setWorkerName(String workerName) {
this.workerName = workerName;
}
public int getWorkerOld() {
return workerOld;
}
public void setWorkerOld(int workerOld) {
this.workerOld = workerOld;
}
public int getWage() {
return wage;
}
public void setWage(int wage) {
this.wage = wage;
}
}