By GokiSoft.com| 19:26 13/05/2024|
Java Basic

Java basic- Assignment - Quản lý xe cộ

* Tạo một giao diện IXe nằm trong gói xeco.info gồm có 2 phương thức:

            - public void nhap();

            - public void hienthi();

 

* Tạo Lớp XeMay cũng nằm trong gói xeco.info thực thi giao diện IXe và có các thuộc tính sau:

            String bienso;

            String loaixe;

            String mauxe;

            float giatien;

Cài đặt Constructor, các phương thức set/get và Override các phương thức trong giao diện IXe.

 

* Tạo lớp XeMayHoaBinh nằm trong gói hoabinh.xemay kế thừa lớp IXe. Bổ sung thêm thuộc tính:

            - n (kiểu int)    : Dùng để nhập vào số lượng xe

- Một mảng n phần tử kiểu XeMay dùng để lưu thông tin của n xe máy đang quản lý tại tỉnh Hòa Bình.

Cài đặt constructor, override tất cả các phương thức trong lớp IXe. Phương thức nhập phải nhập vào số lượng xe và gọi nhập thông tin của n xe đó.

 

* Tạo lớp XeMayHaNoi nằm trong gói hanoi.xemay kế thừa lớp XeMay. Bổ sung thêm thuộc tính:

            - n (kiểu int)    : Dùng để nhập vào số lượng xe

- Một mảng n phần tử kiểu XeMay dùng để lưu thông tin của n xe máy đang quản lý tại tỉnh Hà Nội.

Cài đặt constructor, override tất cả các phương thức trong lớp XeMay. Phương thức nhập phải nhập vào số lượng xe và gọi nhập thông tin của n xe đó.

 

* Tạo lớp QuanLyChung nằm trong gói quanlychung.xemay, có menu như sau:

            1. Nhập thông tin cho n xe máy tại tỉnh Hòa Bình.

            2. Nhập thông tin cho n xe máy tại tỉnh Hà Nội.

            3. Sắp xếp danh sách tăng theo biển số xe.

            4. Tìm kiếm thông tin xe theo biển số xe.

            5. Thống kê số lượng xe đang quản lý.

            6. Thoát

 

-          Yêu cầu:

o   Sau khi người sử dụng chọn chức năng 3, 4, 5 sẽ đưa ra thông báo nhập vào tỉnh cần thực hiện (Hòa Bình hoặc Hà Nội).



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

5

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

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

2020-03-14 07:07:04



/*
 * 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 QLXeco;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Main {
    public static void main(String[] args) {
        XeMayHoaBinh xmHB = new XeMayHoaBinh();
        XeMayHaNoi xmHN = new XeMayHaNoi();
        int choose;
        Scanner scanner = new Scanner(System.in);
        do {
            showmenu();
            choose = scanner.nextInt();
            switch (choose) {
                case 1:
                    xmHB.nhap();
                    xmHB.hienthi();
                    break;
                case 2:
                    xmHN.nhap();
                    xmHN.hienthi();
                    break;
                case 3:
                    int index;
                    do {
                        System.out.println("1. Hoa Binh");
                        System.out.println("2. Ha Noi");
                        index = scanner.nextInt();
                        switch (index) {
                            case 1:
                                xmHB.sapxep();
                                xmHB.hienthi();
                                break;
                            case 2:
                                xmHN.sapxep();
                                xmHN.hienthi();
                                break;
                            default:
                                System.err.println("Vui long chon lai : ");
                                break;
                        }
                    } while (index < 1 || index > 2);
                    break;
                case 4:
                    int bienso;
                    do {
                        System.out.println("1. Hoa Binh");
                        System.out.println("2. Ha Noi");
                        bienso = scanner.nextInt();
                        switch (bienso) {
                            case 1:
                                xmHB.timkiem();
                                break;
                            case 2:
                                xmHN.timkiem();
                                break;
                            default:
                                System.err.println("Vui long chon lai : ");
                                break;
                        }
                    } while (bienso < 1 || bienso > 2);
                    break;
                case 5:
                    int soluong;
                    do {
                        System.out.println("1. Hoa Binh");
                        System.out.println("2. Ha Noi");
                        soluong = scanner.nextInt();
                        switch (soluong) {
                            case 1:
                                xmHB.soluongXe();
                                break;
                            case 2:
                                xmHN.soluongXe();
                                break;
                            default:
                                System.err.println("Vui long chon lai : ");
                                break;
                        }
                    } while (soluong < 1 || soluong > 2);
                    break;
                case 6:
                    System.out.println("Thoat thanh cong.");
                    break;
                default:
                    System.out.println("Cu phap sai,Vui long chon lai : ");
                    break;
            }

        } while (choose != 6);
    }

    public static void showmenu() {
        System.out.println("1. Nhap thong tin cho so xe may tai tinh Hoa Binh. ");
        System.out.println("2. Nhap thong tin cho so xe may tai tinh Ha Noi. ");
        System.out.println("3. Sap xep danh sach tang dan theo bien so xe. ");
        System.out.println("4. Tim kiem thong tin xe theo bien so xe. ");
        System.out.println("5. Thong ke so luong xe dang quan ly. ");
        System.out.println("6. Thoat.");
        System.out.println("Choose: ");
    }
}



/*
 * 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 QLXeco;

/**
 *
 * @author Admin
 */
public interface IXe {
    public void nhap();
    public void hienthi();
}



/*
 * 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 QLXeco;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class XeMay implements IXe {
    public String bienso,loaixe, mauxe;
    public float giatien;

    public XeMay() {
    }

    public XeMay(String bienso, String loaixe, String mauxe, float giatien) {
        this.bienso = bienso;
        this.loaixe = loaixe;
        this.mauxe = mauxe;
        this.giatien = giatien;
    }
    
    @Override
    public void nhap(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("Nhap thong tin xe: ");
        System.out.println("Nhap bien so: ");
        bienso = scanner.nextLine();
        System.out.println("Nhap loai xe: ");
        loaixe = scanner.nextLine();
        System.out.println("Nhap mau xe: ");
        mauxe = scanner.nextLine();
        System.out.println("Nhap gia tien: ");
        giatien = Integer.parseInt(scanner.nextLine());
    }
    
    @Override
    public void hienthi(){
        System.out.println(toString());
    }
    
    @Override
    public String toString() {
        return "XeMay{" + "bienso=" + bienso + ", loaixe=" + loaixe + ", mauxe=" + mauxe + ", giatien=" + giatien + '}';
    }

    public String getBienso() {
        return bienso;
    }

    public void setBienso(String bienso) {
        this.bienso = bienso;
    }

    public String getLoaixe() {
        return loaixe;
    }

    public void setLoaixe(String loaixe) {
        this.loaixe = loaixe;
    }

    public String getMauxe() {
        return mauxe;
    }

    public void setMauxe(String mauxe) {
        this.mauxe = mauxe;
    }

    public float getGiatien() {
        return giatien;
    }

    public void setGiatien(float giatien) {
        this.giatien = giatien;
    } 
}



/*
 * 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 QLXeco;

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

/**
 *
 * @author Admin
 */
