By GokiSoft.com| 14:01 03/07/2023|
Java Basic

Examination & Test >> Quản lý xe trên các địa bạn + java basic BT1139

Cậu 1: (8 điểm)

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

            - 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: (1.5 điểm)

            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 từ interface IXe. Gồm các thuộc tính sau: (1 điểm)

            - 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 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 XeMayHaNoi nằm trong gói hanoi.xemay kế thừa từ interface IXe. Gồm các thuộc tính sau. (1 điểm)

            - 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. (0.5 điểm)

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

            3. Sắp xếp danh sách tăng theo biển số xe. (1 điểm)

            4. Tìm kiếm thông tin xe theo biển số xe. (1 điểm)

            5. Thống kê số lượng xe đang quản lý. (0.5 điểm)

            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).

Câu 2: (2 điểm)

Nhập từ bàn phím 2 chuỗi s1 và s2.

Yêu cầu tìm kiếm số lần xuất hiện của chuỗi s2 trong chuỗi s1 và hiển thị vị trí xuất hiện của s2 trong s1

Ví du:

s1 = "Sinh vien aptech abc abc aptech okok aptech xin chao"

s2 = "aptech"

Kết quả in ra là:

Số lần xuất hiện: 3

Các vị trí xuất hiện lần lượt là: 10, 25, 37

Liên kết rút gọn:

https://gokisoft.com/1139

Bình luận

avatar
GokiSoft.com [Teacher]
2021-08-05 13:46:13


#XeMayHoaBinh.java


/*
 * 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 lesson13.bt1139;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class XeMayHoaBinh implements IXe{
    int n;
    XeMay[] xemayList;

    public XeMayHoaBinh() {
    }

    public int getN() {
        return n;
    }

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

    public XeMay[] getXemayList() {
        return xemayList;
    }

    public void setXemayList(XeMay[] xemayList) {
        this.xemayList = xemayList;
    }
    
    @Override
    public void nhap() {
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap so xe may can quan ly tai tinh Hoa Binh: ");
        n = Integer.parseInt(scan.nextLine());
        
        xemayList = new XeMay[n];
        
        for (int i = 0; i < n; i++) {
            xemayList[i] = new XeMay();
            xemayList[i].nhap();
        }
    }

    @Override
    public void hienthi() {
        System.out.println("Hien thi danh sach xe may tai tinh Hoa Binh: ");
        
        for (int i = 0; i < n; i++) {
            xemayList[i].hienthi();
        }
    }
    
}


#XeMayHaNoi.java


/*
 * 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 lesson13.bt1139;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class XeMayHaNoi implements IXe{
    int n;
    XeMay[] xemayList;

    public XeMayHaNoi() {
    }

    public int getN() {
        return n;
    }

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

    public XeMay[] getXemayList() {
        return xemayList;
    }

    public void setXemayList(XeMay[] xemayList) {
        this.xemayList = xemayList;
    }
    
    @Override
    public void nhap() {
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap so xe may can quan ly tai TP Ha Noi: ");
        n = Integer.parseInt(scan.nextLine());
        
        xemayList = new XeMay[n];
        
        for (int i = 0; i < n; i++) {
            xemayList[i] = new XeMay();
            xemayList[i].nhap();
        }
    }

    @Override
    public void hienthi() {
        System.out.println("Hien thi danh sach xe may tai TP Ha Noi: ");
        
        for (int i = 0; i < n; i++) {
            xemayList[i].hienthi();
        }
    }
    
}


#XeMay.java


/*
 * 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 lesson13.bt1139;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
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 xe: ");
        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());
    }

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

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


#QuanLyChung.java


/*
 * 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 lesson13.bt1139;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class QuanLyChung {

    static XeMayHaNoi xeMayHaNoi = new XeMayHaNoi();
    static XeMayHoaBinh xeMayHoaBinh = new XeMayHoaBinh();
    static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
        int choose;

        List<XeMay> list;

        do {
            showMenu();
            choose = Integer.parseInt(scan.nextLine());

            switch (choose) {
                case 1:
                    xeMayHoaBinh.nhap();
                    break;
                case 2:
                    xeMayHaNoi.nhap();
                    break;
                case 3:
                    System.out.println("Lua chon tinh can sap xep");
                    list = getXemayByCity();

                    Collections.sort(list, new Comparator<XeMay>() {
                        @Override
                        public int compare(XeMay o1, XeMay o2) {
                            return o1.getBienso().compareToIgnoreCase(o2.getBienso());
                        }
                    });

                    for (XeMay xeMay : list) {
                        xeMay.hienthi();
                    }
                    break;
                case 4:
                    System.out.println("Lua chon tinh can tim kiem");
                    list = getXemayByCity();
                    String bienso = scan.nextLine();
                    
                    for (XeMay xeMay : list) {
                        if(xeMay.getBienso().equalsIgnoreCase(bienso)) {
                            xeMay.hienthi();
                            break;
                        }
                    }
                    break;
                case 5:
                    System.out.println("Lua chon tinh can xem thong ke: ");
                    list = getXemayByCity();
                    System.out.println("Tong so xe: " + list.size());
                    break;
                case 6:
                    System.out.println("Thoat!!!");
                    break;
                default:
                    System.out.println("Nhap sai!!!");
                    break;
            }
        } while (choose != 6);
    }

    static void showMenu() {
        System.out.println("1. Nhap xe tinh Hoa Binh");
        System.out.println("2. Nhap xe TP Ha Noi");
        System.out.println("3. Sap xep theo bien so xe (A-Z)");
        System.out.println("4. Tim kiem theo bien so xe");
        System.out.println("5. Thong ke so luong xe");
        System.out.println("6. Thoat");
        System.out.println("Chon: ");
    }

    static List<XeMay> getXemayByCity() {
        List<XeMay> list;
        
        System.out.println("1. TP Ha Noi");
        System.out.println("2. Tinh Hoa Binh");
        System.out.println("Chon: ");

        int option = Integer.parseInt(scan.nextLine());

        switch (option) {
            case 1:
                list = Arrays.asList(xeMayHaNoi.getXemayList());
                break;
            default:
                list = Arrays.asList(xeMayHoaBinh.getXemayList());
                break;
        }
        return list;
    }
}


#IXe.java


/*
 * 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 lesson13.bt1139;

/**
 *
 * @author Diep.Tran
 */
public interface IXe {
    void nhap();
    void hienthi();
}


avatar
Đỗ Phan Hà [community,C2010L]
2021-08-05 13:20:45


#IXe.java


/*
 * 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 ZZoukertic
 */
public interface IXe {
    public void nhap();
    public void hienthi();
}


#QuanLyChung.java


/*
 * 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.lang.reflect.Array;
import java.util.Scanner;
import java.util.Collection;
import java.util.List;
/**
 *
 * @author ZZoukertic
 */
public class QuanLyChung {
    static XeMayHaNoi hanoi;
    static XeMayHoaBinh hoabinh;
    static Scanner sc;
    
