本篇分享一个Java期末大作业系统,Java期末大作业设计 房屋出租系统
主页还有,多瞅瞅,别直接就抄了,你同学也在抄,要是答案都给你了还不会用,我建议你还是学一下qwq
package demo5;
import java.awt.*;
import java.util.ArrayList;
import java.util.Scanner;
/**
* @author 幻影2021
* @version 1.0
* @date 2023/9/22
* @time 1:00
* 房屋出租
*/
public class HouseRentSystem {
public static void main(String[] args) {
boolean flag = true;
Scanner scanner = new Scanner(System.in);
String key = "";
ArrayList<House> houses = new ArrayList<>();
do {
new Menu().menu();
key = scanner.next();
switch (key) {
case "1":
House house = new House();
System.out.println("======添加房源信息=======");
System.out.println("请输入编号:");
house.id = scanner.nextInt();
System.out.println("请输入房主姓名:");
house.name = scanner.next();
System.out.println("请输入电话:");
house.phone = scanner.next();
System.out.println("请输入地址:");
house.address = scanner.next();
System.out.println("请输入月租:");
house.rent = scanner.nextDouble();
System.out.println("请输入出租状态:");
house.state = scanner.next();
houses.add(house);
System.out.println("房源信息添加成功!");
break;
case "2":
System.out.println("请输入要查找房屋的编号");
int searchId = scanner.nextInt(); // 从用户输入中获取房源ID
for (House h : houses) { // 遍历ArrayList
if (h.id == searchId) { // 如果找到了要查找的房源
System.out.println("找到房源信息:");
System.out.println("编号:" + h.id);
System.out.println("房主姓名:" + h.name);
System.out.println("手机号:" + h.phone);
System.out.println("地址:" + h.address);
System.out.println("月租:" + h.rent);
System.out.println("状态:" + h.state);
}else {
System.out.println("未找到房源信息");
}
}
break;
case "3":
System.out.println("请输入要删除的房源编号:");
int deleteId = scanner.nextInt();
for (int i = 0; i < houses.size(); i++) {
if (houses.get(i).id == deleteId){
houses.remove(i);
System.out.println("删除成功");
}
}
break;
case "4":
System.out.println("请输入要修改房源信息的编号");
int modifyId = scanner.nextInt();
for (House house1 : houses) {
if (house1.id == modifyId){
System.out.println("请输入新的编号:");
house1.id = scanner.nextInt();
System.out.println("请输入新的房主姓名:");
house1.name = scanner.next();
System.out.println("请输入新的电话:");
house1.phone = scanner.next();
System.out.println("请输入新的地址:");
house1.address = scanner.next();
System.out.println("请输入新的月租:");
house1.rent = scanner.nextDouble();
System.out.println("请输入新的出租状态:");
house1.state = scanner.next();
System.out.println("房源信息修改成功!");
}else {
System.out.println("没有该房源");
}
}
break;
case "5":
if (houses.size() != 0){
for (House house2 : houses) {
System.out.println("编号:" + house2.id);
System.out.println("房主姓名:" + house2.name);
System.out.println("手机号:" + house2.phone);
System.out.println("地址:" + house2.address);
System.out.println("月租:" + house2.rent);
System.out.println("状态:" + house2.state);
}
}else {
System.out.println("暂时还没有房源信息");
}
break;
case "6":
// 退出系统功能
flag = false;
break;
default:
System.out.println("输入有误,请重新输入!");
break;
}
} while (flag);
}
}
class Menu {
public void menu() {
System.out.println("\n=============房屋出租系统菜单============");
System.out.println("\t\t\t1 新 增 房 源");
System.out.println("\t\t\t2 查 找 房 屋");
System.out.println("\t\t\t3 删 除 房 屋 信 息");
System.out.println("\t\t\t4 修 改 房 屋 信 息");
System.out.println("\t\t\t5 房 屋 列 表");
System.out.println("\t\t\t6 退 出");
System.out.print("请输入你的选择(1-6): ");
}
}
class House {
//添加房屋属性
//1.编号
// 2.房主
// 3.电话
// 4.地址
// 5.月租
// 6.状态(未出租/已出租)
public int id;
public String name;
public String phone;
public String address;
public double rent;
public String state;
}