public class XeMayHaNoi extends XeMay{
    public int n;
    public ArrayList<XeMay> mangXe = new ArrayList<>();

    public XeMayHaNoi() {
    }
     public XeMayHaNoi(String bienso, String loaixe, String mauxe, float giatien) {
        super(bienso, loaixe, mauxe, giatien);
    }
    @Override
    public void hienthi() {
        System.out.println("Danh sach xe may Ha Noi");
        mangXe.forEach((mangXe1) -> {
            mangXe1.hienthi();
        });
    }
    @Override
    public void nhap() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap thong tin cho n xe may o tinh Ha Noi");
        n = Integer.parseInt(sc.nextLine());
        for (int i = 0; i < n; i++) {
            XeMay xm = new XeMay();
            xm.nhap();
            mangXe.add(xm);
        }
    }
     public void sapxep() {
        Collections.sort(mangXe, (XeMay o1, XeMay o2) -> o1.getBienso().compareTo(o2.getBienso()));
    }

    public void soluongXe() {
        System.out.println("So luong xe quan li o Ha Noi:" + mangXe.size());
    }

    public void timkiem() {
        int a = -1;
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap bien so can tim");
        String bienso = sc.nextLine();
        for (int i = 0; i < mangXe.size(); i++) {
            if (mangXe.get(i).getBienso().equalsIgnoreCase(bienso)) {
                a = i;
            }
        }
        if (a != -1) {
            mangXe.get(a).hienthi();
        } else {
            System.out.println("Khong tim thay bien so" + bienso);
        }
    }

    public int getN() {
        return n;
    }

    public void setN(int n) {
        this.n = n;
    }

    public ArrayList<XeMay> getMangXe() {
        return mangXe;
    }

    public void setMangXe(ArrayList<XeMay> mangXe) {
        this.mangXe = mangXe;
    }

}



/*
 * 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 QLXeco;

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

/**
 *
 * @author Admin
 */
public class XeMayHoaBinh extends XeMay {
     private int n;
    private ArrayList<XeMay> mangXe = new ArrayList<>();

    public XeMayHoaBinh() {
    }

    public XeMayHoaBinh(String bienso, String loaixe, String mauxe, float giatien) {
        super(bienso, loaixe, mauxe, giatien);
    }

    @Override
    public void hienthi() {
        System.out.println("Danh sach xe may Hoa Binh");
        for (XeMay mangXe1 : mangXe) {
            mangXe1.hienthi();
        }
    }

    public void timkiem() {
        int a = -1;
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap bien so can tim");
        String bienso = sc.nextLine();
        for (int i = 0; i < mangXe.size(); i++) {
            if (mangXe.get(i).getBienso().equalsIgnoreCase(bienso)) {
                a = i;
            }
        }
        if (a != -1) {
            mangXe.get(a).hienthi();
        } else {
            System.out.println("Khong tim thay bien so" + bienso);
        }
    }

    @Override
    public void nhap() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap thong tin cho n xe may o tinh Hoa Binh");
        n = Integer.parseInt(sc.nextLine());
        for (int i = 0; i < n; i++) {
            XeMay xm = new XeMay();
            xm.nhap();
            mangXe.add(xm);
        }
    }

    public void soluongXe() {
        System.out.println("So luong xe quan li o Hoa Binh:" + mangXe.size());
    }

    public int getN() {
        return n;
    }

    public void setN(int n) {
        this.n = n;
    }

    public ArrayList<XeMay> getMangXe() {
        return mangXe;
    }

    public void setMangXe(ArrayList<XeMay> mangXe) {
        this.mangXe = mangXe;
    }

    public void sapxep() {
        Collections.sort(mangXe, (XeMay o1, XeMay o2) -> o1.getBienso().compareTo(o2.getBienso()));
    }
}



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

2020-03-14 07:00:45

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 Quanlixe;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Main {
    public static void main(String[] args) {
        XeMayHB xmHB = new XeMayHB();
        XeMayHN xmHN = new XeMayHN();
        int choose;
        Scanner scanner = new Scanner(System.in);
        do {
            showmenu();
            choose = scanner.nextInt();
            switch (choose) {
                case 1:
                    xmHB.nhap();
                    xmHB.hienthi();
                    break;
                case 2:
                    xmHN.nhap();
                    xmHN.hienthi();
                    break;
                case 3:
                    int index;
                    do {
                        System.out.println("1.Hoa Binh");
                        System.out.println("2.Ha Noi");
                        index = scanner.nextInt();
                        switch (index) {
                            case 1:
                                xmHB.sapxep();
                                xmHB.hienthi();
                                break;
                            case 2:
                                xmHN.sapxep();
                                xmHN.hienthi();
                                break;
                            default:
                                System.err.println("Chon lai di");
                                break;
                        }
                    } while (index < 1 || index > 2);
                    break;
                case 4:
                    int bienso;
                    do {
                        System.out.println("1.Hoa Binh");
                        System.out.println("2.Ha Noi");
                        bienso = scanner.nextInt();
                        switch (bienso) {
                            case 1:
                                xmHB.timkiem();
                                break;
                            case 2:
                                xmHN.timkiem();
                                break;
                            default:
                                System.err.println("Chon lai di");
                                break;
                        }
                    } while (bienso < 1 || bienso > 2);
                    break;
                case 5:
                    int soluong;
                    do {
                        System.out.println("1.Hoa Binh");
                        System.out.println("2.Ha Noi");
                        soluong = scanner.nextInt();
                        switch (soluong) {
                            case 1:
                                xmHB.soluongXe();
                                break;
                            case 2:
                                xmHN.soluongXe();
                                break;
                            default:
                                System.err.println("Chon lai di");
                                break;
                        }
                    } while (soluong < 1 || soluong > 2);
                    break;
                case 6:
                    System.out.println("Thoat thanh cong");
                    break;
                default:
                    System.out.println("Nhap sai roi ,nhap lai di ban eii");
                    break;
            }

        } while (choose != 6);
    }

    public static void showmenu() {
        System.out.println("1.Nhap thong tin cho so xe may tai tinh Hoa Binh.");
        System.out.println("2. Nhap thong tin cho so xe may tai tinh Ha Noi.");
        System.out.println("3. Sap xep danh sach tang dan theo bien so xe.");
        System.out.println("4. Tim kiem thong tin xe theo bien so xe.");
        System.out.println("5. Thong ke so luong xe dang quan ly.");
        System.out.println("6:Thoat");
        System.out.println("Choose:");
    }
}