    public static void main(String[] args){
        hanoi = new XeMayHaNoi();
        hoabinh = new XeMayHoaBinh();
        sc = new Scanner(System.in);
        int choose;
        

        
        do{
            showMenu();
            choose = Integer.parseInt(sc.nextLine());

            switch(choose){
                case 1:
                    hoabinh.nhap();
                    break;
                case 2:
                    hanoi.nhap();
                    break;
                case 3:
                    sort();
                    break;
                case 4:
                    search();
                    break;
                case 5:
                    showinfo();
                    break;
                case 6:
                    System.out.println("Thoat!!!");
                    break;
                default:
                    System.out.println("Nhap sai!!!");
                    break;
            }
        } while (choose != 6);
    }
    
    static void showMenu(){
        System.out.println("1. Nhap xe may tai Hoa Binh");
        System.out.println("2. Nhap xe may tai Ha Noi");
        System.out.println("3. Sap xe danh sach tang cua bien so xe");
        System.out.println("4. Tim kiem thong tin theo bien so xe");
        System.out.println("5. Thong ke so luong xe dang quan ly");
        System.out.println("6. Thoat");
        System.out.println("Chon: ");
    }
    
    static void showMenuByAddress(){
        System.out.println("1. Hoa Binh");
        System.out.println("2. Ha Noi");
        System.out.println("Chon:");
    }
    
    static void sort(){
        showMenuByAddress();
        int choose = Integer.parseInt(sc.nextLine());
        XeMay[] danhsachxe;
        
        danhsachxe = switch (choose) {
            case 1 -> hoabinh.getDanhsachxemay();
            default -> hanoi.getDanhsachxemay();
        };
        List<XeMay> list = Array.asList(danhsachxe);
        
        Collection.sort(list, (o1, o2) -> o1.getBienso().compareToIgnoreCase(o2.getBienso()));
        
        list.forEach(XeMay -> {
            XeMay.hienthi();
        });
    }
    
    static void search(){
        showMenuByAddress();
        int choose = Integer.parseInt(sc.nextLine());
        XeMay[] danhsachxe;
        
        danhsachxe = switch (choose) {
            case 1 -> hoabinh.getDanhsachxemay();
            default -> hanoi.getDanhsachxemay();
        };
        System.out.println("Nhap bien so xe can tim:");
        String bs = sc.nextLine();
        boolean Finded = false;
        for(XeMay xemay : danhsachxe){
            if(xemay.getBienSo().equalsIgnoreCase(bs)){
                xemay.hienthi();
                Finded = true;
                break;
            }
        }
        if (!Finded){
            System.out.println("Khong tim thay bien so xe " + bs);
        }
    }
    
    static void showinfo(){
        showMenuByAddress();
        int choose = Integer.parseInt(sc.nextLine());
        
        switch(choose){
            case 1 -> System.out.println("So xe dang quan ly tai tinh Hoa Binh: " + hoabinh.getN());
            default -> System.out.println("So xe dang quan ly tai tinh Ha Noi: " + hanoi.getN());  
        }
    }
}


#XeMay.java


/*
 * 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 ZZoukertic
 */
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 sc = new Scanner(System.in);
        System.out.println("Nhap Bien so xe: ");
        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 = Float.parseFloat(sc.nextLine());
    }

    @Override
    public void hienthi() {
        System.out.println(toString());
    }
    
    @Override 
    public String toString(){
        return "Xe may{" + "bienso = " + bienso + ",loaixe = " + loaixe + ",mauxe = " + mauxe + ",giatien = " + giatien + "}";
    }
}


#XeMayHaNoi.java


/*
 * 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 ZZoukertic
 */
public class XeMayHaNoi implements IXe {
    int n;
    XeMay[] danhsachxemay;
    public XeMayHaNoi(){
    }
    
    public int getN(){
        return n;
    }
    public void setN(int n){
        this.n = n;
    }
    public XeMay[] getDanhsachxemay() {
        return danhsachxemay;
    }
    public void setDanhsachxemay(XeMay[] danhsachxemay){
        this.danhsachxemay = danhsachxemay;
    }
    
    @Override
    public void nhap() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap so xe tai Ha Noi: ");
        n = Integer.parseInt(sc.nextLine());
        danhsachxemay = new XeMay[n];
        for (int i = 0; i < n; i++){
            danhsachxemay[i] = new XeMay();
            danhsachxemay[i].nhap();
        }
    }

    @Override
    public void hienthi() {
        System.out.println("Danh sach xe may tai Ha Noi: ");
        for (int i = 0; i < n; i++){
            System.out.println("Thong tin xe may thu " + (i+1));
            danhsachxemay[i].hienthi();
        }
    }
    
}


#XeMayHoaBinh.java


/*
 * 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 ZZoukertic
 */
public class XeMayHoaBinh implements IXe {
    int n;
    XeMay[] danhsachxemay;
    public XeMayHoaBinh(){
    }
    
    public int getN(){
        return n;
    }
    public void setN(int n){
        this.n = n;
    }
    public XeMay[] getDanhsachxemay() {
        return danhsachxemay;
    }
    public void setDanhsachxemay(XeMay[] danhsachxemay){
        this.danhsachxemay = danhsachxemay;
    }
    
    @Override
    public void nhap() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Nhap so xe tai Hoa Binh: ");
        n = Integer.parseInt(sc.nextLine());
        danhsachxemay = new XeMay[n];
        for (int i = 0; i < n; i++){
            danhsachxemay[i] = new XeMay();
            danhsachxemay[i].nhap();
        }
    }

    @Override
    public void hienthi() {
        System.out.println("Danh sach xe may tai Hoa Binh: ");
        for (int i = 0; i < n; i++){
            System.out.println("Thong tin xe may thu " + (i+1));
            danhsachxemay[i].hienthi();
        }
    }
    
}


avatar
Đào Mạnh Dũng [C2010L]
2021-08-05 13:05:26


#Gokisoft1139.java


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

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

/**
 *
 * @author Đào Dũng
 */
public class Gokisoft1139 {

    /**Câu 2:
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("nhap s1 ");
        String s1 = scan.nextLine();
        System.out.println("nhap s2 ");
        String s2 = scan.nextLine();
        ArrayList<Integer> tmp = new ArrayList<>();
        int index = 0;
        while (s1.indexOf(s2,index)!=-1) {            
            tmp.add(s1.indexOf(s2,index));
            index = s1.indexOf(s2,index)+1;
        }
        System.out.print("Số lần xuất hiện: "+tmp.size()+"\nCác vị trí xuất hiện lần lượt là: ");
        


        for (int i = 0; i < tmp.size()-1; i++) {
            System.out.print(tmp.get(i)+" ,");
        }
        System.out.print(tmp.get(tmp.size()-1)+"\n");
    }

}


#XeMayHaNoi.java


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

/**
 *
 * @author Đào Dũng
 */
public class XeMayHaNoi implements IXe{

    int n;
    
    public XeMay[] arr;     

    public XeMayHaNoi() {
    }

      
    
    @Override
    public void nhap() {

        System.out.print("nhap so xe :" );
        Scanner scan = new Scanner(System.in);
        n = Integer.parseInt(scan.nextLine());
        arr = new XeMay[n];
        for (int i = 0; i < n; i++) {
            arr[i] = new XeMay();
                    System.out.print("nhap thong tin xe thu "+i+" :" );
                arr[i].nhap();
        }

    }

