By GokiSoft.com| 20:16 26/04/2024|
Java Basic

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

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

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

5

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

Nguyễn Hoàng Anh [C1907L]
Nguyễn Hoàng Anh

2020-04-02 05:33:54



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

/**
 *
 * @author Redmibook 14
 */
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 April2.VehicleManager;

/**
 *
 * @author Redmibook 14
 */
public class XeMay implements Ixe {

    String bienso;

    String loaixe;

    String mauxe;

    float giatien;

    @Override
    public void nhap() {

    }
    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 hienthi() {
        System.out.println("Bien so : " + bienso);
        System.out.println("Loai xe : "+loaixe);
        System.out.println("Mau xe : "+mauxe);
        System.out.println("Gia tien : "+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 April2.VehicleManager;

import java.util.*;

/**
 *
 * @author Redmibook 14
 */
public class XeMayHoaBinh extends XeMay {

    int n;
    XeMay[] arrXeMay;
    Scanner input = new Scanner(System.in);

    @Override
    public void nhap() {
        System.out.println("Nhap so luong xe : ");
        n = Integer.parseInt(input.nextLine());
        arrXeMay = new XeMay[n];
        for (int i = 0; i < n; i++) {
            System.out.println("Nhap thong tin xe " + (i + 1));
            System.out.println("Nhap bien so : ");
            String bien = input.nextLine();
            System.out.println("Nhap loai xe : ");
            String loai = input.nextLine();
            System.out.println("Nhap mau xe : ");
            String mau = input.nextLine();
            System.out.println("Nhap gia tien : ");
            float gia = Float.parseFloat(input.nextLine());
            arrXeMay[i] = new XeMay(bien, loai, mau, gia);
        }
    }

    @Override
    public void hienthi() {
        System.out.println("Bien so : " + bienso);
        System.out.println("Loai xe : " + loaixe);
        System.out.println("Mau xe : " + mauxe);
        System.out.println("Gia tien : " + 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 April2.VehicleManager;

import java.util.Scanner;

/**
 *
 * @author Redmibook 14
 */
public class XeMayHaNoi extends XeMay {

    int n;
    XeMay[] arrXeMay;
    Scanner input = new Scanner(System.in);

    @Override
    public void nhap() {
        System.out.println("Nhap so luong xe : ");
        n = Integer.parseInt(input.nextLine());
        arrXeMay = new XeMay[n];
        for (int i = 0; i < n; i++) {
            System.out.println("Nhap thong tin xe " + (i + 1));
            System.out.println("Nhap bien so : ");
            String bien = input.nextLine();
            System.out.println("Nhap loai xe : ");
            String loai = input.nextLine();
            System.out.println("Nhap mau xe : ");
            String mau = input.nextLine();
            System.out.println("Nhap gia tien : ");
            float gia = Float.parseFloat(input.nextLine());
            arrXeMay[i] = new XeMay(bien, loai, mau, gia);
        }
    }

    @Override
    public void hienthi() {
        System.out.println("Bien so : " + bienso);
        System.out.println("Loai xe : " + loaixe);
        System.out.println("Mau xe : " + mauxe);
        System.out.println("Gia tien : " + 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 April2.VehicleManager;

import java.util.*;

/**
 *
 * @author Redmibook 14
 */
public class QuanLyChung {

    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");
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        XeMayHoaBinh xemayhb = new XeMayHoaBinh();
        XeMayHaNoi xemayhn = new XeMayHaNoi();
        while (true) {
            menu();
            int choice = Integer.parseInt(input.nextLine());
            switch (choice) {
                case 1:
                    xemayhb.nhap();
                    break;
                case 2:
                    xemayhn.nhap();
                    break;
                case 3:
                    if (xemayhb.arrXeMay != null) {
                        System.out.println("Xe may Hoa Binh : ");
                        for (int i = 0; i < xemayhb.arrXeMay.length; i++) {
                            for (int j = 0; j < xemayhb.arrXeMay.length; j++) {
                                XeMay temp;
                                if (xemayhb.arrXeMay[i].bienso.compareTo(xemayhb.arrXeMay[j].bienso) == -1) {
                                    temp = xemayhb.arrXeMay[i];
                                    xemayhb.arrXeMay[i] = xemayhb.arrXeMay[j];
                                    xemayhb.arrXeMay[j] = temp;
                                }
                            }
                        }
                        for (int i = 0; i < xemayhb.arrXeMay.length; i++) {
                            xemayhb.arrXeMay[i].hienthi();
                        }
                    }
                    if (xemayhn.arrXeMay != null) {
                        System.out.println("Xe may Ha Noi : ");
                        for (int i = 0; i < xemayhn.arrXeMay.length; i++) {
                            for (int j = 0; j < xemayhn.arrXeMay.length; j++) {
                                XeMay temp;
                                if (xemayhn.arrXeMay[i].bienso.compareTo(xemayhn.arrXeMay[j].bienso) == -1) {
                                    temp = xemayhn.arrXeMay[i];
                                    xemayhn.arrXeMay[i] = xemayhn.arrXeMay[j];
                                    xemayhn.arrXeMay[j] = temp;
                                }
                            }
                        }
                        for (int i = 0; i < xemayhn.arrXeMay.length; i++) {
                            xemayhn.arrXeMay[i].hienthi();
                        }
                    } else {
                        System.out.println("Chua co thong ke nao!");
                    }
                    break;
                case 4:
                    System.out.println("Nhap vao bien so xe : ");
                    String bien = input.nextLine();
                    int flag = 0;
                    if (xemayhb.arrXeMay != null) {
                        for (int i = 0; i < xemayhb.arrXeMay.length; i++) {
                            if (xemayhb.arrXeMay[i].bienso.compareTo(bien) == 0) {
                                xemayhb.arrXeMay[i].hienthi();
                                flag++;
                            }
                        }
                    }
                    if (xemayhn.arrXeMay != null) {
                        for (int i = 0; i < xemayhn.arrXeMay.length; i++) {
                            if (xemayhn.arrXeMay[i].bienso.compareTo(bien) == 0) {
                                xemayhn.arrXeMay[i].hienthi();
                                flag++;
                            }
                        }
                    }
                    if (flag == 0) {
                        System.out.println("Khong co bien so xe nay. ");
                    }

                    break;
                case 5:
                    if (xemayhb.arrXeMay != null) {
                        System.out.println("Co " + xemayhb.arrXeMay.length + " xe may o Hoa Binh");
                    } if (xemayhn.arrXeMay != null) {
                        System.out.println("Co " + xemayhn.arrXeMay.length + " xe may o Ha Noi");
                    } else {
                        System.out.println("Chua co thong ke nao!");
                    }
                    break;
                case 6:
                    return;

            }
        }

    }
}