By GokiSoft.com| 23:41 23/11/2020|
Java Basic

Java basic- Assignment - Quản lý nhà

* Xây dựng một giao diện (interface) IHouse nằm trong gói house.cm gồm có 2 phương thức:

            - public void input();

            - public void display();

 

* Xây dựng lớp House thực thi  giao diện IHouse và cũng nằm trong gói house.cm, bổ sung thêm các thuộc tính sau:

private String soNha;

private String diaChi;

private String loaiNha;

Cài đặt các Constructor có tham số và không có tham số.

Cài đặt các phương thức set/get cho các thuộc tính trong lớp.

Cài đè (override) các phương thức nhập và hiển thị trong giao diện IHouse.

 

* Cài đặt lớp HaNoiHouse nằm trong gói house.hanoi kế thừa lớp House ở trên vào bổ sung thêm các thuộc tính:

- private String tenQuan;

Cài đặt 2 constructor, trong đó constructor có tham số phải sử dụng từ khóa super để gọi constructor của lớp House.

Cài đặt các phương thức get/set cho thuộc tính bổ sung.

Override các phương thức input(), display() trong lớp House.

 

* Xây dựng lớp ManagerHouse nằm trong gói house.hanoi

Tạo menu như sau và cài đặt để thực thi các công việc theo từng menu đó:

            1. Nhập thông tin n ngôi nhà ở Hà Nội

            2. Hiển thị thông tin của n ngôi nhà đó.

            3. Sắp xếp theo trường địa chỉ và hiển thị thông tin sau khi sắp xếp.

            4. Tìm kiếm nhà theo địa chỉ nhập vào.

            5. Thoát.

Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

nguyễn văn huy [T1907A]
nguyễn văn huy

2020-03-17 13:57:34



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package nhatao.hanoi;
import java.util.*;
/**
 *
 * @author ASUS
 */
public class main {
    public static void main(String[] args) {
        ArrayList<hanoihouse> hn=new ArrayList<>();
        Scanner scan=new Scanner(System.in);
        int choise,n;
        do{
            menu();
            choise =Integer.parseInt(scan.nextLine());
            switch(choise){
                case 1:
                    n=Integer.parseInt(scan.nextLine());
                    for (int i = 0; i < 10; i++) {
                        hanoihouse hanoi=new hanoihouse();
                        hanoi.input();
                        hn.add(hanoi);
                    }
                    break;
                case 2:
                    for (int i = 0; i < hn.size(); i++) {
                        hn.get(i).display();
                    }
                    break;
                case 3:
                    System.out.println("sap sep theo dia chi");
                    Collections.sort(hn, new Comparator<hanoihouse>() {
                @Override
                public int compare(hanoihouse o1, hanoihouse o2) {
                    return o1.getDiaChi().compareTo(o2.getDiaChi()); //To change body of generated methods, choose Tools | Templates.
                }
            });
                    break;
                case 4:
                    System.out.println("nhap dia chi can tim");
                    String diachi=scan.nextLine();
                    for (int i = 0; i < hn.size(); i++) {
                        if(hn.get(i).getDiaChi().equalsIgnoreCase(diachi)){
                            hn.get(i).display();
                        }
                    }
                    break;
                case 5:
                    System.out.println("thoat");
                    break;
                default:
                    System.out.println("Sai!!!!");
                    
                    break;
            }
            
        }while(choise!=5);
    }
 public static void menu(){
     System.out.println("1. Nhập thông tin n ngôi nhà ở Hà Nội");
     System.out.println("2. Hiển thị thông tin của n ngôi nhà đó.");
     System.out.println("3. Sắp xếp theo trường địa chỉ và hiển thị thông tin sau khi sắp xếp.");
     System.out.println("4. Tìm kiếm nhà theo địa chỉ nhập vào");
     System.out.println("5.Thoat");
 }       
}
///////
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package nhatao.hanoi;
import nhatao.cm.house;
import java.util.*;
/**
 *
 * @author ASUS
 */
public class hanoihouse extends house{
   private String tenQuan;

    public hanoihouse() {
    }
    public hanoihouse(String tenQuan){
        this.tenQuan=tenQuan;
    }

    public hanoihouse(String tenQuan,String soNha,String diaChi,String loaiNha) {
        super(soNha,diaChi,loaiNha);
        this.tenQuan = tenQuan;
    }

    public String getTenQuan() {
        return tenQuan;
    }

    public void setTenQuan(String tenQuan) {
        this.tenQuan = tenQuan;
    }
   @Override
    public void input(){
      Scanner scan=new Scanner(System.in);
       System.out.println("nhap ten quan");
       tenQuan=scan.nextLine();
    }
   @Override
    public void display(){
       super.display();
       System.out.println(toString());
    }

    @Override
    public String toString() {
        return "hanoihouse{" + "tenQuan=" + tenQuan + '}';
    }

    
}
/////
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package nhatao.cm;