    @Override
    public void hienthi() {


    }
}


#XeMayHoaBinh.java


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

/**
 *
 * @author Đào Dũng
 */
public class XeMayHoaBinh  implements IXe{

    int n;
    
    public XeMay[] arr;     

    public XeMayHoaBinh() {
    }

      
    
    @Override
    public void nhap() {

        System.out.print("nhap so xe :" );
        Scanner scan = new Scanner(System.in);
        n = Integer.parseInt(scan.nextLine());
        arr = new XeMay[n];
        for (int i = 0; i < n; i++) {
            arr[i] = new XeMay();
                    System.out.print("nhap thong tin xe thu "+i+" :" );
                arr[i].nhap();
        }

    }

    @Override
    public void hienthi() {


    }
    
}


#QuanLyChung.java


/*
 * 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 hanoi.xemay.XeMayHaNoi;
import hoabinh.xemay.XeMayHoaBinh;
import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author Đào Dũng
 */
public class QuanLyChung {
        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            XeMayHaNoi x = null;
            XeMayHoaBinh y = null; 
            while (true) {   
                menu();
                switch(Integer.parseInt(scan.nextLine())){
                    case 1 ->{
                        y = new XeMayHoaBinh();
                        y.nhap();
                        
                    }
                    case 2 ->{
                        x = new XeMayHaNoi();
                        x.nhap();
                        
                    }
                    case 3 ->{
                        System.out.println("nhap tinh can thu hien ");
                        if (scan.nextLine().equals("Hòa Bình")) {
                            Arrays.sort(y.arr);
                        }
                        if (scan.nextLine().equals("Hà Nội")) {
                            Arrays.sort(x.arr);
                        }
                    }
                    case 4 ->{
                        System.out.println("nhap tinh can thu hien ");
                        if (scan.nextLine().equals("Hòa Bình")) {
                            System.out.println("nhap bien so");
                            String str = scan.nextLine();
                            for (int i = 0; i < y.arr.length; i++) {
                                if (y.arr[i].getBienso().equals(str)) {
                                    System.out.println("thong tin xe la");
                                    y.arr[i].hienthi();
                                    break;
                                }
                                
                            }
                             
                        }
                        if (scan.nextLine().equals("Hà Nội")) {
                            System.out.println("nhap bien so");
                            String str = scan.nextLine();
                            for (int i = 0; i < x.arr.length; i++) {
                                if (x.arr[i].getBienso().equals(str)) {
                                    System.out.println("thong tin xe la");
                                    x.arr[i].hienthi();
                                    break;
                                }
                                
                            }
                        }
                    }
                    case 5 ->{
                        System.out.println("nhap tinh can thu hien ");
                        if (scan.nextLine().equals("Hòa Bình")) {
                            System.out.println("so xe dang quan ly la " + y.arr.length);
                        }
                        if (scan.nextLine().equals("Hà Nội")) {
                            System.out.println("so xe dang quan ly la " + x.arr.length);
                        }
                    }
                    case 6 ->{
                        System.exit(0);
                    }
                }        
            }
        }

    private 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.\n" +
        "\n" +
        "2. Nhập thông tin cho n xe máy tại tỉnh Hà Nội.\n" +
        "\n" +
        "3. Sắp xếp danh sách tăng theo biển số xe.\n" +
        "\n" +
        "4. Tìm kiếm thông tin xe theo biển số xe.\n" +
        "\n" +
        "5. Thống kê số lượng xe đang quản lý.\n"
                + "chon : ");
    }
}


#IXe.java


/*
 * 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 inter
 */
public interface IXe {
     public void nhap();

     public void hienthi();
}


#XeMay.java


/*
 * 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 Đào Dũng
 */
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());
    }

    @Override
    public void hienthi() {
        System.out.println("bien so la "+bienso);
        System.out.println("loai xe la "+loaixe);
        System.out.println("mau la "+mauxe);
        System.out.println("gia tien la "+giatien);
    }
}


avatar
GokiSoft.com [Teacher]
2021-07-23 02:44:53


#XeMayHoaBinh.java


/*
 * 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 lesson09.bt1139;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class XeMayHoaBinh implements IXe{
    int n;
    XeMay[] dsXemay;

    public XeMayHoaBinh() {
    }

    @Override
    public void nhap() {
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap so xe tai Hoa Binh (n): ");
        try {
            n = Integer.parseInt(scan.nextLine());
        } catch(NumberFormatException e) {}
        
        dsXemay = new XeMay[n];
        for (int i = 0; i < n; i++) {
            dsXemay[i] = new XeMay();
            dsXemay[i].nhap();
        }
    }

    @Override
    public void hienthi() {
        System.out.println("Danh sach xe may tinh Hoa Binh");
        
        for (int i = 0; i < dsXemay.length; i++) {
            System.out.println("Thong tin xe may thu " + i);
            dsXemay[i].hienthi();
        }
    }

    public int getN() {
        return n;
    }

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

    public XeMay[] getDsXemay() {
        return dsXemay;
    }

    public void setDsXemay(XeMay[] dsXemay) {
        this.dsXemay = dsXemay;
    }
}


#XeMayHaNoi.java


/*
 * 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 lesson09.bt1139;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class XeMayHaNoi implements IXe{
    int n;
    XeMay[] dsXemay;

    public XeMayHaNoi() {
    }

    @Override
    public void nhap() {
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap so xe may tai Ha Noi (n): ");
        try {
            n = Integer.parseInt(scan.nextLine());
        } catch(NumberFormatException e) {}
        
        dsXemay = new XeMay[n];
        for (int i = 0; i < n; i++) {
            dsXemay[i] = new XeMay();
            dsXemay[i].nhap();
        }
    }

    @Override
    public void hienthi() {
        System.out.println("Danh sach xe may tinh Ha Noi");
        
        for (int i = 0; i < dsXemay.length; i++) {
            System.out.println("Thong tin xe may thu " + i);
            dsXemay[i].hienthi();
        }
    }

    public int getN() {
        return n;
    }

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

    public XeMay[] getDsXemay() {
        return dsXemay;
    }

    public void setDsXemay(XeMay[] dsXemay) {
        this.dsXemay = dsXemay;
    }
}


#XeMay.java


/*
 * 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 lesson09.bt1139;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
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;
    }

    @Override
    public void nhap() {
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Bien so xe: ");
        bienso = scan.nextLine();
        
        System.out.println("Loai xe: ");
        loaixe = scan.nextLine();
        
        System.out.println("Mau xe: ");
        mauxe = scan.nextLine();
        
        try {
            System.out.println("Gia tien: ");
            giatien = Float.parseFloat(scan.nextLine());
        } catch(NumberFormatException e) {}
    }

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

    @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;
    }
}


#QuanLyChung.java


/*
 * 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 lesson09.bt1139;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class QuanLyChung {
    static XeMayHaNoi haNoi;
    static XeMayHoaBinh hoaBinh;
    static Scanner scan;
    
    public static void main(String[] args) {
        haNoi = new XeMayHaNoi();
        hoaBinh = new XeMayHoaBinh();
        scan = new Scanner(System.in);
        int choose;
        
        do {
            showMenu();
            choose = Integer.parseInt(scan.nextLine());
            
            switch(choose) {
                case 1:
                    hoaBinh.nhap();
                    break;
                case 2:
                    haNoi.nhap();
                    break;
                case 3:
                    sort();
                    break;
                case 4:
                    search();
                    break;
                case 5:
                    showInfor();
                    break;
                case 6:
                    System.out.println("Thoat!!!");
                    break;
                default:
                    System.out.println("Nhap sai!!!");
                    break;
            }
        } while(choose != 6);
    }
    
    static void showMenu() {
        System.out.println("1. Nhap xe may tinh hoa binh");
        System.out.println("2. Nhap xe may TP. Ha Noi");
        System.out.println("3. Sort theo bien so xe");
        System.out.println("4. Tim kiem theo bien so xe");
        System.out.println("5. Thong ke so xe dang quan ly");
        System.out.println("6. Thoat");
        System.out.println("Chon: ");
    }
    
    static void showMenuByAddress() {
        System.out.println("1. Hoa Binh");
        System.out.println("2. Ha Noi");
        System.out.println("Chon: ");
    }

    static void sort() {
        showMenuByAddress();
        int choose = Integer.parseInt(scan.nextLine());
        XeMay[] dsXe;
        
        switch(choose) {
            case 1:
                dsXe = hoaBinh.getDsXemay();
                break;
            default:
                dsXe = haNoi.getDsXemay();
                break;
        }
        
        List<XeMay> list = Arrays.asList(dsXe);
        
        Collections.sort(list,
            (o1, o2) -> o1.getBienso().compareToIgnoreCase(o2.getBienso()));
        
        list.forEach(xeMay -> {
            xeMay.hienthi();
        });
    }

    static void search() {
        showMenuByAddress();
        int choose = Integer.parseInt(scan.nextLine());
        XeMay[] dsXe;
        
        switch(choose) {
            case 1:
                dsXe = hoaBinh.getDsXemay();
                break;
            default:
                dsXe = haNoi.getDsXemay();
                break;
        }
        System.out.println("Nhap bien so xe can tim: ");
        String bs = scan.nextLine();
        
        boolean isFind = false;
        for (XeMay xeMay : dsXe) {
            if(xeMay.getBienso().equalsIgnoreCase(bs)) {
                xeMay.hienthi();
                isFind = true;
                break;
            }
        }
        if(!isFind) {
            System.out.println("Khong tim thay bien so xe " + bs);
        }
    }

    static void showInfor() {
        showMenuByAddress();
        int choose = Integer.parseInt(scan.nextLine());
        
        switch(choose) {
            case 1:
                System.out.println("So xe dang quan ly tai tinh hoa binh: " + hoaBinh.getN());
                break;
            default:
                System.out.println("So xe dang quan ly tai tp Ha Noi: " + haNoi.getN());
                break;
        }
    }
}


#IXe.java


/*
 * 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 lesson09.bt1139;

/**
 *
 * @author Diep.Tran
 */
