[Java Rehabilitation Guide 09] Full Solution to Project Exercises--Housing Rental System

A comprehensive exercise based on a text interface, mainly used for concatenating and recalling knowledge points, which is relatively simple

Design styles of each interface

main menu

=============Home Rental System Menu============
			1 Add new listings
			2 Find a house
			3 delete house information
			4 Modify housing information
			5 house list
			6 retreat       out
 Please enter your choice(1-6):

Add a new listing

=============Add a house============
Name: jk
 Telephone: 174
 address: Fengtai District
 monthly rent: 5600
 state: 
not rented

Find a property

=============Query housing information============
Please enter the property you want to inquire ID:  
1
1	jk1	13544856575	Xiqing District	1800	not rented

delete listing

=============delete house information============
Please enter the house number to be deleted or enter-1 quit: 1
 Please enter your choice(Y/N): Please choose carefully
y
=============Delete house information successfully============

Edit a listing

=============Modify housing information============
Please select the house number to be modified(-1 quit): 
2
 Name(jk):jack
 Telephone(174):124
 address(Fengtai District): Haidian District
 rent(5600):5300
 state(not rented):rented
=============Modified housing information successfully============

house listing

=============house listing============
Numbering		homeowner		Telephone		address		monthly rent		state(not rented/rented)
2	jack	124	Haidian District	5300	rented
3	gg	485	Changping District	1800	rented
=============The list of houses is displayed============

Exit system

=============Home Rental System Menu============
			1 Add new listings
			2 Find a house
			3 delete house information
			4 Modify housing information
			5 house list
			6 retreat       out
 Please enter your choice(1-6):6
 Please enter your choice(Y/N): Please choose carefully
y
========signed out========

Project Design

Compared with the previous exercises, the volume of this program has reached the level of small projects. Therefore, it is necessary to plan in a reasonable manner

Use the layered model to design and plan the functions of each part of the software

step:

1. Identify the types of the system

2. Determine the relationship between classes

The system wants to display through a text interface

Then the display interface needs a class to implement [HouseView.java]

The business logic code required behind each function in the display interface should be placed in a separate class, that is, this class is used for each service of the corresponding main interface class [HouseService.java]

In the system, the operation of various data is carried out indirectly through the house class [House.java], which defines the properties and methods that a house should contain

The three main classes are basically completed, and now a class that calls each object is needed as the entry of the program, namely [HouseRentApp.java]

The relationship of the above classes is shown in the figure

ps: The Utility class is prefabricated in advance as a tool class, and there is no need to tangle. It is mainly responsible for judging whether the input is legal, etc.

The project structure is as follows

Function realization

Implement the main menu

After clarifying the relationship, you must first write the interface, that is, define a method to display the main menu in HouseView [mainMenu]