import java.util.*;

/**
 *
 * @author ASUS
 */
public class house implements inter {

    private String soNha;
    private String diaChi;
    private String loaiNha;

    public house() {
    }

    public house(String soNha, String diaChi, String loaiNha) {
        this.soNha = soNha;
        this.diaChi = diaChi;
        this.loaiNha = loaiNha;
    }

    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.println("nhap so nha");
        soNha = scan.nextLine();
        System.out.println("nhap dia chi");
        diaChi = scan.nextLine();
        System.out.println("nha loai nha");
        loaiNha = scan.nextLine();
    }

    public void display() {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "house{" + "soNha=" + soNha + ", diaChi=" + diaChi + ", loaiNha=" + loaiNha + '}';
    }

    public String getSoNha() {
        return soNha;
    }

    public void setSoNha(String soNha) {
        this.soNha = soNha;
    }

    public String getDiaChi() {
        return diaChi;
    }

    public void setDiaChi(String diaChi) {
        this.diaChi = diaChi;
    }

    public String getLoaiNha() {
        return loaiNha;
    }

    public void setLoaiNha(String loaiNha) {
        this.loaiNha = loaiNha;
    }

}
/////
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package nhatao.cm;

/**
 *
 * @author ASUS
 */
public interface inter {
    public void input();
    public void display();
}



NguyenHuuThanh [T1907A]
NguyenHuuThanh

2020-03-15 03:46:34



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package house.cm;
import java.util.Scanner;
/**
 *
 * @author Minh
 */
public class House implements IHouse {
    private String soNha;
    private String diaChi;
    private String loaiNha;
    
    public House()
    {
        
    }

    public House(String soNha, String diaChi, String loaiNha) {
        this.soNha = soNha;
        this.diaChi = diaChi;
        this.loaiNha = loaiNha;
    }

    public String getSoNha() {
        return soNha;
    }

    public void setSoNha(String soNha) {
        this.soNha = soNha;
    }

    public String getDiaChi() {
        return diaChi;
    }

    public void setDiaChi(String diaChi) {
        this.diaChi = diaChi;
    }

    public String getLoaiNha() {
        return loaiNha;
    }