public interface IXe {
    void nhap();
    void hienthi();
}


avatar
Nguyễn Tiến Đạt [T2008A]
2021-03-04 02:00:25


#IXe.java


/*
 * 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 lesson8.QuanLyXeDiaBan;

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


#Test.java


/*
 * 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 lesson8.QuanLyXeDiaBan;

import java.util.Scanner;

/**
 *
 * @author MyPC
 */
public class Test {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        XeMayHaNoi haNoi = new XeMayHaNoi();
        XeMayHoaBinh hoaBinh = new XeMayHoaBinh();
        int choose, chon;
        do{
            showMenu();
            System.out.println("Lua chon chuong trinh:");
            choose = Integer.parseInt(scan.nextLine());
            switch(choose){
                case 1:
                    hoaBinh.nhap();
                    break;
                case 2:
                    haNoi.nhap();
                    break;
                case 3:
                    System.out.println("1.Danh sach xe Hoa Binh");
                    System.out.println("2.Danh sach xe Ha Noi");
                    System.out.println("Lua chon khu vuc:");
                    chon = Integer.parseInt(scan.nextLine());;
                    if(chon == 1){
                        hoaBinh.sapXep();
                    }else{
                        haNoi.sapXep();
                    }
                    break;
                case 4:
                    System.out.println("1.Danh sach xe Hoa Binh");
                    System.out.println("2.Danh sach xe Ha Noi");
                    System.out.println("Lua chon khu vuc:");
                    chon = Integer.parseInt(scan.nextLine());;
                    if(chon == 1){
                        hoaBinh.search();
                    }else{
                        haNoi.search();
                    }
                    break;
                case 5:
                    System.out.println("Danh sach xe Hoa Binh:");
                    hoaBinh.hoaBinhList.forEach((xeMay) -> {
                        xeMay.hienthi();
                    });
                    System.out.println("Danh sach xe Ha Noi:");
                    haNoi.haNoiList.forEach((xeMay) -> {
                        xeMay.hienthi();
                    });
                    break;
                case 6:
                    System.out.println("Tam biet!!");
                    break;
                default:
                    System.out.println("Nhap sai chuong trinh!!");
                    break;
            }
        }while(choose != 6);
    }
    
    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. Thoát");
    }
}


#XeMay.java


/*
 * 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 lesson8.QuanLyXeDiaBan;

/**
 *
 * @author MyPC
 */
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() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

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

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


#XeMayHaNoi.java