IXe:



/*
 * 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 Quanlixe;

/**
 *
 * @author Admin
 */
public interface IXe {
    public void nhap();
    public void hienthi();
}

XeMay:



/*
 * 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 Quanlixe;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class XeMay implements IXe {
    public String bienso,loaixe, mauxe;
    public float giatien;

    public XeMay() {
    }

    public XeMay(String bienso, String loaixe, String mauxe, float giatien) {
        this.bienso = bienso;
        this.loaixe = loaixe;
        this.mauxe = mauxe;
        this.giatien = giatien;
    }
    
    @Override
    public void nhap(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("Nhap thong tin xe: ");
        System.out.println("Nhap bien so: ");
        bienso = scanner.nextLine();
        System.out.println("Nhap loai xe: ");
        loaixe = scanner.nextLine();
        System.out.println("Nhap mau xe: ");
        mauxe = scanner.nextLine();
        System.out.println("Nhap gia tien: ");
        giatien = Integer.parseInt(scanner.nextLine());
    }
    
    @Override
    public void hienthi(){
        System.out.println(toString());
    }
    
    @Override
    public String toString() {
        return "XeMay{" + "bienso=" + bienso + ", loaixe=" + loaixe + ", mauxe=" + mauxe + ", giatien=" + giatien + '}';
    }

    public String getBienso() {
        return bienso;
    }

    public void setBienso(String bienso) {
        this.bienso = bienso;
    }

    public String getLoaixe() {
        return loaixe;
    }

    public void setLoaixe(String loaixe) {
        this.loaixe = loaixe;
    }

    public String getMauxe() {
        return mauxe;
    }

    public void setMauxe(String mauxe) {
        this.mauxe = mauxe;
    }

    public float getGiatien() {
        return giatien;
    }

    public void setGiatien(float giatien) {
        this.giatien = giatien;
    }
    
    

   
    
    
}

XeMayHN:



/*
 * 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 Quanlixe;

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

/**
 *
 * @author Admin
 */
public class XeMayHN extends XeMay{
    public int n;
    public ArrayList<XeMay> mangXe = new ArrayList<>();

    public XeMayHN() {
    }
     public XeMayHN(String bienso, String loaixe, String mauxe, float giatien) {
        super(bienso, loaixe, mauxe, giatien);
    }
    @Override
    public void hienthi() {
        System.out.println("Danh sach xe may Ha Noi");
        mangXe.forEach((mangXe1) -> {
            mangXe1.hienthi();
        });
    }
    @Override
    public void nhap() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap thong tin cho n xe may o tinh Ha Noi");
        n = Integer.parseInt(sc.nextLine());
        for (int i = 0; i < n; i++) {
            XeMay xm = new XeMay();
            xm.nhap();
            mangXe.add(xm);
        }
    }
     public void sapxep() {
        Collections.sort(mangXe, (XeMay o1, XeMay o2) -> o1.getBienso().compareTo(o2.getBienso()));
    }

    public void soluongXe() {
        System.out.println("So luong xe quan li o Ha Noi:" + mangXe.size());
    }

    public void timkiem() {
        int a = -1;
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap bien so can tim");
        String bienso = sc.nextLine();
        for (int i = 0; i < mangXe.size(); i++) {
            if (mangXe.get(i).getBienso().equalsIgnoreCase(bienso)) {
                a = i;
            }
        }
        if (a != -1) {
            mangXe.get(a).hienthi();
        } else {
            System.out.println("Khong tim thay xe co bien so: " + bienso);
        }
    }

    public int getN() {
        return n;
    }

    public void setN(int n) {
        this.n = n;
    }

    public ArrayList<XeMay> getMangXe() {
        return mangXe;
    }

    public void setMangXe(ArrayList<XeMay> mangXe) {
        this.mangXe = mangXe;
    }

}

XeMayHB:



/*
 * 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 Quanlixe;

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

/**
 *
 * @author Admin
 */
public class XeMayHB extends XeMay {
     private int n;
    private ArrayList<XeMay> mangXe = new ArrayList<>();

    public XeMayHB() {
    }

    public XeMayHB(String bienso, String loaixe, String mauxe, float giatien) {
        super(bienso, loaixe, mauxe, giatien);
    }

    @Override
    public void hienthi() {
        System.out.println("Danh sach xe may Hoa Binh");
        for (XeMay mangXe1 : mangXe) {
            mangXe1.hienthi();
        }
    }

    public void timkiem() {
        int a = -1;
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap bien so can tim");
        String bienso = sc.nextLine();
        for (int i = 0; i < mangXe.size(); i++) {
            if (mangXe.get(i).getBienso().equalsIgnoreCase(bienso)) {
                a = i;
            }
        }
        if (a != -1) {
            mangXe.get(a).hienthi();
        } else {
            System.out.println("Khong tim thay xe co bien so: " + bienso);
        }
    }

    @Override
    public void nhap() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap thong tin cho n xe may o tinh Hoa Binh");
        n = Integer.parseInt(sc.nextLine());
        for (int i = 0; i < n; i++) {
            XeMay xm = new XeMay();
            xm.nhap();
            mangXe.add(xm);
        }
    }

    public void soluongXe() {
        System.out.println("So luong xe quan li o Hoa Binh:" + mangXe.size());
    }

    public int getN() {
        return n;
    }

    public void setN(int n) {
        this.n = n;
    }

    public ArrayList<XeMay> getMangXe() {
        return mangXe;
    }

    public void setMangXe(ArrayList<XeMay> mangXe) {
        this.mangXe = mangXe;
    }

    public void sapxep() {
        Collections.sort(mangXe, (XeMay o1, XeMay o2) -> o1.getBienso().compareTo(o2.getBienso()));
    }
}



thienphu [T1907A]
thienphu

2020-03-14 02:12: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 QuanLiXeCo2;

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

    void nhap();

    void hienthi();
}



