| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx

JAVA 集合框架 之 ArrayList 应用

0
Java C/C++ list 3414 次浏览

房屋信息:房主名称,  价格, 描述)

1 . 添加房屋

2 . 列出房屋的所有信息

3 . 根据 房主名称 修改房屋

4 . 按房主名称查询房屋

5 . 根据 房主名称  删除房屋

http://cn.honoit.com/home/?com=detail&id=11113296120378

 

import java.util.List;

 

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/**

 *

 * @author zhangd

 */

public class Test {

 

    /**

     * List 实现房地产公司对, 出租的房屋信息的管理

(房屋信息:房主名称,  价格, 描述)

1 . 添加房屋

2 . 列出房屋的所有信息

3 . 根据 房主名称 修改房屋

4 . 按房主名称查询房屋

5 . 根据 房主名称  删除房屋

 

     */

    public static void main(String[] args) {

        //实例化房地产公司

       Company company=new Company("链家地产");

       //添加房屋

       company.add(new House("李强",1500,"单间"));

       company.add(new House("王浩",3000,"一室一厅"));

       company.add(new House("张涛",4000,"两室一厅"));

       

       //根据 房主名称 修改房屋

       company.updateByOwner(new House("张涛",4500,"两室一厅"));

       

       //按房主名称查询房屋

       House house=company.findByOwner("王浩");

       System.out.println("您查找的王浩房屋信息:"+house.getOwner()+","+house.getDescription()+","+house.getPrice());

       

       //根据 房主名称  删除房屋

       company.deleteByOwner("张涛");

       

       //列出房屋的所有信息

       List houseList=company.getHouseList();

       for(int i=0;i<houseList.size();i++)

       {

           House h=(House)houseList.get(i);

           System.out.println(h.getOwner()+","+h.getPrice()+","+h.getDescription());

       }

       

    }

}

 

 

 

 

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/**

 *

 * @author zhangd

 */

public class House {

    private String owner;

    private double price;

    private String description;

 

    public House(String owner, double price, String description) {

        this.owner = owner;

        this.price = price;

        this.description = description;

    }

 

    public String getOwner() {

        return owner;

    }

 

    public void setOwner(String owner) {

        this.owner = owner;

    }

 

    public double getPrice() {

        return price;

    }

 

    public void setPrice(double price) {

        this.price = price;

    }

 

    public String getDescription() {

        return description;

    }

 

    public void setDescription(String description) {

        this.description = description;

    }

    

    

}

 

 

 

 

 

 

import java.util.ArrayList;

import java.util.List;

 

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

 

/**

 *

 * @author zhangd

 */

public class Company {

    private String name;

    // company 1 对 多 house

    private List houseList;

 

    public Company(String name) {

        this.name = name;

        this.houseList=new ArrayList();

    }

    

    //1 . 添加房屋

    public void add(House h)

    {

        houseList.add(h);

    }

    //2 . 列出房屋的所有信息

    public List getHouseList() {

        return houseList;

    }

    

    //3 . 根据 房主名称 修改房屋

    public boolean updateByOwner(House h)

    {

        for(int i=0;i<houseList.size();i++)

        {

            House house=(House)houseList.get(i);

            if(house.getOwner().equals(h.getOwner()))

            {

                //修改

                houseList.set(i, h);

                return true;

            }

        }

        return false;

    }

    //4 . 按房主名称查询房屋

    public House findByOwner(String owner)

    {

        for(int i=0;i<houseList.size();i++)

        {

            House h=(House)houseList.get(i);

            if(h.getOwner().equals(owner))

            {

                return h;

            }

        }

        return null;

    }

    //5 . 根据 房主名称  删除房屋

    public boolean deleteByOwner(String owner)

    {

        for(int i=0;i<houseList.size();i++)

        {

            House h=(House)houseList.get(i);

            if(h.getOwner().equals(owner))

            {

                houseList.remove(i);

                return true;

            }

        }

        return false;

    }

 

    public String getName() {

        return name;

    }

 

    public void setName(String name) {

        this.name = name;

    }

 

    

 

    public void setHouseList(List houseList) {

        this.houseList = houseList;

    }

    

    

    

}

 

 

33个答案

0

The number 1 online slot game in Thailand, slot 888 online that includes the 888 slot game camp to play more than 300 games. Slot 888

0

Slot deposit 19 get the latest 100 2021 is a new pro slot and the strongest of the year Appealing to slot spinners with low budget who want to take money 19 baht to exchange money in the amount of 100 baht, which is considered very worthwhile because the promotion deposit 19 receives 100 unlimited withdrawals 19รับ100

0

A promotion that many people like and think that it is a worthwhile promotion. ฝาก20รับ100

0

Roma, the most popular online slots game of all time, roma slot 888, play free, online roma slot games. playing for real money Legendary online gambling game 2021 Roma Slots from famous gaming companies โรม่า

0

Direct web slots, not through agents online gambling games The most legendary casino game Stuck in one of the 5 most popular slot game camps. With more than 150 games to choose from, Joker Slot โจ๊กเกอร์

0

Direct web slots, not through agents online gambling games The most legendary casino game Stuck in one of the 5 most popular slot game camps. With more than 150 games to choose from, Joker Slot joker game

0

No deposit required is something that online gambling sites. free credit slots pg There is a reward for the members of the web. free credit slots no deposit will be able to play free slots all within the web เครดิตฟรี

0

No need to turn or call each other easily understood is a promotion, deposit 50, get 150 wallet, is another promotion that many people like and think that it is a worthwhile promotion. ฝาก50รับ150

0

The latest with a game system designed for direct pg slot players because the game format is very advanced, can play pg slot auto via ios and android systems, supports playing pg slots via mobile Deposit-withdraw automatically in just 8 seconds  pg

0

ฝาก20รับ100New arrivals, latest 2021 with special conditions 20 get 100

0

slotcurrently has online slot games. Comes in a new format with 3D images as slots online, direct websites and leading game camps such as PG SLOT JOKER GAME, new member registration, 100% bonus and many more slots

0

เครดิตฟรีcurrently has online slot games. Comes in a new format with 3D images as slots online, direct websites and leading game camps such as PG SLOT JOKER GAME, new member registration, 100% bonus and many more slots

0

PG SLOTThe latest with a game system designed for direct pg slot players because the game format is very advanced, can play pg slot auto via ios and android systems, supports playing pg slots via mobile Deposit-withdraw automatically in just 8 seconds

0

โรม่าJoker online slots that come with a modern system roma joker web slot

0

เล่นสล็อตFree Trial PG and Joker is to play slots for free without having to pay a deposit first. There are currently playing slots. mostly through the mobile internet without having to go to the casino to play slots

0

Betflixcurrently has online slot games. Comes in a new format with 3D images as slots online, direct websites and leading game camps such as PG SLOT JOKER GAME, new member registration, 100% bonus and many more slots

0

joker gameonline slot games The most popular of the year 2021, joker game, deposit-withdraw, no minimum, there is a popular game like roma slot, apply for a joker game today, get a 100% bonus if you ask about the hot online gambling game overtaking the curve.

0

PGFree Trial PG and Joker is to play slots for free without having to pay a deposit first. There are currently playing slots. mostly through the mobile internet without having to go to the casino to play slots

0

I love how you decorated your house. It looks like it belongs on HGTVhttps://privateinvestigatortallahassee.com

0

Your article is awesome. I enjoyed reading your article. This is really a great document for me. I've bookmarked it and I'm looking forward to reading new posts. Please continue to uphold! the impossible quiz

1 2