/*
 * 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 lesson8.QuanLyXeDiaBan;

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

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

    public XeMayHaNoi() {
    }

    public XeMayHaNoi(int n) {
        this.n = n;
    }

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

    public int getN() {
        return n;
    }

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

    public ArrayList<XeMay> getHaNoiList() {
        return haNoiList;
    }

    public void setHoaBinhList(ArrayList<XeMay> haNoiList) {
        this.haNoiList = haNoiList;
    }

    @Override
    public String getBienso() {
        return bienso;
    }

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

    @Override
    public String getLoaixe() {
        return loaixe;
    }

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

    @Override
    public String getMauxe() {
        return mauxe;
    }

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

    @Override
    public float getGiatien() {
        return giatien;
    }

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

    @Override
    public void nhap() {
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap so luong xe o Ha Noi muon them:");
        int n = Integer.parseInt(scan.nextLine());
        for (int i = 1; i <= n; i++) {
            System.out.println("Nhap thong tin xe thu " + i + ":");
            XeMay xemay = new XeMayHaNoi();
            System.out.println("Bien so xe:");
            xemay.bienso = scan.nextLine();
            System.out.println("Loai xe:");
            xemay.loaixe = scan.nextLine();
            System.out.println("Mau xe:");
            xemay.mauxe = scan.nextLine();
            System.out.println("Gia tien:");
            xemay.giatien = Float.parseFloat(scan.nextLine());
            haNoiList.add(xemay);
        }
    }
    
    public void sapXep(){
        Collections.sort(haNoiList, (XeMay o1, XeMay o2) -> o1.bienso.compareToIgnoreCase(o2.bienso));
        System.out.println("Danh sach xe may Ha Noi sau khi da sap xep theo bien so xe:");
        haNoiList.forEach((xeMay) -> {
            xeMay.hienthi();
        });
    }
    
    public void search(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap bien so xe muon tim kiem:");
        String bien = scan.nextLine();
        int check = 0;
        check = haNoiList.stream().filter((xeMay) -> (xeMay.bienso.equalsIgnoreCase(bien))).map((xeMay) -> {
            xeMay.hienthi();
            return xeMay;
        }).map((_item) -> 1).reduce(check, Integer::sum);
        if(check == 0) System.out.println("Khong tim thay xe nao co bien so xe nhu vay!!");
    }

    @Override
    public void hienthi() {
        System.out.println("XeMay{" + "bienso=" + bienso + ", loaixe=" + loaixe + ", mauxe=" + mauxe + ", giatien=" + giatien + '}');
    }
}


#XeMayHoaBinh.java


/*
 * 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 lesson8.QuanLyXeDiaBan;

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


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

    public XeMayHoaBinh() {
    }

    public XeMayHoaBinh(int n) {
        this.n = n;
    }

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

    public int getN() {
        return n;
    }

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

    public ArrayList<XeMay> getHoaBinhList() {
        return hoaBinhList;
    }

    public void setHoaBinhList(ArrayList<XeMay> hoaBinhList) {
        this.hoaBinhList = hoaBinhList;
    }

    @Override
    public String getBienso() {
        return bienso;
    }

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

    @Override
    public String getLoaixe() {
        return loaixe;
    }

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

    @Override
    public String getMauxe() {
        return mauxe;
    }

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

    @Override
    public float getGiatien() {
        return giatien;
    }

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

    @Override
    public void nhap() {
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap so luong xe o Hoa Binh muon them:");
        int n = Integer.parseInt(scan.nextLine());
        for (int i = 1; i <= n; i++) {
            System.out.println("Nhap thong tin xe thu " + i + ":");
            XeMay xemay = new XeMayHoaBinh();
            System.out.println("Bien so xe:");
            xemay.bienso = scan.nextLine();
            System.out.println("Loai xe:");
            xemay.loaixe = scan.nextLine();
            System.out.println("Mau xe:");
            xemay.mauxe = scan.nextLine();
            System.out.println("Gia tien:");
            xemay.giatien = Float.parseFloat(scan.nextLine());
            hoaBinhList.add(xemay);
        }
    }
    
    public void sapXep(){
        Collections.sort(hoaBinhList, (XeMay o1, XeMay o2) -> o1.bienso.compareToIgnoreCase(o2.bienso));
        System.out.println("Danh sach xe may Hoa Binh sau khi da sap xep theo bien so xe:");
        hoaBinhList.forEach((xeMay) -> {
            xeMay.hienthi();
        });
    }
    
    public void search(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap bien so xe muon tim kiem:");
        String bien = scan.nextLine();
        int check = 0;
        check = hoaBinhList.stream().filter((xeMay) -> (xeMay.bienso.equalsIgnoreCase(bien))).map((xeMay) -> {
            xeMay.hienthi();
            return xeMay;
        }).map((_item) -> 1).reduce(check, Integer::sum);
        if(check == 0) System.out.println("Khong tim thay xe nao co bien so xe nhu vay!!");
    }

    @Override
    public void hienthi() {
        System.out.println("XeMay{" + "bienso=" + bienso + ", loaixe=" + loaixe + ", mauxe=" + mauxe + ", giatien=" + giatien + '}');
    }
    
}


avatar
Nguyen Duc Viet [C1907L]
2020-04-08 11:14:39



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

import java.util.Scanner;

/**
 *
 * @author Viet
 */
public class XeMay implements IXe {
    String bienso,loaixe, 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 float getGiatien() {
        return giatien;
    }

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

    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;
    }
    
    @Override
    public void nhap() {
        Scanner input = new Scanner(System.in);
        System.out.println("biển số : ?");
        bienso = input.nextLine();
        System.out.println("loại xe: ?");
        loaixe = input.nextLine();
        System.out.println("màu xe: ?");
        mauxe = input.nextLine();
        System.out.println("giá tiền: ?");
        giatien = Float.parseFloat(input.nextLine());        
    }
    
    @Override
    public void hienthi() {
        System.out.println(this);
    }

    @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 hoabinh.xemay;
import java.util.Scanner;
import xeco.info.XeMay;
/**
 *
 * @author Viet
 */
public class XeMayHoaBinh {
      int n;
    XeMay[] arrXMHB;

    public XeMayHoaBinh() {
    }

    public XeMayHoaBinh(XeMay[] arrXMHB) {
        this.arrXMHB = arrXMHB;
        this.n = arrXMHB.length;
    }

    public int getN() {
        return n;
    }

    public XeMay[] getArrXMHB() {
        return arrXMHB;
    }