//show main menu
//The display is still implemented with the do-while loop mentioned earlier, and the loop flag controls whether to end (exit the system) display
    public void mainMenu(){
        do{
            System.out.println("=============Home Rental System Menu============");
            System.out.println("\t\t\t1 Add new listings");
            System.out.println("\t\t\t2 Find a house");
            System.out.println("\t\t\t3 delete house information");
            System.out.println("\t\t\t4 Modify housing information");
            System.out.println("\t\t\t5 house list");
            System.out.println("\t\t\t6 retreat       out");
            System.out.print("Please enter your choice(1-6):");
            key = Utility.readChar();
            switch (key) {//The following is the implementation method of each function in the menu. You can use sout to occupy the place before writing it at the beginning.
                case '1':
                    addHouse();
                    break;
                case '2':
                    findHouse();
                    break;
                case '3':
                    delHouse();
                    break;
                case '4':
                    update();
                    break;
                case '5':
                    listHouses();
                    break;
                case '6':
                    exit();
                    loop = false;
                    break;
            }
        }while (loop);

Note that the methods of the interface class are only responsible for the functions of the interface part, and the operations related to the data need to be defined in the business class

The interface class is only responsible for referencing related business methods

define business class

/*
* //Define House[], save the House object
1.Responding to a HouseView call
2.Complete various operations on housing information
* (CRUD c[create]r[read]u[update]d[delete])*/
public class HouseService {
    
}

Implementing a house listing

Next, realize the display of existing houses, that is, the display of the list of houses [listHouses()]

Why implement this feature in the first place? Because being able to show the house means we need to complete the definition of the house class, which is also required for the latter function

Therefore, as a basic part, you need to do this house list function first

//Write listHouses() to display a list of houses
//The method of the business class is used to instantiate and return the House array of the house object
//Therefore, it is necessary to define House first
    public void listHouses(){
        System.out.println("=============house listing============");
        System.out.println("Numbering\t\t homeowner\t\t Telephone\t\t address\t\t monthly rent\t\t state(not rented/rented)");
        House[] houses = houseService.list();//Returns all house information, stored in the houses array
        for (int i = 0; i < houses.length; i++) {
            if (houses[i] == null) {
                break;
            }
            System.out.println(houses[i]);
        }
        System.out.println("=============The list of houses is displayed============");
    }
Business method list()

list() needs to return an array used by the system to store house information, and the elements of the array are house objects

Information about all houses can be obtained by iterating over this array

/*
* //Define House[], save the House object
1.Responding to a HouseView call
2.Complete various operations on housing information
* (CRUD c[create]r[read]u[update]d[delete])*/
public class HouseService {
    private House[] house;
    //Constructor
    public HouseService(int size){
        house = new House[size];//When creating a HouseService object, you need to specify the size of the House array
        //Test, initialize a default HouseService object
        house[0] = new House(1, "jk", "13544856575","Xiqing District", 1800,"not rented");
    }
    //list method returns house (array)
    public House[] list(){
        return house;
    }
}

The house class already needs to be used here, naturally we need to write the house class

define house class

The house class House.java is as follows

/*
* House An object representing a house information*/
public class House {
    //The following information is required
    //No. Owner Telephone Address Monthly Rent Status (Not Rent/Rented)
    private int id;
    private String name;
    private String phone;
    private String address;
    private int rent;
    private String state;

    public House(int id, String name, String phone, String address, int rent, String state) {
        this.id = id;
        this.name = name;
        this.phone = phone;
        this.address = address;
        this.rent = rent;
        this.state = state;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public int getRent() {
        return rent;
    }
    public void setRent(int rent) {
        this.rent = rent;
    }
    public String getState() {
        return state;
    }
    public void setState(String state) {
        this.state = state;
    }
    //In order to output object information conveniently, the toString method needs to be implemented
    //For example, there is House h1, so the house information can be printed directly by sout(h1).
    @Override
    public String toString() {
        return id +
                "\t" + name +
                "\t" + phone +
                "\t" + address +
                "\t" + rent +
                "\t" + state ;
    }
}

Realize house addition

After implementing the house list, the house class is actually defined

So now you can consider adding house information

Each house added should be given a number, which needs attention, and the subsequent need to query by the number

//Write addHouse() to accept input, create a House object, and call the add method
//addHouse() is only responsible for adding at the interface level, and the method of actually manipulating the House object array to complete the addition belongs to a specific business function
//That is, the add() method should be defined in HouseService.java and called in the addHouse() of HouseView.java, following the previous class diagram design
    public void addHouse(){
        System.out.println("=============Add a house============");
        System.out.print("Name: ");
        String name = Utility.readString(8);
        System.out.print("Telephone: ");
        String phone = Utility.readString(12);
        System.out.print("address: ");
        String address = Utility.readString(16);
        System.out.print("monthly rent: ");
        int rent = Utility.readInt();
        System.out.println("state: ");
        String state = Utility.readString(3);
        //Create a new House object according to the input information
        //id is the system assignment
        House newHouse = new House(0, name, phone, address, rent, state);
        if(houseService.add(newHouse)){
            System.out.println("=============Add house successfully============");
        }else {
            System.out.println("=============Failed to add house============");
        }
    }
Business method add()

The new data operation on the house object array needs to be implemented in this business method

And need to realize the automatic numbering of house information

public class HouseService {
    private House[] house;
    private int houseNums = 1;//Record how many houses there are currently
    private int idCounter = 1;//Record the value to which the current id grows
    //Constructor
    public HouseService(int size){
        house = new House[size];//When creating a HouseService object, you need to specify the size of the House array
        //Test, initialize a HouseService object
        house[0] = new House(1, "jk", "13544856575","Xiqing District", 1800,"not rented");
    }
    //list method returns house (array)
    public House[] list(){
        return house;
    }
    //add method, add a new object, return boolean
    //The input parameter is the House object
    public boolean add(House newHouse){
        //Determine whether it can continue to be added (for the time being, the problem of array expansion will not be considered)
        if(houseNums == house.length){//If the number of housing information is greater than the length of the array, it cannot be added
            System.out.println("The array is full and cannot be added");
            return false;
        }
        //If the array is not full, add the newHouse object to the array, and the number of houses counts +1
//        house[houseNums] = newHouse;
//        houseNums++;//Add a house
        //The above code can be integrated using the "post++" feature
        //The value of houseNums++ is incremented only after one run
        //For example, if the current houseNums is 1 and the array is set to 10, it is definitely possible to add new house information.
        //Therefore, add newHouse where the array index is 1, after which houseNums is incremented to 2
        house[houseNums++] = newHouse;//post++
        //Need to design an id self-growth mechanism, and then update the id of newHouse
//        idCounter ++;
//        newHouse.setId(idCounter);
        newHouse.setId(++idCounter);//Before ++, the same is true
        return true;
    }
}

Realize the deletion of housing information

Add, delete, modify and check, then the deletion of housing information should be realized now

Here you can delete it according to the number of the house information, or according to the specific information of the house, such as: address, name, phone number, etc.

Take the house number as an example

//Write delHouse() to receive the input id number
//Similar to addHouse(), the final deletion logic is implemented in the business class, and only the related methods are called here.
    public void delHouse(){
        System.out.println("=============delete house information============");
        System.out.print("Please enter the house number to be deleted or enter-1 quit: ");
        int delId = Utility.readInt();//get an input
        if(delId == -1){
            System.out.println("=============Abandon deletion of housing information============");
            return;
        }
        //The method itself has loop judgment logic, you must enter Y/N to exit
        char choice = Utility.readConfirmSelection();
        if(choice=='Y'){//If it is really deleted, call the business method
            if(houseService.del(delId)){
                System.out.println("=============Delete house information successfully============");
            }else {
                System.out.println("=============The house number does not exist, delete failed============");
            }
        }else {
            System.out.println("=============Abandon deletion of housing information============");
        }
    }
Business method del()

In this business method, the deletion operation of the elements of the house object array needs to be implemented according to the house number.

 //del method, delete a house information
    public boolean del(int delId){
        //The corresponding subscript of the deleted house should be found first, the house number does not correspond to the subscript
        int index = -1;
        for (int i = 0; i < houseNums; i++) {
            if(delId == house[i].getId()){
                //The house to delete (id) is the element of the array index i
                index = i;//record i
            }
        }
        if(index == -1){//Explain that delId does not exist in the array
            return false;
        }
        //If found, how should I delete it?
        //The element after the element to be deleted (determined by subscript) is moved forward, covering the element to be deleted
        //Then the last bit is set to null, and the above operation is repeated
        for (int i = index; i < houseNums - 1; i++) {
            house[i] = house[i+1];
        }
        //blank the last element
        //"Before --" means to directly take the value after subtracting one from houseNums. For details, please refer to the explanation of "After++" in the business method add().
//        house[houseNums - 1] = null;
//        houseNums--;//one element less
        house[--houseNums] = null;//Leave the last of the current housing information blank
        return true;
    }

Enable home search

For the query in "Add, delete, modify and check", the function findHouse() is given in the interface class first, and the business method is called to realize the house query

//Find houses by id (improved, look up by address)
    public void findHouse(){
        System.out.println("=============Query housing information============");
        System.out.println("Please enter the property you want to inquire ID:  ");
        int findId = Utility.readInt();
        House houses = houseService.findById(findId);//Returns all house information, stored in the houses array
        if(houses ! = null){
            System.out.println(houses);
        }else {
            System.out.println("No search results, please enter the correct house ID");
        }
    }
Business method findById()

The specific method of query is also based on the number, which is relatively simple. Subsequent updates can add the function of querying by other attributes (touched)

//findById() method, finds houses according to id, returns House object or null
    public House findById(int findId){
        //iterate over the house array
        for (int i = 0; i < houseNums; i++) {
            if(findId == house[i].getId()){
                return house[i];
            }
        }
        return null;
    }

Realize housing information update

Updating house information actually includes query actions, which can only be updated after finding out, so there is no need to write new methods in business, just reuse findById().

//Modify housing information based on id
    //Just adjust findById, no need to add new business functions in HouseService
    public void update(){
        System.out.println("=============Modify housing information============");
        System.out.println("Please select the house number to be modified(-1 quit): ");
        int updateId = Utility.readInt();
        if(updateId == -1){
            System.out.println("=============Modification abandoned============");
            return;
        }
        //Find an object based on the entered ID
        //Because this is a reference object, the original array will be changed synchronously
        House house = houseService.findById(updateId);
        if(house==null){
            System.out.println("=============Housing information does not exist. . .=============");
            return;
        }
        //if the house exists
        System.out.print("Name("+house.getName()+"):");
        String name = Utility.readString(10,"");//If the user presses Enter directly, the default is ""
        if (!"".equals(name)) {//If it is not empty, use the get method to modify
            house.setName(name);
        }
        System.out.print("Telephone(" + house.getPhone() + "):");
        String phone = Utility.readString(12, "");
        if (!"".equals(phone)) {
            house.setPhone(phone);
        }
        System.out.print("address(" + house.getAddress() + "): ");
        String address = Utility.readString(18, "");
        if (!"".equals(address)) {
            house.setAddress(address);
        }
        System.out.print("rent(" + house.getRent() + "):");
        int rent = Utility.readInt(-1);
        if (rent != -1) {
            house.setRent(rent);
        }
        System.out.print("state(" + house.getState() + "):");
        String state = Utility.readString(3, "");
        if (!"".equals(state)) {
            house.setState(state);
        }
        System.out.println("=============Modified housing information successfully============");
    }

The implementation method is a bit simple, in fact, it can be optimized, I will talk about it next time

Summarize

Summarize some programming skills used

trick1

When writing a slightly larger program, you need to separate the page from the business

trick2

Arrays of objects can also be initialized

trick3

Techniques for deleting elements in an array: overwriting deletion [from business method del()]

        //The element after the element to be deleted (determined by subscript) is moved forward, covering the element to be deleted
        //Then the last bit is set to null, and the above operation is repeated
        for (int i = index; i < houseNums - 1; i++) {
            house[i] = house[i+1];
        }

trick4

Practical application of "post++" to streamlined code [business method add()]

//        house[houseNums] = newHouse;
//        houseNums++;//Add a house
        //The above code can be integrated using the "post++" feature
        //The value of houseNums++ is incremented only after one run
        //For example, if the current houseNums is 1 and the array is set to 10, it is definitely possible to add new house information.
        //Therefore, add newHouse where the array index is 1, after which houseNums is incremented to 2
        house[houseNums++] = newHouse;//post++

full code

HouseView.java

package com./.../.houserent.view;

import com./.../.houserent.domain.House;
import com./.../.houserent.service.HouseService;
import com./.../.houserent.utils.Utility;
/**
 * 1.UI
 * 2.Receive user input
 * 3.Call HouseService to complete various operations on house information
 */
public class HouseView {
    private boolean loop = true;//control display menu
    private char key = ' ';//Accept user selection
    private HouseService houseService = new HouseService(10);//array size 10

    //Modify housing information based on id
    //Just adjust findById, no need to add new business functions in HouseService
    public void update(){
        System.out.println("=============Modify housing information============");
        System.out.println("Please select the house number to be modified(-1 quit): ");
        int updateId = Utility.readInt();
        if(updateId == -1){
            System.out.println("=============Modification abandoned============");
            return;
        }
        //Find an object based on the entered ID
        //Because this is a reference object, the original array will be changed synchronously
        House house = houseService.findById(updateId);
        if(house==null){
            System.out.println("=============Housing information does not exist. . .=============");
            return;
        }
        //if the house exists
        System.out.print("Name("+house.getName()+"):");
        String name = Utility.readString(10,"");//If the user presses Enter directly, the default is ""
        if (!"".equals(name)) {//If it is not empty, use the get method to modify
            house.setName(name);
        }
        System.out.print("Telephone(" + house.getPhone() + "):");
        String phone = Utility.readString(12, "");
        if (!"".equals(phone)) {
            house.setPhone(phone);
        }
        System.out.print("address(" + house.getAddress() + "): ");
        String address = Utility.readString(18, "");
        if (!"".equals(address)) {
            house.setAddress(address);
        }
        System.out.print("rent(" + house.getRent() + "):");
        int rent = Utility.readInt(-1);
        if (rent != -1) {
            house.setRent(rent);
        }
        System.out.print("state(" + house.getState() + "):");
        String state = Utility.readString(3, "");
        if (!"".equals(state)) {
            house.setState(state);
        }
        System.out.println("=============Modified housing information successfully============");

    }

    //Find houses by id (improved, look up by address)
    public void findHouse(){
        System.out.println("=============Query housing information============");
        System.out.println("Please enter the property you want to inquire ID:  ");
        int findId = Utility.readInt();
        House houses = houseService.findById(findId);//Returns all house information, stored in the houses array
        if(houses != null){
            System.out.println(houses);
        }else {
            System.out.println("No search results, please enter the correct house ID");
        }
    }
    //Complete Exit Confirmation
    public void exit() {
        //Here we use the Utility method to complete the confirmation
        char c = Utility.readConfirmSelection();
        if (c == 'Y') {
            loop = false;
        }
    }
    //Write delHouse() to receive the input id number
    //Similar to addHouse(), the final deletion logic is implemented in the business class, and only the related methods are called here.
    public void delHouse(){
        System.out.println("=============delete house information============");
        System.out.print("Please enter the house number to be deleted or enter-1 quit: ");
        int delId = Utility.readInt();
        if(delId == -1){
            System.out.println("=============Abandon deletion of housing information============");
            return;
        }
        //The method itself has loop judgment logic, you must enter Y/N to exit
        char choice = Utility.readConfirmSelection();
        if(choice=='Y'){//really delete
            if(houseService.del(delId)){
                System.out.println("=============Delete house information successfully============");
            }else {
                System.out.println("=============The house number does not exist, delete failed============");
            }
        }else {
            System.out.println("=============Abandon deletion of housing information============");
        }


    }
    //Write addHouse() to accept input, create a House object, and call the add method
    //addHouse() is only responsible for adding at the interface level, and the method of actually manipulating the House object array to complete the addition belongs to a specific business function
    //That is, the add() method should be defined in HouseService.java and called in the addHouse() of HouseView.java, following the previous class diagram design
    public void addHouse(){
        System.out.println("=============Add a house============");
        System.out.print("Name: ");
        String name = Utility.readString(8);
        System.out.print("Telephone: ");
        String phone = Utility.readString(12);
        System.out.print("address: ");
        String address = Utility.readString(16);
        System.out.print("monthly rent: ");
        int rent = Utility.readInt();
        System.out.println("state: ");
        String state = Utility.readString(3);
        //Create a new House object
        //id is the system assignment
        House newHouse = new House(0, name, phone, address, rent, state);
        if(houseService.add(newHouse)){
            System.out.println("=============Add house successfully============");
        }else {
            System.out.println("=============Failed to add house============");
        }


    }
    //Write listHouses() to display a list of houses
    //where the instantiation calls the house object House and uses an array of objects
    //Therefore, it is necessary to define House first
    public void listHouses(){
        System.out.println("=============house listing============");
        System.out.println("Numbering\t\t homeowner\t\t Telephone\t\t address\t\t monthly rent\t\t state(not rented/rented)");
        House[] houses = houseService.list();//Returns all house information, stored in the houses array
        for (int i = 0; i < houses.length; i++) {
            if (houses[i] == null) {
                break;
            }
            System.out.println(houses[i]);
        }
        System.out.println("=============The list of houses is displayed============");
    }
    //show main menu
    //The display is still implemented with the do-while loop mentioned earlier, and the loop flag controls whether to end (exit the system) display
    public void mainMenu(){
        do{
            System.out.println("=============Home Rental System Menu============");
            System.out.println("\t\t\t1 Add new listings");
            System.out.println("\t\t\t2 Find a house");
            System.out.println("\t\t\t3 delete house information");
            System.out.println("\t\t\t4 Modify housing information");
            System.out.println("\t\t\t5 house list");
            System.out.println("\t\t\t6 retreat       out");
            System.out.print("Please enter your choice(1-6):");
            key = Utility.readChar();
            switch (key) {
                case '1':
                    addHouse();
                    break;
                case '2':
                    findHouse();
                    break;
                case '3':
                    delHouse();
                    break;
                case '4':
                    update();
                    break;
                case '5':
                    listHouses();
                    break;
                case '6':
                    exit();
                    loop = false;
                    break;
            }
        }while (loop);
    }
}

HouseService.java

package com./.../.houserent.service;
import com./.../.houserent.domain.House;
/*
* //Define House[], save the House object
1.Responding to a HouseView call
2.Complete various operations on housing information
* (CRUD c[create]r[read]u[update]d[delete])*/
public class HouseService {
    private House[] house;
    private int houseNums = 1;//Record how many houses there are currently
    private int idCounter = 1;//Record the value to which the current id grows
    //Constructor
    public HouseService(int size){
        house = new House[size];//When creating a HouseService object, you need to specify the size of the House array
        //Test, initialize a HouseService object
        house[0] = new House(1, "jk", "13544856575","Xiqing District", 1800,"not rented");
    }
    //list method returns house (array)
    public House[] list(){
        return house;
    }

    //findById() method, finds houses according to id, returns House object or null
    public House findById(int findId){
        //iterate over the house array
        for (int i = 0; i < houseNums; i++) {
            if(findId == house[i].getId()){
                return house[i];
            }
        }
        return null;
    }

    //del method, delete a house information
    public boolean del(int delId){
        //The corresponding subscript of the deleted house should be found first, the house number does not correspond to the subscript
        int index = -1;
        for (int i = 0; i < houseNums; i++) {
            if(delId == house[i].getId()){
                //The house to delete (id) is the element of the array index i
                index = i;//record i
            }
        }
        if(index == -1){//Explain that delId does not exist in the array
            return false;
        }
        //If found, how should I delete it?
        //The element after the element at the subscript position to be deleted is moved forward, covering the element to be deleted
        //Then the last bit is set to null, and the above operation is repeated
        for (int i = index; i < houseNums - 1; i++) {
            house[i] = house[i+1];
        }
        //blank the last element
//        house[houseNums - 1] = null;
//        houseNums--;//one element less
        house[--houseNums] = null;//Leave the last of the current housing information blank
        return true;
    }
    //add method, add a new object, return boolean
    public boolean add(House newHouse){
        //Determine whether it can continue to be added (for the time being, the problem of array expansion will not be considered)
        if(houseNums == house.length){//can not add
            System.out.println("The array is full and cannot be added");
            return false;
        }
        //Add the newHouse object to the array
//        house[houseNums] = newHouse;
//        houseNums++;//Add a house
        //The above code can be integrated using the "post++" feature
        //The value of houseNums++ is incremented only after one run
        //For example, if the current houseNums is 1 and the array is set to 10, it is definitely possible to add new house information.
        //Therefore, add newHouse where the array index is 1, after which houseNums is incremented to 2
        house[houseNums++] = newHouse;//post++
        //Need to design an id self-growth mechanism, and then update the id of newHouse
//        idCounter ++;
//        newHouse.setId(idCounter);
        newHouse.setId(++idCounter);//ex++
        return true;
    }
}

House.java

package com./.../.houserent.domain;
/*
* House An object representing a house information*/
public class House {
    //No. Owner Telephone Address Monthly Rent Status (Not Rent/Rented)
    private int id;
    private String name;
    private String phone;
    private String address;
    private int rent;
    private String state;

    public House(int id, String name, String phone, String address, int rent, String state) {
        this.id = id;
        this.name = name;
        this.phone = phone;
        this.address = address;
        this.rent = rent;
        this.state = state;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public int getRent() {
        return rent;
    }

    public void setRent(int rent) {
        this.rent = rent;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    //In order to output object information conveniently, the toString method needs to be implemented
    //For example, there is House h1, so the house information can be printed directly by sout(h1).
    @Override
    public String toString() {
        return id +
                "\t" + name +
                "\t" +phone +
                "\t" + address +
                "\t" + rent +
                "\t" + state ;
    }
}

HouseRentApp.java

package com./.../.houserent;
import com./.../.houserent.view.HouseView;

public class HouseRentApp {
    public static void main(String[] args) {
        //Create a HouseView object to display the interface, which is the main entrance of the program
        new HouseView().mainMenu();
        System.out.println("========signed out========");
    }
}

Tags: Java

Posted by released on Thu, 03 Nov 2022 18:22:36 +0300