/*
 * 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 QuanLiXeCo2;

import java.util.Scanner;

/**
 *
 * @author Thien Phu
 */
public class XeMay implements IXe {

    private String bienso, loaixe, mauxe;
    private float giatien;

    public XeMay() {
    }

    public XeMay(String bienso, String loaixe, String mauxe, float giatien) {
        this.bienso = bienso;
        this.loaixe = loaixe;
        this.mauxe = mauxe;
        this.giatien = giatien;
    }

    @Override
    public void nhap() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap thong tin xe");
        System.out.println("Nhap bien so: ");
        bienso = sc.nextLine();
        System.out.println("Nhap loai xe");
        loaixe = sc.nextLine();
        System.out.println("Nhap mau xe");
        mauxe = sc.nextLine();
        System.out.println("Nhap gia tien");
        giatien = Integer.parseInt(sc.nextLine());
    }

    @Override
    public void hienthi() {
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "XeMay{" + "bienso=" + bienso + ", loaixe=" + loaixe + ", mauxe=" + mauxe + ", giatien=" + giatien + '}';
    }

    public String getBienso() {
        return bienso;
    }

    public void setBienso(String bienso) {
        this.bienso = bienso;
    }

    public String getLoaixe() {
        return loaixe;
    }

    public void setLoaixe(String loaixe) {
        this.loaixe = loaixe;
    }

    public String getMauxe() {
        return mauxe;
    }

    public void setMauxe(String mauxe) {
        this.mauxe = mauxe;
    }

    public float getGiatien() {
        return giatien;
    }

    public void setGiatien(float giatien) {
        this.giatien = giatien;
    }
}



/*
 * 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 QuanLiXeCo2;

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

/**
 *
 * @author Thien Phu
 */
public class XeMayHN extends XeMay {

    private int n;
    private ArrayList<XeMay> mangXe = new ArrayList<>();

    public XeMayHN() {
    }

    public XeMayHN(String bienso, String loaixe, String mauxe, float giatien) {
        super(bienso, loaixe, mauxe, giatien);
    }

    @Override
    public void hienthi() {
        System.out.println("Danh sach xe may Ha Noi");
        for (XeMay mangXe1 : mangXe) {
            mangXe1.hienthi();
        }
    }

    @Override
    public void nhap() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap thong tin cho n xe may o tinh Ha Noi");
        n = Integer.parseInt(sc.nextLine());
        for (int i = 0; i < n; i++) {
            XeMay xm = new XeMay();
            xm.nhap();
            mangXe.add(xm);
        }
    }

    public void sapxep() {
        Collections.sort(mangXe, new Comparator<XeMay>() {

            @Override
            public int compare(XeMay o1, XeMay o2) {
                return o1.getBienso().compareTo(o2.getBienso());
            }
        });
    }

    public void soluongXe() {
        System.out.println("So luong xe quan li o Ha Noi:" + mangXe.size());
    }

    public void timkiem() {
        int a = -1;
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap bien so can tim");
        String bienso = sc.nextLine();
        for (int i = 0; i < mangXe.size(); i++) {
            if (mangXe.get(i).getBienso().equalsIgnoreCase(bienso)) {
                a = i;
            }
        }
        if (a != -1) {
            mangXe.get(a).hienthi();
        } else {
            System.out.println("Khong tim thay xe co bien so: " + bienso);
        }
    }

    public int getN() {
        return n;
    }

    public void setN(int n) {
        this.n = n;
    }

    public ArrayList<XeMay> getMangXe() {
        return mangXe;
    }

    public void setMangXe(ArrayList<XeMay> mangXe) {
        this.mangXe = mangXe;
    }

}



package QuanLiXeCo2;

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

/**
 *
 * @author Thien Phu
 */
public class XeMayHoaBInh extends XeMay {

    private int n;
    private ArrayList<XeMay> mangXe = new ArrayList<>();

    public XeMayHoaBInh() {
    }

    public XeMayHoaBInh(String bienso, String loaixe, String mauxe, float giatien) {
        super(bienso, loaixe, mauxe, giatien);
    }

    @Override
    public void hienthi() {
        System.out.println("Danh sach xe may Hoa Binh");
        for (XeMay mangXe1 : mangXe) {
            mangXe1.hienthi();
        }
    }

    public void timkiem() {
        int a = -1;
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap bien so can tim");
        String bienso = sc.nextLine();
        for (int i = 0; i < mangXe.size(); i++) {
            if (mangXe.get(i).getBienso().equalsIgnoreCase(bienso)) {
                a = i;
            }
        }
        if (a != -1) {
            mangXe.get(a).hienthi();
        } else {
            System.out.println("Khong tim thay xe co bien so: " + bienso);
        }
    }

    @Override
    public void nhap() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap thong tin cho n xe may o tinh Hoa Binh");
        n = Integer.parseInt(sc.nextLine());
        for (int i = 0; i < n; i++) {
            XeMay xm = new XeMay();
            xm.nhap();
            mangXe.add(xm);
        }
    }

    public void soluongXe() {
        System.out.println("So luong xe quan li o Hoa Binh:" + mangXe.size());
    }

    public int getN() {
        return n;
    }

    public void setN(int n) {
        this.n = n;
    }

    public ArrayList<XeMay> getMangXe() {
        return mangXe;
    }

    public void setMangXe(ArrayList<XeMay> mangXe) {
        this.mangXe = mangXe;
    }

    public void sapxep() {
        Collections.sort(mangXe, new Comparator<XeMay>() {

            @Override
            public int compare(XeMay o1, XeMay o2) {
                return o1.getBienso().compareTo(o2.getBienso());
            }
        });
    }
}