    public void nhap() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập vào số lượng xe: ");
        n = Integer.parseInt(input.nextLine());
        arrXMHB = new XeMay[n];
        for (int i = 0; i < n; i++) {
            arrXMHB[i] = new XeMay();
            arrXMHB[i].nhap();
        }
    }

    public void hienthi() {
        for (int i = 0; i < n; i++) {
            arrXMHB[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;

/**
 *
 * @author Viet
 */
public class XeMayHaNoi {
    int n;
    XeMay[] arrXMHN;

    public XeMayHaNoi() {
    }

    public XeMayHaNoi(XeMay[] arrXMHN) {
        this.arrXMHN = arrXMHN;
        this.n = arrXMHN.length;
    }

    public int getN() {
        return n;
    }

    public XeMay[] getArrXMHN() {
        return arrXMHN;
    }

    
    public void nhap() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập vào số lượng xe: ");
        n = Integer.parseInt(input.nextLine());
        arrXMHN = new XeMay[n];
        for (int i = 0; i < n; i++) {
            arrXMHN[i] = new XeMay();
            arrXMHN[i].nhap();
        }
    }

    public void hienthi() {
        for (int i = 0; i < n; i++) {
            arrXMHN[i].hienthi();
        }
    }
}


avatar
Lê Trí Dũng [C1907L]
2020-04-08 08:14:06



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

import java.util.Scanner;

/**
 *
 * @author Dzung
 */
public class XeMay implements IXe {
    String bienso,loaixe, 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 float getGiatien() {
        return giatien;
    }

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

    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;
    }
    
    @Override
    public void nhap() {
        Scanner input = new Scanner(System.in);
        System.out.println("biển số : ?");
        bienso = input.nextLine();
        System.out.println("loại xe: ?");
        loaixe = input.nextLine();
        System.out.println("màu xe: ?");
        mauxe = input.nextLine();
        System.out.println("giá tiền: ?");
        giatien = Float.parseFloat(input.nextLine());        
    }
    
    @Override
    public void hienthi() {
        System.out.println(this);
    }

    @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 hoabinh.xemay;
import java.util.Scanner;
import xeco.info.XeMay;
/**
 *
 * @author Dzung
 */
public class XeMayHoaBinh {
      int n;
    XeMay[] arrXMHB;

    public XeMayHoaBinh() {
    }

    public XeMayHoaBinh(XeMay[] arrXMHB) {
        this.arrXMHB = arrXMHB;
        this.n = arrXMHB.length;
    }

    public int getN() {
        return n;
    }

    public XeMay[] getArrXMHB() {
        return arrXMHB;
    }

    public void nhap() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập vào số lượng xe: ");
        n = Integer.parseInt(input.nextLine());
        arrXMHB = new XeMay[n];
        for (int i = 0; i < n; i++) {
            arrXMHB[i] = new XeMay();
            arrXMHB[i].nhap();
        }
    }

    public void hienthi() {
        for (int i = 0; i < n; i++) {
            arrXMHB[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;

/**
 *
 * @author Dzung
 */
public class XeMayHaNoi {
    int n;
    XeMay[] arrXMHN;

    public XeMayHaNoi() {
    }

    public XeMayHaNoi(XeMay[] arrXMHN) {
        this.arrXMHN = arrXMHN;
        this.n = arrXMHN.length;
    }

    public int getN() {
        return n;
    }

    public XeMay[] getArrXMHN() {
        return arrXMHN;
    }

    
    public void nhap() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập vào số lượng xe: ");
        n = Integer.parseInt(input.nextLine());
        arrXMHN = new XeMay[n];
        for (int i = 0; i < n; i++) {
            arrXMHN[i] = new XeMay();
            arrXMHN[i].nhap();
        }
    }

    public void hienthi() {
        for (int i = 0; i < n; i++) {
            arrXMHN[i].hienthi();
        }
    }
}


avatar
Hoàng Quang Huy [C1907L]
2020-04-06 09:34:11




package xeco.info;

public interface IXe {
    public void nhap();
    public void hienthi();
}
-------------------------------------------------------------------------------------

package xeco.info;

import java.util.Scanner;

public class XeMay implements IXe{

    private String bienso;
    private String loaixe;
    private String 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;
    }

    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 input = new Scanner(System.in);
        System.out.println("Nhập biển số xe: ");
        this.bienso = input.nextLine();
        System.out.println("Nhập giá tiền: ");
        this.giatien = Integer.parseInt(input.nextLine());
        System.out.println("Nhập loại xe: ");
        this.loaixe = input.nextLine();
        System.out.println("Nhập màu xe: ");
        this.mauxe = input.nextLine();
    }

    @Override
    public void hienthi() {
        System.out.println("Biển số xe: "+bienso);
        System.out.println("Giá tiền: "+giatien);
        System.out.println("Loại xe: "+loaixe);
        System.out.println("Màu xe: "+mauxe);
    }
    
}
-----------------------------------------------------------------------------------

package hoabinh.xemay;

import java.util.Scanner;
import xeco.info.XeMay;

public class XeMayHoaBinh extends XeMay{
    private int n;
    XeMay [] xemayhoabinh;

    public XeMayHoaBinh() {
    }

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

    public int getN() {
        return n;
    }

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

    public XeMay[] getXemay() {
        return xemayhoabinh;
    }

    public void setXemay(XeMay[] xemayhoabinh) {
        this.xemayhoabinh = xemayhoabinh;
    }
    
    @Override
    public void nhap(){
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập số lượng xe: ");
        this.n = Integer.parseInt(input.nextLine());
        xemayhoabinh = new XeMay[n];
        for (int i = 0; i < n; i++) {
            xemayhoabinh[i] = new XeMay();
            xemayhoabinh[i].nhap();
        }
    }
    
    @Override
    public void hienthi(){
        System.out.println("Danh sách xe mày ở Hòa Bình:");
        for (int i = 0; i < n; i++) {
            xemayhoabinh[i].hienthi();
        }
    }
}
-------------------------------------------------------------------------------------

package hanoi.xemay;

import xeco.info.XeMay;
import java.util.Scanner;

public class XeMayHaNoi extends XeMay{
    private int n;
    XeMay [] xemayhanoi;

    public XeMayHaNoi() {
    }

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

    public int getN() {
        return n;
    }

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

    public XeMay[] getXemay() {
        return xemayhanoi;
    }

    public void setXemay(XeMay[] xemayhanoi) {
        this.xemayhanoi = xemayhanoi;
    }
    
    @Override
    public void nhap(){
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập số lượng xe: ");
        this.n = Integer.parseInt(input.nextLine());
        xemayhanoi = new XeMay[n];
        for (int i = 0; i < n; i++) {
            xemayhanoi[i] = new XeMay();
            xemayhanoi[i].nhap();
        }
    }
    
    @Override
    public void hienthi(){
        System.out.println("Danh sách xe mày ở Hà Nội:");
        for (int i = 0; i < n; i++) {
            xemayhanoi[i].hienthi();
        }
    }
}

------------------------------------------------------------------------------------

package quanlychung.xemay;

import java.util.Scanner;
import hanoi.xemay.XeMayHaNoi;
import hoabinh.xemay.XeMayHoaBinh;
import java.util.Arrays;
import java.util.Collections;
import xeco.info.XeMay;

public class QuanLyChung {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int choice;
        boolean flag = true;
        XeMayHoaBinh xemayhoabinh = new XeMayHoaBinh();
        XeMayHaNoi xemayhanoi = new XeMayHaNoi();
        while (flag) {
            showMenu();
            System.out.println("Lựa chọn của bạn: ");
            choice = Integer.parseInt(input.nextLine());
            switch (choice) {
                case 1:
                    xemayhoabinh.nhap();
                    break;
                case 2:
                    xemayhanoi.nhap();
                    break;
                case 3:
                    System.out.println("1.Hà Nội");
                    System.out.println("2.Hòa Bình");
                    System.out.println("Nhập tên tỉnh/thành phố bạn muốn chọn: ");
                    int choose3 = Integer.parseInt(input.nextLine());
                    switch (choose3) {
                        case 1:
                            for (int i = 0; i < xemayhanoi.getXemay().length - 1; i++) {
                                for (int j = i + 1; j < xemayhanoi.getXemay().length; j++) {
                                    if (xemayhanoi.getXemay()[i].getBienso().compareTo(xemayhanoi.getXemay()[i].getBienso()) > 0) {
                                        XeMay temp = xemayhanoi.getXemay()[i];
                                        xemayhanoi.getXemay()[i] = xemayhanoi.getXemay()[j];
                                        xemayhanoi.getXemay()[j] = temp;
                                    }
                                }
                            }
                            System.out.println("Danh sách xe máy ở Hà Nội: ");
                            xemayhanoi.hienthi();
                            break;
                        case 2:
                            for (int i = 0; i < xemayhoabinh.getXemay().length - 1; i++) {
                                for (int j = i + 1; j < xemayhoabinh.getXemay().length; j++) {
                                    if (xemayhoabinh.getXemay()[i].getBienso().compareTo(xemayhoabinh.getXemay()[i].getBienso()) > 0) {
                                        XeMay temp = xemayhoabinh.getXemay()[i];
                                        xemayhoabinh.getXemay()[i] = xemayhoabinh.getXemay()[j];
                                        xemayhoabinh.getXemay()[j] = temp;
                                    }
                                }
                            }
                        }
                            System.out.println("Danh sách xe máy ở Hòa Bình: ");
                            for (int i = 0; i < xemayhoabinh.getXemay().length; i++) {
                                xemayhoabinh.getXemay()[i].hienthi();
                            }
                            break;
                        case 4:
                            System.out.println("1.Hà Nội");
                            System.out.println("2.Hòa Bình");
                            System.out.println("Nhập tên tỉnh/thành phố bạn muốn chọn: ");
                            int choose4 = Integer.parseInt(input.nextLine());
                            switch (choose4) {
                                case 1:
                                    boolean flag4_1 = true;
                                    System.out.println("Nhập biển số xe bạn muốn tìm: ");
                                    String biensohanoi = input.nextLine();
                                    for (int i = 0; i < xemayhanoi.getXemay().length; i++) {
                                        if (xemayhanoi.getXemay()[i].getBienso().equals(biensohanoi)) {
                                            flag4_1 = false;
                                            xemayhanoi.getXemay()[i].hienthi();
                                        }
                                    }
                                    if (flag4_1) {
                                        System.out.println("Không tìm thấy xe với biển số " + biensohanoi);
                                    }
                                    break;
                                case 2:
                                    boolean flag4_2 = true;
                                    System.out.println("Nhập biển số xe bạn muốn tìm: ");
                                    String biensohoabinh = input.nextLine();
                                    for (int i = 0; i < xemayhoabinh.getXemay().length; i++) {
                                        if (xemayhoabinh.getXemay()[i].getBienso().equals(biensohoabinh)) {
                                            flag4_2 = false;
                                            xemayhoabinh.getXemay()[i].hienthi();
                                        }
                                    }
                                    if (flag4_2) {
                                        System.out.println("Không tìm thấy xe với biển số " + biensohoabinh);
                                    }
                                    break;
                            }
                            break;
                        case 5:
                            System.out.println("1.Hà Nội");
                            System.out.println("2.Hòa Bình");
                            System.out.println("Nhập tên tỉnh/thành phố bạn muốn chọn: ");
                            int choose5 = Integer.parseInt(input.nextLine());
                            switch (choose5) {
                                case 2:
                                    if (xemayhoabinh.getXemay().length == 0) {
                                        System.out.println("Hiện tại không quản lý xe nào ở Hòa Bình");
                                    } else {
                                        System.out.println("Số lượng xe đang quản lý ở Hòa Bình là: " + xemayhoabinh.getXemay().length);
                                    }
                                    break;
                                case 1:
                                    if (xemayhanoi.getXemay().length == 0) {
                                        System.out.println("Hiện tại không quản lý xe nào ở Hà Nội");
                                    } else {
                                        System.out.println("Số lượng xe đang quản lý ở Hà Nội là: " + xemayhanoi.getXemay().length);
                                    }
                                    break;
                            }
                            break;
                        case 6:
                            flag = false;
                            System.out.println("Thoát chương trình");
                            break;
                    }
            }
        }

    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 thành phố 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");
    }
}