    public void setLoaiNha(String loaiNha) {
        this.loaiNha = loaiNha;
    }
    @Override
    public void input()
    {
        Scanner scan = new Scanner(System.in);
        soNha = scan.nextLine();
        diaChi = scan.nextLine();
        loaiNha = scan.nextLine();
    }
    @Override 
    public void display()
    {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "House{" + "soNha=" + soNha + ", diaChi=" + diaChi + ", loaiNha=" + loaiNha + '}';
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package house.cm;

/**
 *
 * @author Minh
 */
public interface IHouse {
     public void input();
     public void display();
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package house.hanoi;
import java.util.Scanner;
import house.cm.House;

/**
 *
 * @author Minh
 */
public class HanoiHouse extends House {
    String tenQuan;
    
    public HanoiHouse()
    {
        
    }   

    public HanoiHouse(String tenQuan) {
        this.tenQuan = tenQuan;
    }

    public HanoiHouse(String tenQuan, String soNha, String diaChi, String loaiNha) {
        super(soNha, diaChi, loaiNha);
        this.tenQuan = tenQuan;
    }

    public String getTenQuan() {
        return tenQuan;
    }

    public void setTenQuan(String tenQuan) {
        this.tenQuan = tenQuan;
    }
    
    @Override
    public void input()
    {
        Scanner scan = new Scanner(System.in);
        super.input();
        tenQuan = scan.nextLine();
    }
    @Override
    public void display()
    {
        super.display();
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "HanoiHouse{" + "tenQuan=" + tenQuan + '}';
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package house.hanoi;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
/**
 *
 * @author Minh
 */
public class Managerhouse {
    public static void main(String[] args)
    {
        int choice;
        Scanner scan = new Scanner(System.in);
        ArrayList<HanoiHouse> hnhouse = new ArrayList<>();
        
        do{
            showMenu();
            System.out.println("Nhap lua chon");
            choice =Integer.parseInt(scan.nextLine());
            
            
            
            switch(choice){
                case 1 :
                    int n = Integer.parseInt(scan.nextLine());
                    for(int i = 0 ; i < n; i++)
                    {
                        HanoiHouse h = new HanoiHouse();
                        h.input();
                        hnhouse.add(h);
                    }
                    break;
                case 2 :
                    for(int i = 0 ; i < hnhouse.size() ; i++)
                    {
                        hnhouse.get(i).display();
                    }
                    break;
                case 3 :
                    System.out.println("Sap xep theo dia chi");
                    Collections.sort(hnhouse, new Comparator<HanoiHouse>(){
                        @Override
                        public int compare (HanoiHouse o1 , HanoiHouse o2){
                          return o1.getDiaChi().compareTo(o2.getDiaChi());
                        }
                    });
                    break;
                case 4 :
                    System.out.println("Nhap dia chi nha");
                    String dc = scan.nextLine();
                    
                    for ( int i = 0 ; i < hnhouse.size(); i++)
                    {
                        if(hnhouse.get(i).getDiaChi().equalsIgnoreCase(dc))
                        {
                            hnhouse.get(i).display();
                        }
                    }
                    break;
                case 5 :
                    System.out.println("Thoat");
                    break;
                default :
                    System.out.println("Moi ban nhap lai");
                    break;
                
                
                
            }
        }while(choice!=5);
        
    }
    public static void showMenu()
    {
        System.out.println("1.Nhap thong tin n ngôi nhà ở Hà Nội");
        System.out.println("2. Hiển thị thông tin của n ngôi nhà đó");
        System.out.println("3. Sắp xếp theo địa chỉ");
        System.out.println("4. Tìm kiếm theo địa chỉ");
        System.out.println("5. Thoát");
    }
    
}



Minh Nghia [T1907A]
Minh Nghia

2020-03-14 14:46:52



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package House.cm;

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class House {
    private String soNha;
    private String diaChi;
    private String loaiNha;

    public House() {
    }

    public House(String soNha, String diaChi, String loaiNha) {
        this.soNha = soNha;
        this.diaChi = diaChi;
        this.loaiNha = loaiNha;
    }

    public String getSoNha() {
        return soNha;
    }

    public void setSoNha(String soNha) {
        this.soNha = soNha;
    }

    public String getDiaChi() {
        return diaChi;
    }

    public void setDiaChi(String diaChi) {
        this.diaChi = diaChi;
    }

    public String getLoaiNha() {
        return loaiNha;
    }

    public void setLoaiNha(String loaiNha) {
        this.loaiNha = loaiNha;
    }
    
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap so nha:");
        soNha = scan.nextLine();
        System.out.println("Nhap dia chi:");
        diaChi = scan.nextLine();
        System.out.println("Nhap loai nha:");
        loaiNha = scan.nextLine();
    }
    public void display(){
        System.out.println("So nha:" + soNha);
        System.out.println("Dia chi:" + diaChi);
        System.out.println("Loai nha:" + loaiNha);
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package House.cm;

/**
 *
 * @author Administrator
 */
public interface IHouse {
    
        public void input();
      
        public void display();
          
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package House.hanoi;

import House.cm.House;
import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class HaNoiHouse extends House{
    private String tenQuan;

    public HaNoiHouse() {
    }

    public HaNoiHouse(String soNha, String diaChi, String loaiNha) {
        super(soNha, diaChi, loaiNha);
    }

    public String getTenQuan() {
        return tenQuan;
    }

    public void setTenQuan(String tenQuan) {
        this.tenQuan = tenQuan;
    }
    @Override
    public void input(){
        Scanner scan = new Scanner(System.in);
        super.input();
        System.out.println("Nhap ten quan:");
        tenQuan = scan.nextLine();
    }
    @Override
    public void display(){
        super.display();
        System.out.println("Ten quan:" + tenQuan);
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package House.hanoi;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class ManagerHouse {
    public static void main(String[] args) {
        int choose;
        
        ArrayList<HaNoiHouse> list = new ArrayList<>();
        Scanner scan = new Scanner(System.in);
        
        do{
            showMenu();
            choose = Integer.parseInt(scan.nextLine());
            
            switch(choose){
                case 1:
                    System.out.println("Nhap thong tin N ngoi nha o Han Noi:");
                    int n = Integer.parseInt(scan.nextLine());
                    
                    for(int i = 0; i < n; i++){
                        HaNoiHouse haNoiHouse = new HaNoiHouse();
                        haNoiHouse.input();
                        
                        list.add(haNoiHouse);
                    }
                    break;
                case 2:
                    for(int i = 0 ; i < list.size(); i++ ){
                        list.get(i).display();
                    }
                    break;
                case 3:
                    Collections.sort(list, new Comparator<HaNoiHouse>() {
                        @Override
                        public int compare(HaNoiHouse o1, HaNoiHouse o2) {
                            if(o1.getDiaChi().equalsIgnoreCase(o2.getDiaChi())){
                                return 1;
                            }
                            return -1;
                    }
                    });
                    for (int i = 0; i < list.size(); i++) {
                        list.get(i).display();
                    }
                    break;
                case 4:
                    String diaChi;
                    System.out.println("Nhap dia chi can tim:");
                    diaChi = scan.nextLine();
                    for (int i = 0; i < list.size(); i++) {
                        if(list.get(i).getDiaChi().equalsIgnoreCase(diaChi)){
                            list.get(i).display();
                        }
                    }
                    break;
                case 5:
                    System.out.println("Thoat.");
                    break;
                default:
                    System.out.println("Chon lai:");
                     break;
            }
        }while(choose != 5);
            
    }
    public static void showMenu(){
        System.out.println("1. Nhập thông tin n ngôi nhà ở Hà Nội");
        System.out.println("2. Hiển thị thông tin của n ngôi nhà đó.");
        System.out.println("3. Sắp xếp theo trường địa chỉ và hiển thị thông tin sau khi sắp xếp.");
        System.out.println("4. Tìm kiếm nhà theo địa chỉ nhập vào.");
        System.out.println("5. Thoat.");
        System.out.println("Choose:");
    } 
}



Phí Văn Long [T1907A]
Phí Văn Long

2020-03-14 07:45:01

main :



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QuanLiNha;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Main {
      public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int choose;
        ArrayList<HaNoiHouse> list = new ArrayList<>();
        do {
            showMenu();
            System.out.print("Nhap lua chon: ");
            choose = Integer.parseInt(scan.nextLine());
            switch (choose) {
                case 1:
                    System.out.print("Nhap n ngoi nha: ");
                    int n = Integer.parseInt(scan.nextLine());
                    for (int i = 0; i < n; i++) {
                        HaNoiHouse hn = new HaNoiHouse();
                        System.out.println("Nhap thong tin ngoi nha thu " + (i + 1) + " :");
                        hn.input();
                        list.add(hn);
                    }
                    break;
                case 2:
                    for (int j = 0; j < list.size(); j++) {
                        System.out.println("Thong tin ngoi nha thu " + (j + 1) + " la: ");
                        list.get(j).display();
                    }
                    break;
                case 3:
                    Collections.sort(list, new Comparator<HaNoiHouse>() {
                        @Override
                        public int compare(HaNoiHouse o1, HaNoiHouse o2) {
                            if (o1.getDiaChi().equalsIgnoreCase(o2.getDiaChi())) {
                                return 1;
                            }
                            return -1;
                        }
                    });
                    for (int i = 0; i < list.size(); i++) {
                        list.get(i).display();
                    }
                    break;
                case 4:
                    System.out.println("Nhap ten dia chi nha can tim: ");
                    String diachi = scan.nextLine();
                    System.out.println("Thong tin ngoi nha can tim la: ");
                    for (int k = 0; k < list.size(); k++) {
                        if (list.get(k).getDiaChi().equalsIgnoreCase(diachi)) {
                            list.get(k).display();
                        } else {
                            System.out.println("Khong tim thay thong tin ngoi nha co dia chi: " + diachi);
                        }
                    }
                    break;
                case 5:
                    System.out.println("Thoat.");
                    break;
                default:
                    System.err.println("Nhap sai !!!");
                    break;
            }
        } while (choose != 5);


    }

    public static void showMenu() {
        System.out.println("*==================*");
        System.out.println("1. Nhap thong tin so ngoi nha o Ha Noi.");
        System.out.println("2. Hien thi thong tin cua so ngoi nha do.");
        System.out.println("3. Sap xep theo truong dia chi va hien thi thong tin sau khi sap xep.");
        System.out.println("4. Tim kiem nha theo dia chi nhap vao.");
        System.out.println("5. Thoat.");
        System.out.println("*==================*");

    }
}

HaNoiHouse:



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QuanLiNha;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class HaNoiHouse extends House {
    private String tenQuan;

    public HaNoiHouse() {
    }

    public HaNoiHouse(String soNha, String diaChi, String loaiNha, String tenQuan) {
        super(soNha, diaChi, loaiNha);
        this.tenQuan = tenQuan;
    }

    public String getTenQuan() {
        return tenQuan;
    }

    public void setTenQuan(String tenQuan) {
        this.tenQuan = tenQuan;
    }

    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        super.input();
        System.out.println("Nhap ten quan: ");
        tenQuan = scan.nextLine();
        System.out.println("");
    }

    @Override
    public void display() {
        super.display();
        System.out.println("Ten quan la: " + tenQuan);
        System.out.println("");
    }
}
iHouse:




/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QuanLiNha;

/**
 *
 * @author Admin
 */
public interface IHouse {
    public void input();
    public void display();
}

House:



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QuanLiNha;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class House implements IHouse {
   private String soNha;
    private String diaChi;
    private String loaiNha;

    public House() {
    }

    public House(String soNha, String diaChi, String loaiNha) {
        this.soNha = soNha;
        this.diaChi = diaChi;
        this.loaiNha = loaiNha;
    }

    public String getSoNha() {
        return soNha;
    }

    public void setSoNha(String soNha) {
        this.soNha = soNha;
    }

    public String getDiaChi() {
        return diaChi;
    }

    public void setDiaChi(String diaChi) {
        this.diaChi = diaChi;
    }

    public String getLoaiNha() {
        return loaiNha;
    }

    public void setLoaiNha(String loaiNha) {
        this.loaiNha = loaiNha;
    }

    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap so nha: ");
        soNha = scan.nextLine();
        System.out.println("Nhap dia chi: ");
        diaChi = scan.nextLine();
        System.out.println("Nhap loai nha: ");
        loaiNha = scan.nextLine();
    }

    @Override
    public void display() {
        System.out.println("So nha la: " + soNha);
        System.out.println("Dia chi nha la: " + diaChi);
        System.out.println("Loai nha la: " + loaiNha);
    } 
}



Phan Bạch Tùng Dương [T1907A]
Phan Bạch Tùng Dương

2020-03-14 07:43:31



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QLNha;

/**
 *
 * @author Admin
 */

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int choose;
        ArrayList<HaNoiHouse> list = new ArrayList<>();
        do {
            showMenu();
            System.out.print("Chon : ");
            choose = Integer.parseInt(scan.nextLine());
            switch (choose) {
                case 1:
                    System.out.print("Nhap n ngoi nha: ");
                    int n = Integer.parseInt(scan.nextLine());
                    for (int i = 0; i < n; i++) {
                        HaNoiHouse hn = new HaNoiHouse();
                        System.out.println("Nhap thong tin ngoi nha thu " + (i + 1) + " :");
                        hn.input();
                        list.add(hn);
                    }
                    break;
                case 2:
                    for (int j = 0; j < list.size(); j++) {
                        System.out.println("Thong tin ngoi nha thu " + (j + 1) + " la: ");
                        list.get(j).display();
                    }
                    break;
                case 3:
                    Collections.sort(list, new Comparator<HaNoiHouse>() {
                        @Override
                        public int compare(HaNoiHouse o1, HaNoiHouse o2) {
                            if (o1.getDiaChi().equalsIgnoreCase(o2.getDiaChi())) {
                                return 1;
                            }
                            return -1;
                        }
                    });
                    for (int i = 0; i < list.size(); i++) {
                        list.get(i).display();
                    }
                    break;
                case 4:
                    System.out.println("Nhap ten dia chi nha can tim : ");
                    String diachi = scan.nextLine();
                    System.out.println("Thong tin ngoi nha can tim : ");
                    for (int k = 0; k < list.size(); k++) {
                        if (list.get(k).getDiaChi().equalsIgnoreCase(diachi)) {
                            list.get(k).display();
                        } else {
                            System.out.println("Khong tim thay thong tin ngoi nha co dia chi: " + diachi);
                        }
                    }
                    break;
                case 5:
                    System.out.println("Thoat.");
                    break;
                default:
                    System.err.println("!!!Error!!!");
                    break;
            }
        } while (choose != 5);


    }

    public static void showMenu() {
        System.out.println("1. Nhap thon tin n ngoi nha o Ha Noi : ");
        System.out.println("2. Hien thi thong tin cua n ngoi nha do : ");
        System.out.println("3. Sap xep theo truong dia chi va hien thi thong tin sau khi sap xep : ");
        System.out.println("4. Tim kiem nha theo dia chi : ");
        System.out.println("5. Thoát.");
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QLNha;

/**
 *
 * @author Admin
 */
public interface IHouse {
    public void input();
    public void display();
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QLNha;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class House implements IHouse {

    
    private String soNha;
    private String diaChi;
    private String loaiNha;

    public House() {
    }

    public House(String soNha, String diaChi, String loaiNha) {
        this.soNha = soNha;
        this.diaChi = diaChi;
        this.loaiNha = loaiNha;
    }

    public String getSoNha() {
        return soNha;
    }

    public void setSoNha(String soNha) {
        this.soNha = soNha;
    }

    public String getDiaChi() {
        return diaChi;
    }

    public void setDiaChi(String diaChi) {
        this.diaChi = diaChi;
    }

    public String getLoaiNha() {
        return loaiNha;
    }

    public void setLoaiNha(String loaiNha) {
        this.loaiNha = loaiNha;
    }

    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap so nha : ");
        soNha = scan.nextLine();
        System.out.println("Nhap dia chi : ");
        diaChi = scan.nextLine();
        System.out.println("Nhap loai nha : ");
        loaiNha = scan.nextLine();
    }

    @Override
    public void display() {
        System.out.println("So nha la : " + soNha);
        System.out.println("Dia chi nha la : " + diaChi);
        System.out.println("Loai nha la : " + loaiNha);
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package QLNha;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class HaNoiHouse extends House {
    private String tenQuan;

    public HaNoiHouse() {
    }

    public HaNoiHouse(String soNha, String diaChi, String loaiNha, String tenQuan) {
        super(soNha, diaChi, loaiNha);
        this.tenQuan = tenQuan;
    }

    public String getTenQuan() {
        return tenQuan;
    }

    public void setTenQuan(String tenQuan) {
        this.tenQuan = tenQuan;
    }

    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        super.input();
        System.out.println("Nhap ten quan: ");
        tenQuan = scan.nextLine();
        System.out.println("");
    }

    @Override
    public void display() {
        super.display();
        System.out.println("Ten quan la: " + tenQuan);
        System.out.println("");
    }
}



thienphu [T1907A]
thienphu

2020-03-13 15:11:17



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package house.cm;

/**
 *
 * @author Thien Phu
 */
public interface IHouse {

    void input();

    void display();
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package house.cm;

import java.util.Scanner;

/**
 *
 * @author Thien Phu
 */
public class House implements IHouse {

    private String soNha;
    private String diaChi;
    private String loaiNha;

    public House() {
    }

    public House(String soNha, String diaChi, String loaiNha) {
        this.soNha = soNha;
        this.diaChi = diaChi;
        this.loaiNha = loaiNha;
    }

    public String getSoNha() {
        return soNha;
    }

    public void setSoNha(String soNha) {
        this.soNha = soNha;
    }

    public String getDiaChi() {
        return diaChi;
    }

    public void setDiaChi(String diaChi) {
        this.diaChi = diaChi;
    }

    public String getLoaiNha() {
        return loaiNha;
    }

    public void setLoaiNha(String loaiNha) {
        this.loaiNha = loaiNha;
    }

    @Override
    public void input() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap sonha:");
        soNha = sc.nextLine();
        System.out.println("Nhap diachi: ");
        diaChi = sc.nextLine();
        System.out.println("Nhap loaiNha");
        loaiNha = sc.nextLine();
    }

    @Override
    public void display() {
        System.out.print(toString());
    }

    @Override
    public String toString() {
        return "House:" + "soNha=" + soNha + ", diaChi=" + diaChi + ", loaiNha=" + loaiNha;
    }

}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package house.cm;

import java.util.Scanner;

/**
 *
 * @author Thien Phu
 */
public class HaNoiHouse extends House {

    private String tenQuan;

    public HaNoiHouse() {
    }

    public HaNoiHouse(String tenQuan, String soNha, String diaChi, String loaiNha) {
        super(soNha, diaChi, loaiNha);
        this.tenQuan = tenQuan;
    }

    public void setTenQuan(String tenQuan) {
        this.tenQuan = tenQuan;
    }

    public String getTenQuan() {
        return tenQuan;
    }

    @Override
    public void display() {
        super.display(); //To change body of generated methods, choose Tools | Templates.
        System.out.print(" TenQuan: " + tenQuan);
    }

    @Override
    public void input() {
        super.input();
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap ten Quan:");
        tenQuan = sc.nextLine();

    }

}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package house.cm;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author Thien Phu
 */
public class ListHouse {

    private List<HaNoiHouse> houselist = new ArrayList<>();
    private static Scanner sc = new Scanner(System.in);

    public ListHouse() {
    }

    public void inputN() {
        System.out.println("Nhap thong tin N ngoi nha o Ha Noi");
        int n = Integer.parseInt(sc.nextLine());
        for (int i = 0; i < n; i++) {
            HaNoiHouse hn = new HaNoiHouse();
            hn.input();
            houselist.add(hn);
        }
    }

    public void display() {
        for (HaNoiHouse houselist1 : houselist) {
            houselist1.display();
            System.out.println("");
        }
    }

    public void findAddress() {
        int a = -1;
        System.out.println("Nhap dia chi can tim:");
        String address = sc.nextLine();
        for (int i = 0; i < houselist.size(); i++) {
            if (houselist.get(i).getDiaChi().equalsIgnoreCase(address)) {
                a = i;
            }
        }
        if (a != -1) {
            System.out.println("Thong tin can tim la: " + address);
            houselist.get(a).display();
        } else {
            System.err.println("Dia chi nay khong ton tai");
        }
    }

    //sap xep theo dia chi
    public void sapxep() {
        Collections.sort(houselist, new Comparator<HaNoiHouse>() {

            @Override
            public int compare(HaNoiHouse o1, HaNoiHouse o2) {
                return o1.getDiaChi().compareToIgnoreCase(o2.getDiaChi());
            }
        }
        );
        System.out.println("danh sap nha sap xep theo dia chi:");
        display();
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package house.cm;

import java.util.Scanner;

/**
 *
 * @author Thien Phu
 */
public class ManagerHouse {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ListHouse listHouse = new ListHouse();
        int choose;
        do {
            showmenu();
            choose = Integer.parseInt(sc.nextLine());
            switch (choose) {
                case 1:
                    listHouse.inputN();
                    break;
                case 2:
                    listHouse.display();
                    break;

                case 3:
                    listHouse.sapxep();
                    break;
                case 4:
                    listHouse.findAddress();
                    break;
                case 5:
                    System.out.println("Exit thanh cong");
                    break;
                default:
                    System.err.println("Nhap sai roi");
                    break;
            }
        } while (choose != 5);
    }

    public static void showmenu() {
        System.out.println("1. Nhập thông tin n ngôi nhà ở Hà Nội");
        System.out.println("2. Hiển thị thông tin của n ngôi nhà đó.");
        System.out.println("3. Sắp xếp theo trường địa chỉ và hiển thị thông tin sau khi sắp xếp.");
        System.out.println("4. Tìm kiếm nhà theo địa chỉ nhập vào.");
        System.out.println("5: Thoat");
        System.out.println("Choose: ");
    }

}



Trương Công Vinh [T1907A]
Trương Công Vinh

2020-03-13 10:57:05



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package house.hanoi;

import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
/**
 *
 * @author DELL
 */
public class ManagerHouse {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        ArrayList<HaNoiHouse> houseHN = new ArrayList<>();
         int c;
         do{
             menu();
             c= Integer.parseInt(scan.nextLine());
             switch(c){
                 case 1:
                     int n;
                     System.out.println("Nhap so ngoi nha can quan ly : ");
                     n=Integer.parseInt(scan.nextLine());
                     for (int i = 0; i < n; i++) {
                         HaNoiHouse h = new HaNoiHouse();
                         h.input();
                         houseHN.add(h);
                     }
                     break;
                 case 2:
                     System.out.println("Show InHouse : ");
                     for (int i = 0; i < houseHN.size(); i++) {
                         houseHN.get(i).display();
                     }
                     break;
                 case 3:
                     Collections.sort(houseHN, new Comparator<HaNoiHouse>() {
                 @Override
                 public int compare(HaNoiHouse o1, HaNoiHouse o2) {
                     if(o1.getDiaChi().equalsIgnoreCase(o2.getDiaChi())){
                         return 1;
                     }return -1;
                 }
             });
                     for (int i = 0; i < houseHN.size(); i++) {
                         houseHN.get(i).display();
                     }
                    
                     break;
                 case 4:
                     String dc ;
                     System.out.println("Nhap dia Chi can tim : ");
                     dc = scan.nextLine();
                     for (int i = 0; i < houseHN.size(); i++) {
                         if(houseHN.get(i).getDiaChi().equalsIgnoreCase(dc))
                         {
                             houseHN.get(i).display();
                         }
                     }
                     break;
                 case 5:
                     System.out.println("End!!");
                     break;
                 default :
                     
                     break;
                 
             }
         }while(c!=5);
    }

    public static void menu() {
        System.out.println("1. Nhập thông tin n ngôi nhà ở Hà Nội");
        System.out.println("2. Hiển thị thông tin của n ngôi nhà đó.");
        System.out.println("3. Sắp xếp theo trường địa chỉ và hiển thị thông tin sau khi sắp xếp.");
        System.out.println("4. Tìm kiếm nhà theo địa chỉ nhập vào.");
        System.out.println("5. Thoát.");
        System.out.println("Chon : ");
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package house.hanoi;

import house.cm.House;
import java.util.Scanner;

/**
 *
 * @author DELL
 */
public class HaNoiHouse extends House {

    Scanner scan = new Scanner(System.in);

    private String tenQuan;

    public HaNoiHouse() {
    }

    public HaNoiHouse(String tenQuan, String soNha, String diaChi, String loaiNha) {
        super(soNha, diaChi, loaiNha);
        this.tenQuan = tenQuan;
    }

    public String getTenQuan() {
        return tenQuan;
    }

    public void setTenQuan(String tenQuan) {
        this.tenQuan = tenQuan;
    }

    @Override
    public void input() {

        super.input();
        System.out.println("Nhap ten quan : ");
        tenQuan = scan.nextLine();
    }

    @Override
    public void display() {
        super.display();
        System.out.println("Ten quan : " + tenQuan);

    }

}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package house.cm;

import java.util.Scanner;

/**
 *
 * @author DELL
 */
public class House {

    private String soNha;

    private String diaChi;

    private String loaiNha;

    public House() {
    }

    public House(String soNha, String diaChi, String loaiNha) {
        this.soNha = soNha;
        this.diaChi = diaChi;
        this.loaiNha = loaiNha;
    }

    public String getSoNha() {
        return soNha;
    }

    public void setSoNha(String soNha) {
        this.soNha = soNha;
    }

    public String getDiaChi() {
        return diaChi;
    }

    public void setDiaChi(String diaChi) {
        this.diaChi = diaChi;
    }

    public String getLoaiNha() {
        return loaiNha;
    }

    public void setLoaiNha(String loaiNha) {
        this.loaiNha = loaiNha;
    }

    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.println("So nha : ");
        soNha = scan.nextLine();
        System.out.println("Dia chi : ");
        diaChi = scan.nextLine();
        System.out.println("Loai nha : ");
        loaiNha = scan.nextLine();
    }

    public void display() {
        System.out.println("So nha : "+soNha);
        System.out.println("Dia chi : "+diaChi);
        System.out.println("Loai nha : "+loaiNha);

    }

}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package house.cm;

/**
 *
 * @author DELL
 */
public interface IHouse {

    public void input();

    public void display();
}



Đỗ Văn Huấn [T1907A]
Đỗ Văn Huấn

2020-03-11 15:17:27


package ASSIGNMENT.assignment1.house.cm;

import java.util.Scanner;

public class House implements IHouse {


private String soNha;
private String diaChi;
private String loaiNha;

public House() {
}

public House(String soNha, String diaChi, String loaiNha) {
this.soNha = soNha;
this.diaChi = diaChi;
this.loaiNha = loaiNha;
}

public String getSoNha() {
return soNha;
}

public void setSoNha(String soNha) {
this.soNha = soNha;
}

public String getDiaChi() {
return diaChi;
}

public void setDiaChi(String diaChi) {
this.diaChi = diaChi;
}

public String getLoaiNha() {
return loaiNha;
}

public void setLoaiNha(String loaiNha) {
this.loaiNha = loaiNha;
}

@Override
public void input() {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap so nha: ");
soNha = scan.nextLine();
System.out.println("Nhap dia chi: ");
diaChi = scan.nextLine();
System.out.println("Nhap loai nha: ");
loaiNha = scan.nextLine();
}

@Override
public void display() {
System.out.println("So nha la: " + soNha);
System.out.println("Dia chi nha la: " + diaChi);
System.out.println("Loai nha la: " + loaiNha);
}
}
package ASSIGNMENT.assignment1.house.cm;

public interface IHouse {
public void input();
public void display();
}
package ASSIGNMENT.assignment1.house.hanoi;

import ASSIGNMENT.assignment1.house.cm.House;

import java.util.Scanner;

public class HaNoiHouse extends House {
private String tenQuan;

public HaNoiHouse() {
}

public HaNoiHouse(String soNha, String diaChi, String loaiNha, String tenQuan) {
super(soNha, diaChi, loaiNha);
this.tenQuan = tenQuan;
}

public String getTenQuan() {
return tenQuan;
}

public void setTenQuan(String tenQuan) {
this.tenQuan = tenQuan;
}

@Override
public void input() {
Scanner scan = new Scanner(System.in);
super.input();
System.out.println("Nhap ten quan: ");
tenQuan = scan.nextLine();
System.out.println("");
}

@Override
public void display() {
super.display();
System.out.println("Ten quan la: " + tenQuan);
System.out.println("");
}
}
package ASSIGNMENT.assignment1.house.hanoi;


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class ManagerHouse {
public static void main(String[] args) {

Scanner scan = new Scanner(System.in);
int choose;
ArrayList<HaNoiHouse> list = new ArrayList<>();
do {
showMenu();
System.out.print("Nhập lựa chọn: ");
choose = Integer.parseInt(scan.nextLine());
switch (choose) {
case 1:
System.out.print("Nhap n ngoi nha: ");
int n = Integer.parseInt(scan.nextLine());
for (int i = 0; i < n; i++) {
HaNoiHouse hn = new HaNoiHouse();
System.out.println("Nhap thong tin ngoi nha thu " + (i + 1) + " :");
hn.input();
list.add(hn);
}
break;
case 2:
for (int j = 0; j < list.size(); j++) {
System.out.println("Thong tin ngoi nha thu " + (j + 1) + " la: ");
list.get(j).display();
}
break;
case 3:
Collections.sort(list, new Comparator<HaNoiHouse>() {
@Override
public int compare(HaNoiHouse o1, HaNoiHouse o2) {
if (o1.getDiaChi().equalsIgnoreCase(o2.getDiaChi())) {
return 1;
}
return -1;
}
});
for (int i = 0; i < list.size(); i++) {
list.get(i).display();
}
break;
case 4:
System.out.println("Nhap ten dia chi nha can tim: ");
String diachi = scan.nextLine();
System.out.println("Thong tin ngoi nha can tim la: ");
for (int k = 0; k < list.size(); k++) {
if (list.get(k).getDiaChi().equalsIgnoreCase(diachi)) {
list.get(k).display();
} else {
System.out.println("Khong tim thay thong tin ngoi nha co dia chi: " + diachi);
}
}
break;
case 5:
System.out.println("Thoat.");
break;
default:
System.err.println("Nhap loi !!!");
break;
}
} while (choose != 5);


}

public static void showMenu() {
System.out.println("*==================*");
System.out.println("1. Nhập thông tin n ngôi nhà ở Hà Nội.");
System.out.println("2. Hiển thị thông tin của n ngôi nhà đó.");
System.out.println("3. Sắp xếp theo trường địa chỉ và hiển thị thông tin sau khi sắp xếp.");
System.out.println("4. Tìm kiếm nhà theo địa chỉ nhập vào.");
System.out.println("5. Thoát.");
System.out.println("*==================*");

}

}