/*
 * 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 QuanLiXeCo2;

import java.util.Scanner;

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

    public static void main(String[] args) {
        XeMayHoaBInh xmHB = new XeMayHoaBInh();
        XeMayHN xmHN = new XeMayHN();
        int choose;
        Scanner sc = new Scanner(System.in);
        do {
            showmenu();
            choose = sc.nextInt();
            switch (choose) {
                case 1:
                    xmHB.nhap();
                    xmHB.hienthi();
                    break;
                case 2:
                    xmHN.nhap();
                    xmHN.hienthi();
                    break;
                case 3:
                    int index;
                    do {
                        System.out.println("1.HoaBinh");
                        System.out.println("2.HaNoi");
                        index = sc.nextInt();
                        switch (index) {
                            case 1:
                                xmHB.sapxep();
                                xmHB.hienthi();
                                break;
                            case 2:
                                xmHN.sapxep();
                                xmHN.hienthi();
                                break;
                            default:
                                System.err.println("Chon lai di");
                                break;
                        }
                    } while (index < 1 || index > 2);
                    break;
                case 4:
                    int bienso;
                    do {
                        System.out.println("1.HoaBinh");
                        System.out.println("2.HaNoi");
                        bienso = sc.nextInt();
                        switch (bienso) {
                            case 1:
                                xmHB.timkiem();
                                break;
                            case 2:
                                xmHN.timkiem();
                                break;
                            default:
                                System.err.println("Chon lai di");
                                break;
                        }
                    } while (bienso < 1 || bienso > 2);
                    break;
                case 5:
                    int soluong;
                    do {
                        System.out.println("1.HoaBinh");
                        System.out.println("2.HaNoi");
                        soluong = sc.nextInt();
                        switch (soluong) {
                            case 1:
                                xmHB.soluongXe();
                                break;
                            case 2:
                                xmHN.soluongXe();
                                break;
                            default:
                                System.err.println("Chon lai di");
                                break;
                        }
                    } while (soluong < 1 || soluong > 2);
                    break;
                case 6:
                    System.out.println("Thoat thanh cong");
                    break;
                default:
                    System.out.println("Nhap lai di");
                    break;
            }

        } while (choose != 6);
    }

    public static void showmenu() {
        System.out.println("1. Nhập thông tin cho n xe máy tại tỉnh Hòa Bình.");
        System.out.println("2. Nhập thông tin cho n xe máy tại tỉnh Hà Nội.");
        System.out.println("3. Sắp xếp danh sách tăng theo biển số xe.");
        System.out.println("4. Tìm kiếm thông tin xe theo biển số xe.");
        System.out.println("5. Thống kê số lượng xe đang quản lý.");
        System.out.println("6:Thoat");
        System.out.println("Choose:");
    }
}



Luong Dinh Dai [T1907A]
Luong Dinh Dai

2020-03-13 15:30:46



/*
 * 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 xe.info;

import java.util.Scanner;

/**
 *
 * @author FATE STORE
 */
public class XeMay implements IXe{
    String bienso;
    String loaixe;
    String mauxe;
    float giatien;

    public XeMay() {
    }

    public XeMay(String bienso, String loaixe, String mauxe, float giatien) {
        this.bienso = bienso;
        this.loaixe = loaixe;
        this.mauxe = mauxe;
        this.giatien = giatien;
    }

    public String getBienso() {
        return bienso;
    }

    public void setBienso(String bienso) {
        this.bienso = bienso;
    }

    public String getLoaixe() {
        return loaixe;
    }

    public void setLoaixe(String loaixe) {
        this.loaixe = loaixe;
    }

    public String getMauxe() {
        return mauxe;
    }

    public void setMauxe(String mauxe) {
        this.mauxe = mauxe;
    }

    public float getGiatien() {
        return giatien;
    }

    public void setGiatien(float giatien) {
        this.giatien = giatien;
    }

    @Override
    public String toString() {
        return "XeMay{" + "bienso=" + bienso + ", loaixe=" + loaixe + ", mauxe=" + mauxe + ", giatien=" + giatien + '}';
    }

    
    @Override
    public void nhap() {
        Scanner sc = new Scanner(System.in);
        System.out.println("nhap bien so: ");
        bienso = sc.nextLine();
        System.out.println("nhap loai xe: ");
        loaixe = sc.nextLine();
        System.out.println("nhap mau xe: ");
        mauxe = sc.nextLine();
        System.out.println("nhap gia tien: ");
        giatien = sc.nextFloat();
    }

    
    @Override
    public void hienthi() {
        System.out.print(toString());
        System.out.println("");
    }
    
}



/*
 * 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 xe.info;

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

/**
 *
 * @author FATE STORE
 */
public class XeMayHaNoi extends XeMay{
    int n;
    ArrayList<XeMay> lstxehn = new ArrayList<>();
    public XeMayHaNoi() {
    }

    public XeMayHaNoi(int n, String bienso, String loaixe, String mauxe, float giatien) {
        super(bienso, loaixe, mauxe, giatien);
        this.n = n;
    }

    @Override
    public void hienthi() {
        for(XeMay xemay: lstxehn){
            xemay.hienthi();
        }
    }

   

    @Override
    public void nhap() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap so luong xe: ");
        n = sc.nextInt();
        System.out.println("Nhap Thong tin xe ");
        for (int i = 1; i <= n; i++) {
            System.out.printf("thong tin xe may thu %d ", i);
            System.out.println("");
            XeMay xemay = new XeMay();
            xemay.nhap();
            lstxehn.add(xemay);
        }
    }
   public void sapxep() {
        Collections.sort(lstxehn, new Comparator<XeMay>() {
            @Override
            public int compare(XeMay xeMay, XeMay t1) {
                if (xeMay.getBienso().equalsIgnoreCase(t1.getBienso())) {
                    return 1;
                }
                return -1;
            }
        });
        hienthi();
    }
   public XeMay Timkiem(String bienso){
       for(XeMay xe: lstxehn){
           if(xe.getBienso().equalsIgnoreCase(bienso))
           {
               return xe;
           }
       }
       return null;
   }
}



/*
 * 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 xe.info;

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

/**
 *
 * @author FATE STORE
 */
public class XeMayHoaBinh extends XeMay {

    int n;
    ArrayList<XeMay> lstxehb = new ArrayList<>();

    public XeMayHoaBinh() {
    }

    public XeMayHoaBinh(int n, String bienso, String loaixe, String mauxe, float giatien) {
        super(bienso, loaixe, mauxe, giatien);
        this.n = n;
    }

    @Override
    public void hienthi() {
        for (XeMay xemay : lstxehb) {
            xemay.hienthi();
        }
    }

    @Override
    public void nhap() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap so luong xe: ");
        n = sc.nextInt();
        System.out.println("Nhap Thong tin xe ");
        for (int i = 1; i <= n; i++) {
            System.out.printf("thong tin xe may thu %d ", i);
            System.out.println("");
            XeMay xemay = new XeMay();
            xemay.nhap();
            lstxehb.add(xemay);
        }

    }

    public void sapxep() {
        Collections.sort(lstxehb, new Comparator<XeMay>() {
            @Override
            public int compare(XeMay xeMay, XeMay t1) {
                if (xeMay.getBienso().equalsIgnoreCase(t1.getBienso())) {
                    return 1;
                }
                return -1;
            }
        });
        hienthi();
    }

    public XeMay Timkiem(String bienso) {
        for (XeMay xe : lstxehb) {
            if (xe.getBienso().equalsIgnoreCase(bienso)) {
                return xe;
            }
        }
        return null;
    }

}