avatar
trung [C1907L]
2020-04-02 15:34:39



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

import java.util.Scanner;

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

    String bienso,loaixe,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 String getLoaixe() {
        return loaixe;
    }

    public String getMauxe() {
        return mauxe;
    }

    public Float getGiatien() {
        return giatien;
    }

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

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

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

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

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

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

import java.util.Scanner;
import xeco.info.XeMay;

/**
 *
 * @author prdox
 */
public class XeMayHoaBinh {
    int n;
    XeMay[] arrXMHB;

    public XeMayHoaBinh() {
    }

    public XeMayHoaBinh(XeMay[] arrXMHB) {
        this.arrXMHB = arrXMHB;
        this.n = arrXMHB.length;
    }

    public int getN() {
        return n;
    }

    public XeMay[] getArrXMHB() {
        return arrXMHB;
    }

    public void nhap() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap vao so luong xe");
        n = Integer.parseInt(input.nextLine());
        arrXMHB = new XeMay[n];
        for (int i = 0; i < n; i++) {
            arrXMHB[i] = new XeMay();
            arrXMHB[i].nhap();
        }
    }

    public void hienthi() {
        for (int i = 0; i < n; i++) {
            arrXMHB[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;

/**
 *
 * @author prdox
 */
public class XeMayHaNoi {

    int n;
    XeMay[] arrXMHN;

    public XeMayHaNoi() {
    }

    public XeMayHaNoi(XeMay[] arrXMHN) {
        this.arrXMHN = arrXMHN;
        this.n = arrXMHN.length;
    }

    public int getN() {
        return n;
    }

    public XeMay[] getArrXMHN() {
        return arrXMHN;
    }

    
    public void nhap() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap vao so luong xe");
        n = Integer.parseInt(input.nextLine());
        arrXMHN = new XeMay[n];
        for (int i = 0; i < n; i++) {
            arrXMHN[i] = new XeMay();
            arrXMHN[i].nhap();
        }
    }

    public void hienthi() {
        for (int i = 0; i < n; i++) {
            arrXMHN[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 quanlychung.xemay;

import hanoi.xemay.XeMayHaNoi;
import hoabinh.xemay.XeMayHoaBinh;
import java.util.Scanner;
import xeco.info.XeMay;

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

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        XeMayHoaBinh xmhb = new XeMayHoaBinh();
        XeMayHaNoi xmhn = new XeMayHaNoi();
        boolean _exit = true;
        int option;
        while (!_exit) {
            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("Choice: ?");
            option = Integer.parseInt(input.nextLine());
            switch (option) {
                case 1:
                    xmhb.nhap();
                    break;
                case 2:
                    xmhn.nhap();
                    break;
                case 3:
                    for (int i = 0; i < xmhn.getArrXMHN().length - 1; i++) {
                        for (int j = i + 1; j < xmhn.getArrXMHN().length; j++) {
                            if (xmhn.getArrXMHN()[i].getBienso().compareTo(xmhn.getArrXMHN()[j].getBienso()) < 0) {
                                XeMay tmp = xmhn.getArrXMHN()[j];
                                xmhn.getArrXMHN()[j] = xmhn.getArrXMHN()[i];
                                xmhn.getArrXMHN()[i] = tmp;
                            }
                        }
                    }
                    for (int i = 0; i < xmhb.getArrXMHB().length - 1; i++) {
                        for (int j = i + 1; j < xmhb.getArrXMHB().length; j++) {
                            if (xmhb.getArrXMHB()[i].getBienso().compareTo(xmhb.getArrXMHB()[j].getBienso()) < 0) {
                                XeMay tmp = xmhb.getArrXMHB()[j];
                                xmhb.getArrXMHB()[j] = xmhb.getArrXMHB()[i];
                                xmhb.getArrXMHB()[i] = tmp;
                            }
                        }
                    }
                    break;
                case 4:
                    System.out.println("bien so xe : ?");
                    String bienso = input.nextLine();
                    int i = 0;
                    for (; i < xmhn.getArrXMHN().length; i++) {
                        if (xmhn.getArrXMHN()[i].getBienso().equals(bienso)) {
                            System.out.println("Found: ");
                            xmhn.getArrXMHN()[i].hienthi();
                            break;
                        }
                    }
                    if (i == xmhn.getArrXMHN().length) {
                        for (i = 0; i < xmhb.getArrXMHB().length; i++) {
                            if (xmhb.getArrXMHB()[i].getBienso().equals(bienso)) {
                                System.out.println("Found: ");
                                xmhb.getArrXMHB()[i].hienthi();
                                break;
                            }
                        }
                    }
                    if (i == xmhb.getArrXMHB().length) {
                        System.out.println("not found !!!!!!!!!!!!!");
                    }
                    break;
                case 5:
                    System.out.format("So luong xe dang quan ly la %d",xmhn.getArrXMHN().length + xmhb.getArrXMHB().length);
                    break;
                case 6:
                    _exit = true;
                    break;

            }
        }
    }
}


avatar
Ngô Quang Huy [C1907L]
2020-04-02 07:04:12



package xeco.info;

public interface IXe {
    public void nhap();
    public void hienthi();
}



package 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 input = new Scanner(System.in);
            System.out.print("Nhap vao bienso: ");
            bienso = input.nextLine();
            System.out.print("Nhap vao loaixe: ");
            loaixe = input.nextLine();
            System.out.print("Nhap vao mauxe: ");
            mauxe = input.nextLine();
            System.out.print("Nhap vao giatien: ");
            giatien = Float.parseFloat(input.nextLine());
    }

    @Override
    public void hienthi() {
            System.out.println("bienso la: "+bienso);
            System.out.println("loaixe la: "+loaixe);
            System.out.println("mauxe la: "+mauxe);
            System.out.println("giatien la: "+giatien);
            
    }
    
    
}



package hoabinh.xemay;

import java.util.Scanner;
import xeco.info.XeMay;

public class XeMayHoaBinh extends XeMay{
    int n;
    XeMay[] listXeHoaBinh;

    public XeMayHoaBinh() {
    }

    public XeMayHoaBinh(int n, XeMay[] listXe) {
        this.n = n;
        this.listXeHoaBinh = listXe;
    }

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

    public int getN() {
        return n;
    }

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

    public XeMay[] getListXe() {
        return listXeHoaBinh;
    }

    public void setListXe(XeMay[] listXe) {
        this.listXeHoaBinh = listXe;
    }
    
    @Override
    public void nhap() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap n=");
        n=Integer.parseInt(input.nextLine());
        listXeHoaBinh = new XeMay[n];
        for(int i=0;i<n;i++){
            System.out.println("\nXe thu "+(i+1));
            listXeHoaBinh[i] = new XeMay();
            listXeHoaBinh[i].nhap();
        }
    }

    @Override
    public void hienthi() {
        for(int i=0;i<n;i++){
            System.out.println("\nXe thu "+(i+1));
            listXeHoaBinh[i].hienthi();
        }
    }
    
    
}



package hanoi.xemay;

import java.util.Scanner;
import xeco.info.XeMay;

public class XeMayHaNoi extends XeMay{
    int n;
    XeMay[] listXeHaNoi;

    public XeMayHaNoi() {
    }

    public XeMayHaNoi(int n, XeMay[] listXe) {
        this.n = n;
        this.listXeHaNoi = listXe;
    }

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

    public int getN() {
        return n;
    }

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

    public XeMay[] getListXe() {
        return listXeHaNoi;
    }

    public void setListXe(XeMay[] listXe) {
        this.listXeHaNoi = listXe;
    }
    
    @Override
    public void nhap() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap n=");
        this.n=input.nextInt();
        this.listXeHaNoi = new XeMay[n];
        for(int i=0;i<n;i++){
            System.out.println("\nXe thu "+(i+1));
            listXeHaNoi[i] = new XeMay();
            listXeHaNoi[i].nhap();
        }
    }

    @Override
    public void hienthi() {
        for(int i=0;i<n;i++){
            System.out.println("\nXe thu "+(i+1));
            listXeHaNoi[i].hienthi();
        }
    }
    
}



package quanlychung.xemay;

import xeco.info.XeMay;
import hanoi.xemay.XeMayHaNoi;
import hoabinh.xemay.XeMayHoaBinh;
import java.util.Scanner;

public class QuanLyChung {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        XeMayHaNoi hn = new XeMayHaNoi();
        XeMayHoaBinh hb = new XeMayHoaBinh();
        while(true){
            showmenu();
            System.out.print("Chon: ");
            int choose = Integer.parseInt(input.nextLine());
            switch(choose){
                case 1:
                    hb.nhap();
                    hb.hienthi();
                    break;
                case 2:
                    hn.nhap();
                    hn.hienthi();
                    break;
                case 3:
                    for(int i=0;i<hn.getListXe().length-1;i++){
                        for(int j=i+1;j<hn.getListXe().length;j++){
                            if(hn.getListXe()[i].getBienso().compareTo(hn.getListXe()[j].getBienso())>0){
                               XeMay tmp = hn.getListXe()[i];
                               hn.getListXe()[i] = hn.getListXe()[j];
                               hn.getListXe()[j] = tmp;
                            }
                        }
                    }
                    for(int i=0;i<hb.getListXe().length-1;i++){
                        for(int j=i+1;j<hb.getListXe().length;j++){
                            if(hb.getListXe()[i].getBienso().compareTo(hb.getListXe()[j].getBienso())>0){
                               XeMay tmp = hb.getListXe()[i];
                               hb.getListXe()[i] = hb.getListXe()[j];
                               hb.getListXe()[j] = tmp;
                            }
                        }
                    }
                    System.out.println("Sau sap xep Xe Hoa Binh");
                    hb.hienthi();
                    System.out.println("Sau sap xep Xe Hoa Binh");
                    hn.hienthi();
                    break;
                case 4:
                    int dk=1;
                    System.out.println("Ban muon tim o dau?\n1.HaNoi\n2.HoaBinh");
                    int choice = Integer.parseInt(input.nextLine());
                    System.out.println("Nhap vao bien so:");
                    String find=input.nextLine();
                    if(choice==1){
                        for(int i=0;i<hn.getListXe().length;i++){
                            if(hn.getListXe()[i].getBienso().equals(find)){
                                dk=0;
                                System.out.println("da tim thay!!");
                                System.out.println("bienso la: "+hn.getListXe()[i].getBienso());
                                System.out.println("loaixe la: "+hn.getListXe()[i].getLoaixe());
                                System.out.println("mauxe la: "+hn.getListXe()[i].getMauxe());
                                System.out.println("giatien la: "+hn.getListXe()[i].getGiatien());
                            }
                        }
                    }else{
                        for(int i=0;i<hb.getListXe().length;i++){
                            if(hb.getListXe()[i].getBienso().equals(find)){
                                dk=0;
                                System.out.println("da tim thay!!");
                                System.out.println("bienso la: "+hb.getListXe()[i].getBienso());
                                System.out.println("loaixe la: "+hb.getListXe()[i].getLoaixe());
                                System.out.println("mauxe la: "+hb.getListXe()[i].getMauxe());
                                System.out.println("giatien la: "+hb.getListXe()[i].getGiatien());
                            }
                        }
                    }
                    if(dk==1){
                        System.out.println("Khong co xe nhu vay trong khu vuc");
                    }
                    break;
                case 5:
                    if(hn.getListXe().length!=0){
                        System.out.println("Co "+hn.getListXe().length+" xe o Hanoi");
                    }else{
                        System.out.println("Ko co xe nao o Hanoi");
                    }
                    if(hb.getListXe().length!=0){
                        System.out.println("Co "+hb.getListXe().length+" xe o Hoa Binh");
                    }else{
                        System.out.println("Ko co xe nao o Hoa Binh");
                    }
                    
                    break;
                default:
                    System.exit(0);
                    break;
            }
        }
    }
    
    static void showmenu(){
        System.out.println("\n1. 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");
    }
    
}