/*
 * 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 xe.info;

import java.util.Scanner;
import java01.Main;

/**
 *
 * @author FATE STORE
 */
public class QuanLyChung {
    public static void main(String[] args) {
        XeMayHoaBinh xehb = new XeMayHoaBinh();
        XeMayHaNoi xehn = new XeMayHaNoi();
        QuanLyChung mn = new QuanLyChung();
        int sw;
        do{
            mn.menu();
            Scanner sc = new Scanner(System.in);
            sw = sc.nextInt();
            sc.nextLine();
            switch(sw){
                case 1:{
                    xehb.nhap();
                    break;
                }
                case 2:{
                    xehn.nhap();
                    break;
                }
                case 3:{
                    System.out.print("=========================================
1: Hoa Binh: 
2: Ha Noi:
3: Thoat: 
 --- Lua Chon: ");
                    sw = sc.nextInt();
                    switch(sw){
                        case 1:{
                            xehb.sapxep();
                            break;
                        }
                        case 2:{
                            xehn.sapxep();
                        }
                        default:
                            break;
                    }
                    break;
                }
                case 4: {
                    System.out.print("=========================================
1: Hoa Binh: 
2: Ha Noi:
3: Thoat: 
 --- Lua Chon: ");
                    sw = sc.nextInt();
                    sc.nextLine();
                    switch (sw) {
                        case 1: {
                            System.out.println("bien so xe: ");
                            String bienso = sc.nextLine();
                            XeMay xemayhb = xehb.Timkiem(bienso);
                            System.out.println("XeMay{" + "bienso=" + xemayhb.getBienso() + ", loaixe=" + xemayhb.getLoaixe() + ", mauxe=" + xemayhb.getMauxe() + ", giatien=" + xemayhb.getGiatien() + '}');
                            break;
                        }
                        case 2: {
                            System.out.println("bien so xe: ");
                            String bienso = sc.nextLine();
                            XeMay xemayhn = xehn.Timkiem(bienso);
                            System.out.println("XeMay{" + "bienso=" + xemayhn.getBienso() + ", loaixe=" + xemayhn.getLoaixe() + ", mauxe=" + xemayhn.getMauxe() + ", giatien=" + xemayhn.getGiatien() + '}');
                            break;
                        }
                        default:
                            break;

                    }
                    break;
                }
                case 5:
                    System.out.print("=========================================
1: Hoa Binh: 
2: Ha Noi:
3: Thoat: 
 --- Lua Chon: ");
                    sw = sc.nextInt();
                    sc.nextLine();
                    switch(sw){
                        case 1:{
                            System.out.println("So luong xe dang quan ly: "+ xehb.lstxehb.size());
                            break;
                        }
                        case 2:{
                            System.out.println("So luong xe dang quan ly: "+ xehn.lstxehn.size());
                            break;
                        }
                        default:
                            break;
                    }
                    break;
            }
        } while (sw != 6);
    }
    public void menu(){
        System.out.print("=========================================
1: Nhap Thong Tin Cho N Xe May Tai Tinh Hoa Binh: 
2: Nhap Thong Tin Cho N Xe May Tai Tinh Ha Noi:
3: Sap Xep Danh Sach Tang Theo Bien So Xe: 
4: Tim Kiem Thong Tin Theo Bien So Xe: 
5: Thong Ke Luong Xe Dang Quan Ly: 
6: Thoat: 
 --- Lua Chon: ");
    }
}



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

2020-03-13 10:54:01



/*
 * 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 quanlychung.xemay;

import hoabinh.xemay.XeMayHoaBinh;
import hanoi.xemay.XeMayHaNoi;
import java.util.Scanner;

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

    public static void main(String[] args) {
        XeMayHoaBinh xeHB = new XeMayHoaBinh();
        XeMayHaNoi xeHN = new XeMayHaNoi();
        Scanner scan = new Scanner(System.in);
        int c;
        String dp;
        do{
            menu();
            c= Integer.parseInt(scan.nextLine());
            switch(c){
                case 1:
                    xeHB.nhap();
                    break;
                case 2:
                    xeHN.nhap();
                    break;
                case 3:
                    System.out.println("1.Ha Noi");
                    System.out.println("2.Hoa Binh");
                    System.out.println("Chon : ");
                    c= Integer.parseInt(scan.nextLine());
                    switch(c){
                        case 1:
                            xeHN.sort();
                            break;
                        case 2:
                            xeHB.sort();
                            break;
                        default :
                            break;
                    }
                    break;
                case 4:
                    System.out.println("1.Ha Noi");
                    System.out.println("2.Hoa Binh");
                    System.out.println("Chon : ");
                    c= Integer.parseInt(scan.nextLine());
                    switch(c){
                        case 1:
                            xeHN.search();
                            break;
                        case 2:
                            xeHB.search();
                            break;
                        default :
                            break;
                    }
                    break;
                case 5:
                    System.out.println("1.Ha Noi");
                    System.out.println("2.Hoa Binh");
                    System.out.println("Chon : ");
                    c= Integer.parseInt(scan.nextLine());
                    switch(c){
                        case 1:
                            xeHN.thongkeSL();
                            break;
                        case 2:
                            xeHB.thongkeSL();
                            break;
                        default :
                            break;
                    }
                    break;
                case 6:
                    System.out.println("End !!");
                    break;
                default :
                    
                    break;
                
            }
        }while(c !=6);
    }

    public static void menu() {
          System.out.println("1. Nhập thông tin cho n xe máy tại tỉnh Hòa Bình.");
          System.out.println(" 2. Nhập thông tin cho n xe máy tại tỉnh Hà Nội.");
          System.out.println("3. Sắp xếp danh sách tăng theo biển số xe.");
          System.out.println("4. Tìm kiếm thông tin xe theo biển số xe.");
          System.out.println("  5. Thống kê số lượng xe đang quản lý. ");
          System.out.println("6. Thoát");
          System.out.print("\nChon : ");
    }
}



/*
 * 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 hoabinh.xemay;

import java.util.Scanner;
import xeco.info.XeMay;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
/**
 *
 * @author DELL
 */
public class XeMayHoaBinh extends XeMay {

    int n;
    Scanner scan = new Scanner(System.in);
    ArrayList<XeMay> listXe = new ArrayList<>();

    public XeMayHoaBinh() {
    }

    public XeMayHoaBinh(int n, String bienso, String loaixe, String mauxe, float giatien) {
        super(bienso, loaixe, mauxe, giatien);
        this.n = n;
    }
    
    
    
    @Override
    public void nhap(){
        System.out.println("Nhap so xe may can quan ly (Hoa Binh) : ");
        n=Integer.parseInt(scan.nextLine());
        for (int i = 0; i < n; i++) {
            XeMay xemay = new XeMay();
            xemay.nhap();
            listXe.add(xemay);
          
        }
    }
    @Override
    public void hienthi(){
        System.out.println("Danh sach xe may tai Hoa Binh : \n");
        for (int i = 0; i < listXe.size(); i++) {
            listXe.get(i).hienthi();
        }
    }
    public void sort(){
        Collections.sort(listXe, new Comparator<XeMay>() {
            @Override
            public int compare(XeMay o1, XeMay o2) {
                if(o2.getBienso().equalsIgnoreCase(o2.getBienso())){
                    return 1;
                }return -1;
            }
            
        });
        hienthi();
    }
    public void thongkeSL(){
        System.out.println("So luong xe quan ly tai Hoa Binh : "+listXe.size());
    }
    public void search(){
        String bsx ;
        bsx = scan.nextLine();
        for (int i = 0; i < listXe.size(); i++) {
            if (listXe.get(i).getBienso().equalsIgnoreCase(bsx)) {
                listXe.get(i).hienthi();
            }
        }
    }
}



/*
 * 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 hanoi.xemay;
import java.util.Scanner;
import xeco.info.XeMay;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
/**
 *
 * @author DELL
 */
public class XeMayHaNoi extends XeMay{
    int n;
    Scanner scan = new Scanner(System.in);
    ArrayList<XeMay> listXe = new ArrayList<>();

    public XeMayHaNoi(int n, String bienso, String loaixe, String mauxe, float giatien) {
        super(bienso, loaixe, mauxe, giatien);
        this.n = n;
    }

    public XeMayHaNoi() {
    }
    
    
    
    @Override
    public void nhap(){
        System.out.println("Nhap so xe may can quan ly (Ha Noi) : ");
        n=Integer.parseInt(scan.nextLine());
        for (int i = 0; i < n; i++) {
            XeMay xemay = new XeMay();
            xemay.nhap();
            listXe.add(xemay);
          
        }
    }
    @Override
    public void hienthi(){
        System.out.println("Danh sach xe may tai Ha Noi : \n");
        for (int i = 0; i < listXe.size(); i++) {
            listXe.get(i).hienthi();
        }
    }
    public void sort(){
        Collections.sort(listXe, new Comparator<XeMay>() {
            @Override
            public int compare(XeMay o1, XeMay o2) {
                if(o2.getBienso().equalsIgnoreCase(o2.getBienso())){
                    return 1;
                }return -1;
            }
            
            
        });
        hienthi();
    }
    
    public void thongkeSL(){
        System.out.println("So luong xe quan ly tai Ha  : "+listXe.size());
    }
    public void search(){
        String bsx ;
        bsx = scan.nextLine();
        for (int i = 0; i < listXe.size(); i++) {
            if (listXe.get(i).getBienso().equalsIgnoreCase(bsx)) {
                listXe.get(i).hienthi();
            }
        }
    }
}



/*
 * 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 xeco.info;

import java.util.Scanner;

/**
 *
 * @author DELL
 */
public class XeMay implements IXe {

    String bienso;

    String loaixe;

    String mauxe;

    float giatien;

    public XeMay() {
    }

    public XeMay(String bienso, String loaixe, String mauxe, float giatien) {
        this.bienso = bienso;
        this.loaixe = loaixe;
        this.mauxe = mauxe;
        this.giatien = giatien;
    }

    public String getBienso() {
        return bienso;
    }

    public void setBienso(String bienso) {
        this.bienso = bienso;
    }

    public String getLoaixe() {
        return loaixe;
    }

    public void setLoaixe(String loaixe) {
        this.loaixe = loaixe;
    }

    public String getMauxe() {
        return mauxe;
    }

    public void setMauxe(String mauxe) {
        this.mauxe = mauxe;
    }

    public float getGiatien() {
        return giatien;
    }

    public void setGiatien(float giatien) {
        this.giatien = giatien;
    }

    @Override
    public void nhap() {
        Scanner scan = new Scanner(System.in);
        System.out.println("Bien so : ");
        bienso = scan.nextLine();
        
        System.out.println("Loai xe : ");
        loaixe = scan.nextLine();

        System.out.println("Mau xe : ");
        mauxe = scan.nextLine();

        System.out.println("Gia tien : ");
        giatien = Float.parseFloat(scan.nextLine());

    }

    @Override
    public void hienthi() {
          toString();
    }

    @Override
    public String toString() {
        return "XeMay{" + "bienso=" + bienso + ", loaixe=" + loaixe + ", mauxe=" + mauxe + ", giatien=" + giatien + '}';
    }
    
}



/*
 * 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 xeco.info;

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

    public void nhap();

    public void hienthi();
    
}



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

2020-03-11 15:15:52


package ASSIGNMENT.assignment2.xeco.info;

public interface IXe {
public void nhap();
public void hienthi();
}
package ASSIGNMENT.assignment2.xeco.info;

import java.util.Scanner;

public class XeMay implements IXe {

String bienso;
String loaixe;
String mauxe;
float giatien;

public XeMay() {
}

public XeMay(String bienso, String loaixe, String mauxe, float giatien) {
this.bienso = bienso;
this.loaixe = loaixe;
this.mauxe = mauxe;
this.giatien = giatien;
}

public String getBienso() {
return bienso;
}

public void setBienso(String bienso) {
this.bienso = bienso;
}

public String getLoaixe() {
return loaixe;
}

public void setLoaixe(String loaixe) {
this.loaixe = loaixe;
}

public String getMauxe() {
return mauxe;
}

public void setMauxe(String mauxe) {
this.mauxe = mauxe;
}

public float getGiatien() {
return giatien;
}

public void setGiatien(float giatien) {
this.giatien = giatien;
}

@Override
public void nhap() {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap bien so: ");
bienso = scan.nextLine();
System.out.println("Nhap loai xe: ");
loaixe = scan.nextLine();
System.out.println("Nhap mau xe: ");
mauxe = scan.nextLine();
System.out.println("Nhap gia tien");
giatien = Float.parseFloat(scan.nextLine());
System.out.println("");
}

@Override
public void hienthi() {
System.out.println("Bien so la:" + bienso);
System.out.println("Loai xe la:" + loaixe);
System.out.println("Mau xe la:" + mauxe);
System.out.println("Gia tien la:" + giatien);
System.out.println("");
}
}
package ASSIGNMENT.assignment2.xemay.hanoi;
import ASSIGNMENT.assignment2.xeco.info.XeMay;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
public class XeMayHaNoi extends XeMay {
Scanner scan = new Scanner(System.in);
int n;
ArrayList<XeMay> list = new ArrayList<>();

public XeMayHaNoi() {
}

public XeMayHaNoi(String bienso, String loaixe, String mauxe, float giatien, Scanner scan, int n, ArrayList<XeMay> list) {
super(bienso, loaixe, mauxe, giatien);
this.scan = scan;
this.n = n;
this.list = list;
}

@Override
public void nhap() {
System.out.print("Nhap so xe: ");
n = Integer.parseInt(scan.nextLine());
for (int i = 0; i < n; i++) {
XeMay xm = new XeMay();
System.out.println("Nhap thong tin xe thu " + (i + 1) + " :");
xm.nhap();
list.add(xm);
}
}

@Override
public void hienthi() {
for (int j = 0; j < list.size(); j++) {
System.out.println("xe thu: "+(j+1));
list.get(j).hienthi();
}
}

public void sapxep() {
Collections.sort(list, new Comparator<XeMay>() {
@Override
public int compare(XeMay xeMay, XeMay t1) {
if (xeMay.getBienso().equalsIgnoreCase(t1.getBienso())) {
return -1;
}
return 1;
}
});
hienthi();
}

public void timkiem(){
System.out.println("Nhap bien so xe can tim: ");
String biensoxe=scan.nextLine();
for (int k = 0 ; k<list.size();k++){
if (list.get(k).getBienso().equalsIgnoreCase(biensoxe)){
list.get(k).hienthi();
}
System.out.println("Khong tim thay xe co bien so "+biensoxe);
}
}

public void thongKe(){
System.out.println("Thong ke thong tin cac xe dang quan ly tai Ha Noi: ");
hienthi();
}
}
package ASSIGNMENT.assignment2.xemay.hoabinh;

import ASSIGNMENT.assignment2.xeco.info.XeMay;


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

public class XeMayHoaBinh extends XeMay {
Scanner scan = new Scanner(System.in);
int n;

ArrayList<XeMay> list = new ArrayList<>();

public XeMayHoaBinh() {
}

public XeMayHoaBinh(String bienso, String loaixe, String mauxe, float giatien, Scanner scan, int n, ArrayList<XeMay> list) {
super(bienso, loaixe, mauxe, giatien);
this.scan = scan;
this.n = n;
this.list = list;
}

@Override
public void nhap() {
System.out.print("Nhap so xe: ");
n = Integer.parseInt(scan.nextLine());
for (int i = 0; i < n; i++) {
XeMay xm = new XeMay();
System.out.println("Nhap thong tin xe thu " + (i + 1) + " :");
xm.nhap();
list.add(xm);
}
}

@Override
public void hienthi() {
for (int j = 0; j < list.size(); j++) {
System.out.println("xe thu: "+(j+1));
list.get(j).hienthi();
}
}

public void sapxep() {
Collections.sort(list, new Comparator<XeMay>() {
@Override
public int compare(XeMay xeMay, XeMay t1) {
if (xeMay.getBienso().equalsIgnoreCase(t1.getBienso())) {
return -1;
}
return 1;
}
});
hienthi();
}

public void timkiem(){
System.out.println("Nhap bien so xe can tim: ");
String biensoxe=scan.nextLine();
for (int k = 0 ; k<list.size();k++){
if (list.get(k).getBienso().equalsIgnoreCase(biensoxe)){
list.get(k).hienthi();
}
System.out.println("Khong tim thay xe co bien so "+biensoxe);
}
}

public void thongKe(){
System.out.println("Thong ke thong tin cac xe dang quan ly tai Hoa Binh: ");
hienthi();
}
}
package ASSIGNMENT.assignment2.xemay.QuanLyChung;
import ASSIGNMENT.assignment2.xemay.hanoi.XeMayHaNoi;
import ASSIGNMENT.assignment2.xemay.hoabinh.XeMayHoaBinh;
import java.util.Scanner;
public class QuanLyChung {
public static void main(String[] args) {
XeMayHoaBinh xmhb = new XeMayHoaBinh();
XeMayHaNoi xmhn = new XeMayHaNoi();
Scanner scan = new Scanner(System.in);
int choose;
do {
showMenu();
System.out.print(" Nhap lua chon :");
choose = Integer.parseInt(scan.nextLine());
switch (choose) {
case 1:
xmhb.nhap();
break;
case 2:
xmhn.nhap();
break;
case 3:
System.out.println("1.Ha Noi");
System.out.println("2.Hoa Binh");
System.out.print(" Nhap lua chon :");
choose = Integer.parseInt(scan.nextLine());
switch (choose) {
case 1:
xmhn.sapxep();
break;
case 2:
xmhb.sapxep();
break;
default:
break;
}
break;
case 4:
System.out.println("1.Ha Noi");
System.out.println("2.Hoa Binh");
System.out.print(" Nhap lua chon :");
choose = Integer.parseInt(scan.nextLine());
switch (choose) {
case 1:
xmhn.timkiem();
break;
case 2:
xmhb.timkiem();
break;
default:
break;
}
break;
case 5:
System.out.println("1.Ha Noi");
System.out.println("2.Hoa Binh");
System.out.print(" Nhap lua chon :");
choose = Integer.parseInt(scan.nextLine());
switch (choose) {
case 1:
xmhn.thongKe();
break;
case 2:
xmhb.thongKe();
break;
default:
break;
}
break;
case 6:
System.out.println("Thoat..");
break;
default:
System.err.println("Nhap sai !!!");
break;
}
} while (choose != 6);
}

public static void showMenu() {
System.out.println("*================*");
System.out.println("1. Nhập thông tin cho n xe máy tại tỉnh Hòa Bình.");
System.out.println("2. Nhập thông tin cho n xe máy tại tỉnh Hà Nội.");
System.out.println("3. Sắp xếp danh sách tăng theo biển số xe.");
System.out.println("4. Tìm kiếm thông tin xe theo biển số xe.");
System.out.println("5. Thống kê số lượng xe đang quản lý. ");
System.out.println("6. Thoát");
System.out.println("*================*");

}
}



Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó