Java basic- Assignment - Quản lý xe cộ
* Tạo một giao diện IXe nằm trong gói xeco.info gồm có 2 phương thức:
- public void nhap();
- public void hienthi();
* Tạo Lớp XeMay cũng nằm trong gói xeco.info thực thi giao diện IXe và có các thuộc tính sau:
String bienso;
String loaixe;
String mauxe;
float giatien;
Cài đặt Constructor, các phương thức set/get và Override các phương thức trong giao diện IXe.
* Tạo lớp XeMayHoaBinh nằm trong gói hoabinh.xemay kế thừa lớp IXe. Bổ sung thêm thuộc tính:
- n (kiểu int) : Dùng để nhập vào số lượng xe
- Một mảng n phần tử kiểu XeMay dùng để lưu thông tin của n xe máy đang quản lý tại tỉnh Hòa Bình.
Cài đặt constructor, override tất cả các phương thức trong lớp IXe. Phương thức nhập phải nhập vào số lượng xe và gọi nhập thông tin của n xe đó.
* Tạo lớp XeMayHaNoi nằm trong gói hanoi.xemay kế thừa lớp XeMay. Bổ sung thêm thuộc tính:
- n (kiểu int) : Dùng để nhập vào số lượng xe
- Một mảng n phần tử kiểu XeMay dùng để lưu thông tin của n xe máy đang quản lý tại tỉnh Hà Nội.
Cài đặt constructor, override tất cả các phương thức trong lớp XeMay. Phương thức nhập phải nhập vào số lượng xe và gọi nhập thông tin của n xe đó.
* Tạo lớp QuanLyChung nằm trong gói quanlychung.xemay, có menu như sau:
1. Nhập thông tin cho n xe máy tại tỉnh Hòa Bình.
2. Nhập thông tin cho n xe máy tại tỉnh Hà Nội.
3. Sắp xếp danh sách tăng theo biển số xe.
4. Tìm kiếm thông tin xe theo biển số xe.
5. Thống kê số lượng xe đang quản lý.
6. Thoát
- Yêu cầu:
o Sau khi người sử dụng chọn chức năng 3, 4, 5 sẽ đưa ra thông báo nhập vào tỉnh cần thực hiện (Hòa Bình hoặc Hà Nội).
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)

Tran Ba Quan
2024-05-13 12:33:55
#XeMayHaNoi.java
package hanoi.xemay;
import xeco.info.*;
import java.util.*;
public class XeMayHaNoi extends XeMay {
private int n;
private XeMay[] xeMays;
public XeMayHaNoi(String bienso, String loaixe, String mauxe, float giatien, int n) {
super(bienso, loaixe, mauxe, giatien);
this.n = n;
this.xeMays = new XeMay[n];
}
@Override
public void nhap() {
Scanner sc = new Scanner(System.in);
System.out.println("Nhập số lượng xe: ");
this.n = sc.nextInt();
sc.nextLine();
this.xeMays = new XeMay[n];
for (int i = 0; i < this.n; i++) {
System.out.println("Nhập thông tin xe thứ " + (i + 1) + ": ");
System.out.println("Nhập các thông tin của xe máy");
System.out.println("Nhập biển số xe: ");
String bienso = sc.nextLine();
System.out.println("Nhập loại xe: ");
String loaixe = sc.nextLine();
System.out.println("Nhập màu xe: ");
String mauxe = sc.nextLine();
System.out.println("Nhập giá tiền của xe: ");
float giatien = sc.nextFloat();
sc.nextLine();
this.xeMays[i] = new XeMay(bienso, loaixe, mauxe, giatien);
}
Arrays.sort(this.xeMays, Comparator.comparing(XeMay::getBienso));
}
public XeMay timkiem(String bienso) {
int left = 0, right = this.n - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
int res = bienso.compareTo(this.xeMays[mid].getBienso());
if (res == 0)
return this.xeMays[mid];
if (res > 0)
left = mid + 1;
else
right = mid - 1;
}
return null;
}
public int thongke() {
return this.n;
}
@Override
public void hienthi() {
super.hienthi();
for (int i = 0; i < this.n; i++) {
System.out.println("Thông tin xe thứ " + (i + 1) + ": ");
this.xeMays[i].hienthi();
}
}
}
#XeMayHoaBinh.java
package hoabinh.xemay;
import xeco.info.*;
import java.util.*;
public class XeMayHoaBinh extends XeMay {
private int n;
private XeMay[] xeMays;
public XeMayHoaBinh(String bienso, String loaixe, String mauxe, float giatien, int n) {
super(bienso, loaixe, mauxe, giatien);
this.n = n;
this.xeMays = new XeMay[n];
}
@Override
public void nhap() {
Scanner sc = new Scanner(System.in);
System.out.println("Nhập số lượng xe: ");
this.n = sc.nextInt();
sc.nextLine();
this.xeMays = new XeMay[n];
for (int i = 0; i < this.n; i++) {
System.out.println("Nhập thông tin xe thứ " + (i + 1) + ": ");
System.out.println("Nhập các thông tin của xe máy");
System.out.println("Nhập biển số xe: ");
String bienso = sc.nextLine();
System.out.println("Nhập loại xe: ");
String loaixe = sc.nextLine();
System.out.println("Nhập màu xe: ");
String mauxe = sc.nextLine();
System.out.println("Nhập giá tiền của xe: ");
float giatien = sc.nextFloat();
sc.nextLine();
this.xeMays[i] = new XeMay(bienso, loaixe, mauxe, giatien);
}
Arrays.sort(this.xeMays, Comparator.comparing(XeMay::getBienso));
}
public XeMay timkiem(String bienso) {
int left = 0, right = this.n - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
int res = bienso.compareTo(this.xeMays[mid].getBienso());
if (res == 0)
return this.xeMays[mid];
if (res > 0)
left = mid + 1;
else
right = mid - 1;
}
return null;
}
public int thongke() {
return this.n;
}
@Override
public void hienthi() {
super.hienthi();
for (int i = 0; i < this.n; i++) {
System.out.println("Thông tin xe thứ " + (i + 1) + ": ");
this.xeMays[i].hienthi();
}
}
}
#QuanLyChung.java
package quanlychung.xemay;
import hoabinh.xemay.*;
import hanoi.xemay.*;
import java.util.*;
import xeco.info.*;
public class QuanLyChung {
private XeMayHoaBinh hb;
private XeMayHaNoi hn;
public void menu() {
System.out.println("1. Nhập thông tin cho n xe máy tại tỉnh Hòa Bình.");
System.out.println("2. Nhập thông tin cho n xe máy tại tỉnh Hà Nội.");
System.out.println("3. Sắp xếp danh sách tăng theo biển số xe.");
System.out.println("4. Tìm kiếm thông tin xe theo biển số xe.");
System.out.println("5. Thống kê số lượng xe đang quản lý.");
System.out.println("6. Thoát.");
System.out.println("Nhập lựa chọn của bạn: ");
}
public void run() {
Scanner sc = new Scanner(System.in);
int opt = sc.nextInt();
sc.nextLine();
do {
menu();
switch (opt) {
case 1:
hb.nhap();
break;
case 2:
hn.nhap();
break;
case 3:
System.out.println("Nhập tỉnh: ");
sc.nextLine();
System.out.println("Đã được xắp xếp");
break;
case 4:
System.out.println("Nhập tỉnh: ");
sc.nextLine();
System.out.println("Đã được xắp xếp");
break;
case 5:
System.out.println("Nhập tỉnh");
if (sc.nextLine() == "hanoi") {
System.out.println("Nhập biển số");
XeMay xm = hn.timkiem(sc.nextLine());
if (xm == null) {
System.out.println("Không có trong danh sách");
} else {
xm.hienthi();
}
} else {
System.out.println("Nhập biển số");
XeMay xm = hb.timkiem(sc.nextLine());
if (xm == null) {
System.out.println("Không có trong danh sách");
} else {
xm.hienthi();
}
}
}
} while (opt != 6);
}
}
#IXe.java
package xeco.info;
import java.util.*;
public interface IXe {
public void nhap();
public void hienthi();
}
#XeMay.java
package xeco.info;
import java.util.*;
public class XeMay implements IXe {
private String bienso;
private String loaixe;
private String mauxe;
private float giatien;
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("Nhập các thông tin của xe máy");
System.out.println("Nhập biển số xe: ");
setBienso(sc.nextLine());
System.out.println("Nhập loại xe: ");
setLoaixe(sc.nextLine());
System.out.println("Nhập màu xe: ");
setMauxe(sc.nextLine());
System.out.println("Nhập giá tiền của xe: ");
setGiatien(sc.nextFloat());
sc.nextLine();
}
@Override
public void hienthi() {
System.out.println("Thông tin của xe máy: ");
System.out.println("Biển số xe: " + getBienso());
System.out.println("Loại xe: " + getLoaixe());
System.out.println("Màu xe: " + getMauxe());
System.out.println("Giá tiền của xe: " + getGiatien());
}
}

Nguyen Thanh Do
2024-05-13 12:23:23
#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.ArrayList;
import java.util.Scanner;
import xeco.info.XeMay;
/**
*
* @author MacAir
*/
public class XeMayHaNoi extends XeMay{
Scanner sc = new Scanner(System.in);
int n;
ArrayList<XeMay> xeMayHNList = new ArrayList<>();
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;
}
@Override
public void nhap(){
System.out.println("Nhap so luong xe may HN");
n = Integer.parseInt(sc.nextLine());
for (int i = 0; i < n; i++) {
XeMay xeMayHB = new XeMay();
xeMayHB.nhap();
xeMayHNList.add(xeMayHB);
}
}
@Override
public void hienthi(){
System.out.println("Danh sach xe may HN");
for (int i = 0; i < xeMayHNList.size(); i++) {
xeMayHNList.get(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 hoabinh.xemay;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import xeco.info.XeMay;
/**
*
* @author MacAir
*/
public class XeMayHoaBinh extends XeMay{
Scanner sc = new Scanner(System.in);
int n;
ArrayList<XeMay> xeMayHBList = new ArrayList<>();
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;
}
@Override
public void nhap(){
System.out.println("Nhap so luong xe may HB");
n = Integer.parseInt(sc.nextLine());
for (int i = 0; i < n; i++) {
XeMay xeMayHB = new XeMay();
xeMayHB.nhap();
xeMayHBList.add(xeMayHB);
}
}
@Override
public void hienthi(){
System.out.println("Danh sach xe may HB");
for (int i = 0; i < xeMayHBList.size(); i++) {
xeMayHBList.get(i).hienthi();
}
}
public void sort(){
Collections.sort(xeMayHBList, new Comparable<XeMay>){
@Override
}
}
public void search(){}
public void count(){}
}
#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 quanluchung.xemay;
/**
*
* @author MacAir
*/
public class QuanLyChung {
}
#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 MacAir
*/
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 MacAir
*/
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 = sc.nextFloat();
}
@Override
public void hienthi() {
System.out.println(this);
}
@Override
public String toString() {
return "XeMay{" + "bienso=" + bienso + ", loaixe=" + loaixe + ", mauxe=" + mauxe + ", giatien=" + giatien + '}';
}
}

Nguyễn Hùng
2024-05-13 12:22:07
#Main.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.hung.project;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
/**
*
* @author ADMIN
*/
public class Main {
public static Scanner scan = new Scanner(System.in);
public static ArrayList<XeMay> xehoabinhList = new ArrayList<>();
public static ArrayList<XeMay> xehanoiList = new ArrayList<>();
public static void menu() {
System.out.println("""
Menu:
1. Nhap thong tin cho n xe may tai tinh Hoa Bnh
2. Nhap thong tin cho n xe may tai tinh Ha Noi
3. Sap xep danh sach theo bien so xe
4. Tim kiem thong tin xe theo bien so xe
5. Thong ke so luong xe dang quan ly
6. Thoat
Lua chon:
""");
}
//
// public static void sapxepBSX() {
// Collections.sort(xemayList, (XeMay o1, XeMay o2) -> o1.getBienso().compareTo(o2.getBienso()));
// for (XeMay item : xemayList) {
// item.hienthi();
// }
// }
public static void timkienXe() {
String s;
System.out.println("Nhap bien so xe muon tim:");
s = scan.nextLine();
for (XeMay item : xehoabinhList) {
if (item.getBienso().equals(s)) {
item.hienthi();
}
}
for (XeMay item : xehanoiList) {
if (item.getBienso().equals(s)) {
item.hienthi();
}
}
}
public static void soluongXe() {
int a= xehoabinhList.size(), b = xehanoiList.size();
System.out.println("Co" + (a+b) + "xe");
}
public static void main(String[] args) {
int t = 0;
while (t != 6) {
menu();
t = Integer.parseInt(scan.nextLine());
switch (t) {
case 1 -> {
XeMayHoaBinh xeMayHoaBinh = new XeMayHoaBinh();
xeMayHoaBinh.nhap();
xehoabinhList.add(xeMayHoaBinh);
}
case 2 -> {
XeMayHaNoi xeMayHaNoi = new XeMayHaNoi();
xeMayHaNoi.nhap();
xehanoiList.add(xeMayHaNoi);
}
// case 3 -> sapxepBSX();
case 4 -> timkienXe();
case 5 -> soluongXe();
case 6 -> System.out.println("Thoat!!");
default -> System.out.println("Nhap lai");
}
}
}
}
#IXe.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.hung.project;
/**
*
* @author ADMIN
*/
public interface IXe {
public void nhap();
public void hienthi();
}
#XeMayHaNoi.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.hung.project;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
*
* @author ADMIN
*/
public class XeMayHaNoi extends XeMay{
int n;
ArrayList<XeMay> xehanoiList = new ArrayList<>();
@Override
public void nhap() {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap so luong xe:");
n = Integer.parseInt(scan.nextLine());
for(int i = 0; i < n; i++) {
System.out.println("Nhap xe so" + (i+1));
XeMay xemay = new XeMay();
xemay.nhap();
xehanoiList.add(xemay);
}
}
@Override
public void hienthi() {
for (XeMay item : xehanoiList) {
item.hienthi();
}
}
}
#XeMayHoaBinh.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.hung.project;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
*
* @author ADMIN
*/
public class XeMayHoaBinh extends XeMay{
int n;
ArrayList<XeMay> xehoabinhList = new ArrayList<>();
@Override
public void nhap() {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap so luong xe:");
n = Integer.parseInt(scan.nextLine());
for(int i = 0; i < n; i++) {
System.out.println("Nhap xe so" + (i+1));
XeMay xemay = new XeMay();
xemay.nhap();
xehoabinhList.add(xemay);
}
}
@Override
public void hienthi() {
for (XeMay item : xehoabinhList) {
item.hienthi();
}
}
}
#XeMay.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.hung.project;
import java.util.Scanner;
/**
*
* @author ADMIN
*/
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 String getLoaixe() {
return loaixe;
}
public void setLoaixe(String loaixe) {
this.loaixe = loaixe;
}
public String getMauxe() {
return mauxe;
}
public void setMauxe(String mauxe) {
this.mauxe = mauxe;
}
public float getGiatien() {
return giatien;
}
public void setGiatien(float giatien) {
this.giatien = giatien;
}
@Override
public String toString() {
return "bienso=" + bienso + ", loaixe=" + loaixe + ", mauxe=" + mauxe + ", 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(toString());
}
}

Đỗ Quốc Dũng
2024-05-13 12:08:55
#IXe.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package xeco.info;
/**
*
* @author ASUS
*/
public interface IXe {
public void nhap();
public void hienthi();
}
#XeMay.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package xeco.info;
import java.util.Scanner;
/**
*
* @author ASUS
*/
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 scanner = new Scanner(System.in);
System.out.println("Nhap bien so xe: ");
bienso = scanner.nextLine();
System.out.println("Nhap loai xe: ");
loaixe = scanner.nextLine();
System.out.println("Nhap mau xe: ");
mauxe = scanner.nextLine();;
System.out.println("Nhap gia tien: ");
giatien = scanner.nextFloat();
}
@Override
public void hienthi() {
System.out.println("Bien so xe: "+bienso);
System.out.println("Loai xe: "+loaixe);
System.out.println("Mau xe: "+mauxe);
System.out.println("Gia tien: "+giatien);
}
}
#QuanLyChung.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package quanlychung.xemay;
import hanoi.xemay.XeMayHaNoi;
import hoabinh.xemay.XeMayHoaBinh;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import xeco.info.XeMay;
/**
*
* @author ASUS
*/
public class QuanLyChung {
static XeMayHaNoi xeMayHaNoi = new XeMayHaNoi();
static XeMayHoaBinh xeMayHoaBinh = new XeMayHoaBinh();
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int choose;
List<XeMay> list;
do{
showMenu();
choose = Integer.parseInt(scanner.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 = getXemayByState();
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 = getXemayByState();
System.out.println("Nhap bien so xe can tim kiem: ");
String bienso = scanner.nextLine();
boolean found = false;
for (XeMay xeMay : list) {
if(xeMay.getBienso().equalsIgnoreCase(bienso)){
System.out.println("Thong tin tim duoc bien so la");
xeMay.hienthi();
found = true;
break;
}
}
if(!found){
System.out.println("Khong tim thay xe voi bien so" +bienso);
}
break;
case 5:
System.out.println("Lua chon tinh can xem thong ke: ");
list = getXemayByState();
System.out.println("Tong so xe: "+list.size());
break;
case 6:
System.out.println("Thoat !!!");
return;
default:
System.out.println("Nhap sai lua chon !!!");
break;
}
}while(choose != 6);
}
static void showMenu(){
System.out.println("Menu");
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> getXemayByState(){
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(scanner.nextLine());
switch (option) {
case 1:
list = Arrays.asList(xeMayHaNoi.getXemayList());
break;
default:
list = Arrays.asList(xeMayHoaBinh.getXemayList());
break;
}
return list;
}
}
#XeMayHaNoi.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package hanoi.xemay;
import xeco.info.IXe;
import java.util.Scanner;
import xeco.info.XeMay;
/**
*
* @author ASUS
*/
public class XeMayHaNoi implements IXe{
int n;
XeMay[] xemayList;
public XeMayHaNoi() {
}
public XeMayHaNoi(int n, XeMay[] xemayList) {
this.n = n;
this.xemayList = xemayList;
}
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 scanner = new Scanner(System.in);
System.out.println("Nhap so xe may can quan ly tai tinh Ha Noi: ");
n = Integer.parseInt(scanner.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 Ha Noi");
for(int i =0; i<n;i++){
xemayList[i].hienthi();
}
}
}
#XeMayHoaBinh.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package hoabinh.xemay;
import xeco.info.IXe;
import java.util.Scanner;
import xeco.info.XeMay;
/**
*
* @author ASUS
*/
public class XeMayHoaBinh implements IXe{
int n;
XeMay[] xemayList;
public XeMayHoaBinh(int n, XeMay[] xemayList) {
this.n = n;
this.xemayList = 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 scanner = new Scanner(System.in);
System.out.println("Nhap so xe may can quan ly tai tinh Hoa Binh: ");
n = Integer.parseInt(scanner.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();
}
}
}

Đỗ Quốc Dũng
2024-05-13 12:08:53
#IXe.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package xeco.info;
/**
*
* @author ASUS
*/
public interface IXe {
public void nhap();
public void hienthi();
}
#XeMay.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package xeco.info;
import java.util.Scanner;
/**
*
* @author ASUS
*/
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 scanner = new Scanner(System.in);
System.out.println("Nhap bien so xe: ");
bienso = scanner.nextLine();
System.out.println("Nhap loai xe: ");
loaixe = scanner.nextLine();
System.out.println("Nhap mau xe: ");
mauxe = scanner.nextLine();;
System.out.println("Nhap gia tien: ");
giatien = scanner.nextFloat();
}
@Override
public void hienthi() {
System.out.println("Bien so xe: "+bienso);
System.out.println("Loai xe: "+loaixe);
System.out.println("Mau xe: "+mauxe);
System.out.println("Gia tien: "+giatien);
}
}
#QuanLyChung.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package quanlychung.xemay;
import hanoi.xemay.XeMayHaNoi;
import hoabinh.xemay.XeMayHoaBinh;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import xeco.info.XeMay;
/**
*
* @author ASUS
*/
public class QuanLyChung {
static XeMayHaNoi xeMayHaNoi = new XeMayHaNoi();
static XeMayHoaBinh xeMayHoaBinh = new XeMayHoaBinh();
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int choose;
List<XeMay> list;
do{
showMenu();
choose = Integer.parseInt(scanner.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 = getXemayByState();
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 = getXemayByState();
System.out.println("Nhap bien so xe can tim kiem: ");
String bienso = scanner.nextLine();
boolean found = false;
for (XeMay xeMay : list) {
if(xeMay.getBienso().equalsIgnoreCase(bienso)){
System.out.println("Thong tin tim duoc bien so la");
xeMay.hienthi();
found = true;
break;
}
}
if(!found){
System.out.println("Khong tim thay xe voi bien so" +bienso);
}
break;
case 5:
System.out.println("Lua chon tinh can xem thong ke: ");
list = getXemayByState();
System.out.println("Tong so xe: "+list.size());
break;
case 6:
System.out.println("Thoat !!!");
return;
default:
System.out.println("Nhap sai lua chon !!!");
break;
}
}while(choose != 6);
}
static void showMenu(){
System.out.println("Menu");
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> getXemayByState(){
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(scanner.nextLine());
switch (option) {
case 1:
list = Arrays.asList(xeMayHaNoi.getXemayList());
break;
default:
list = Arrays.asList(xeMayHoaBinh.getXemayList());
break;
}
return list;
}
}
#XeMayHaNoi.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package hanoi.xemay;
import xeco.info.IXe;
import java.util.Scanner;
import xeco.info.XeMay;
/**
*
* @author ASUS
*/
public class XeMayHaNoi implements IXe{
int n;
XeMay[] xemayList;
public XeMayHaNoi() {
}
public XeMayHaNoi(int n, XeMay[] xemayList) {
this.n = n;
this.xemayList = xemayList;
}
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 scanner = new Scanner(System.in);
System.out.println("Nhap so xe may can quan ly tai tinh Ha Noi: ");
n = Integer.parseInt(scanner.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 Ha Noi");
for(int i =0; i<n;i++){
xemayList[i].hienthi();
}
}
}
#XeMayHoaBinh.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package hoabinh.xemay;
import xeco.info.IXe;
import java.util.Scanner;
import xeco.info.XeMay;
/**
*
* @author ASUS
*/
public class XeMayHoaBinh implements IXe{
int n;
XeMay[] xemayList;
public XeMayHoaBinh(int n, XeMay[] xemayList) {
this.n = n;
this.xemayList = 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 scanner = new Scanner(System.in);
System.out.println("Nhap so xe may can quan ly tai tinh Hoa Binh: ");
n = Integer.parseInt(scanner.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();
}
}
}
![Hoang Ngo [T1907A]](https://www.gravatar.com/avatar/9f7d962f002d4b5c555b1ee25b3622ff.jpg?s=80&d=mm&r=g)
Hoang Ngo
2020-04-10 08:06:29
/*
* 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 Administrator
*/
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 input(){
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 display(){
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 xeco.info;
/**
*
* @author Administrator
*/
public interface IXe {
public void input();
public void display();
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package quanlichung.xemay;
import hanoi.xemay.XeMayHaNoi;
import hoabinh.xemay.XeMayHoaBinh;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author Administrator
*/
public class QuanLyChung {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int choose,n;
ArrayList<XeMayHoaBinh> HBList = new ArrayList<>();
ArrayList<XeMayHaNoi> HNList = new ArrayList<>();
XeMayHoaBinh xmhb = new XeMayHoaBinh();
XeMayHaNoi xmhn = new XeMayHaNoi();
do{
menu();
choose = Integer.parseInt(scan.nextLine());
switch(choose){
case 1:
xmhb.input();
break;
case 2:
xmhn.input();
break;
case 3:
System.out.println("1. Hoa Binh");
System.out.println("2. Ha Noi");
System.out.println("Choose:");
n = Integer.parseInt(scan.nextLine());
switch(choose){
case 1:
xmhb.sort();
break;
case 2:
xmhn.sort();
break;
default:
break;
}
break;
case 4:
System.out.println("1. Hoa Binh");
System.out.println("2. Ha Noi");
System.out.println("Choose:");
n = Integer.parseInt(scan.nextLine());
switch(choose){
case 1:
xmhb.search();
break;
case 2:
xmhn.search();
break;
default:
break;
}
break;
case 5:
System.out.println("1. Hoa Binh");
System.out.println("2. Ha Noi");
System.out.println("Choose:");
n = Integer.parseInt(scan.nextLine());
switch(choose){
case 1:
xmhb.thongKeSL();
break;
case 2:
xmhn.thongKeSL();
break;
default:
break;
}
break;
case 6:
System.out.println("Thoat.");
break;
default:
System.out.println("INPUT FAILED !!!");
break;
}
}while(choose != 6);
}
public static void menu(){
System.out.println("1. Nhập thông tin cho n xe máy tại tỉnh Hòa Bình.");
System.out.println("2. Nhập thông tin cho n xe máy tại tỉnh Hà Nội.");
System.out.println("3. Sắp xếp danh sách tăng theo biển số xe.");
System.out.println("4. Tìm kiếm thông tin xe theo biển số xe.");
System.out.println("5. Thống kê số lượng xe đang quản lý.");
System.out.println(" 6. Thoát");
}
}
/*
* 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.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import xeco.info.XeMay;
/**
*
* @author Administrator
*/
public class XeMayHoaBinh extends XeMay{
Scanner scan = new Scanner(System.in);
int n;
ArrayList<XeMay> xeMayHBList = new ArrayList<>();
public XeMayHoaBinh() {
}
public XeMayHoaBinh(int n, String bienso, String loaixe, String mauxe, float giatien) {
super(bienso, loaixe, mauxe, giatien);
this.n = n;
}
@Override
public void input(){
System.out.println("Nhap so luong xe may HB:");
n = Integer.parseInt(scan.nextLine());
for (int i = 0; i < n; i++) {
XeMay xemayhb = new XeMay();
xemayhb.input();
xeMayHBList.add(xemayhb);
}
}
@Override
public void display(){
System.out.println("Danh sach xe may HB");
for (int i = 0; i < xeMayHBList.size(); i++) {
xeMayHBList.get(i).display();
}
}
public void sort(){
Collections.sort(xeMayHBList, new Comparator<XeMay>() {
@Override
public int compare(XeMay o1, XeMay o2) {
if(o1.getBienso().equalsIgnoreCase(o2.getBienso())){
return 1;
}return -1;
}
});
display();
}
public void search(){
System.out.println("Nhap bien so xe can tim:");
String bienSo = scan.nextLine();
for (int i = 0; i < xeMayHBList.size(); i++) {
if(xeMayHBList.get(i).getBienso().equalsIgnoreCase(bienSo)){
xeMayHBList.get(i).display();
}
}
}
public void thongKeSL(){
System.out.println("So luong xe quan ly tai HB :" + xeMayHBList.size());
}
}
![Hoang Ngo [T1907A]](https://www.gravatar.com/avatar/9f7d962f002d4b5c555b1ee25b3622ff.jpg?s=80&d=mm&r=g)
Hoang Ngo
2020-04-10 08:06:28
/*
* 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 Administrator
*/
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 input(){
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 display(){
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 xeco.info;
/**
*
* @author Administrator
*/
public interface IXe {
public void input();
public void display();
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package quanlichung.xemay;
import hanoi.xemay.XeMayHaNoi;
import hoabinh.xemay.XeMayHoaBinh;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author Administrator
*/
public class QuanLyChung {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int choose,n;
ArrayList<XeMayHoaBinh> HBList = new ArrayList<>();
ArrayList<XeMayHaNoi> HNList = new ArrayList<>();
XeMayHoaBinh xmhb = new XeMayHoaBinh();
XeMayHaNoi xmhn = new XeMayHaNoi();
do{
menu();
choose = Integer.parseInt(scan.nextLine());
switch(choose){
case 1:
xmhb.input();
break;
case 2:
xmhn.input();
break;
case 3:
System.out.println("1. Hoa Binh");
System.out.println("2. Ha Noi");
System.out.println("Choose:");
n = Integer.parseInt(scan.nextLine());
switch(choose){
case 1:
xmhb.sort();
break;
case 2:
xmhn.sort();
break;
default:
break;
}
break;
case 4:
System.out.println("1. Hoa Binh");
System.out.println("2. Ha Noi");
System.out.println("Choose:");
n = Integer.parseInt(scan.nextLine());
switch(choose){
case 1:
xmhb.search();
break;
case 2:
xmhn.search();
break;
default:
break;
}
break;
case 5:
System.out.println("1. Hoa Binh");
System.out.println("2. Ha Noi");
System.out.println("Choose:");
n = Integer.parseInt(scan.nextLine());
switch(choose){
case 1:
xmhb.thongKeSL();
break;
case 2:
xmhn.thongKeSL();
break;
default:
break;
}
break;
case 6:
System.out.println("Thoat.");
break;
default:
System.out.println("INPUT FAILED !!!");
break;
}
}while(choose != 6);
}
public static void menu(){
System.out.println("1. Nhập thông tin cho n xe máy tại tỉnh Hòa Bình.");
System.out.println("2. Nhập thông tin cho n xe máy tại tỉnh Hà Nội.");
System.out.println("3. Sắp xếp danh sách tăng theo biển số xe.");
System.out.println("4. Tìm kiếm thông tin xe theo biển số xe.");
System.out.println("5. Thống kê số lượng xe đang quản lý.");
System.out.println(" 6. Thoát");
}
}
/*
* 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.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import xeco.info.XeMay;
/**
*
* @author Administrator
*/
public class XeMayHoaBinh extends XeMay{
Scanner scan = new Scanner(System.in);
int n;
ArrayList<XeMay> xeMayHBList = new ArrayList<>();
public XeMayHoaBinh() {
}
public XeMayHoaBinh(int n, String bienso, String loaixe, String mauxe, float giatien) {
super(bienso, loaixe, mauxe, giatien);
this.n = n;
}
@Override
public void input(){
System.out.println("Nhap so luong xe may HB:");
n = Integer.parseInt(scan.nextLine());
for (int i = 0; i < n; i++) {
XeMay xemayhb = new XeMay();
xemayhb.input();
xeMayHBList.add(xemayhb);
}
}
@Override
public void display(){
System.out.println("Danh sach xe may HB");
for (int i = 0; i < xeMayHBList.size(); i++) {
xeMayHBList.get(i).display();
}
}
public void sort(){
Collections.sort(xeMayHBList, new Comparator<XeMay>() {
@Override
public int compare(XeMay o1, XeMay o2) {
if(o1.getBienso().equalsIgnoreCase(o2.getBienso())){
return 1;
}return -1;
}
});
display();
}
public void search(){
System.out.println("Nhap bien so xe can tim:");
String bienSo = scan.nextLine();
for (int i = 0; i < xeMayHBList.size(); i++) {
if(xeMayHBList.get(i).getBienso().equalsIgnoreCase(bienSo)){
xeMayHBList.get(i).display();
}
}
}
public void thongKeSL(){
System.out.println("So luong xe quan ly tai HB :" + xeMayHBList.size());
}
}
![nguyễn văn huy [T1907A]](https://www.gravatar.com/avatar/b107d14d7d43c142b68c12c377262371.jpg?s=80&d=mm&r=g)
nguyễn văn huy
2020-03-16 14:52: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 quanlixemay;
import java.util.*;
/**
*
* @author ASUS
*/
public class xemayhoabinh extends xemay {
ArrayList<xemay> xemayl=new ArrayList<>();
int n;
public xemayhoabinh() {
}
public xemayhoabinh(int n, String bienso, String loaixe, String mauxe, float giatien) {
super(bienso, loaixe, mauxe, giatien);
this.n = n;
}
@Override
public void nhap(){
System.out.println("nhap so xe hoa binh");
n=Integer.parseInt(scan.nextLine());
for (int i = 0; i < n; i++) {
xemay xemay=new xemay();
xemay.nhap();
xemayl.add(xemay);
}
}
public void hienthi(){
System.out.println("danh sach xe may hoa binh");
for (int i = 0; i < xemayl.size(); i++) {
xemayl.get(i).display();
}
}
public void timbienso(){
Collections.sort(xemayl, new Comparator<xemay>() {
@Override
public int compare(xemay o1, xemay o2) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
});
hienthi();
}
public void tim(){
float thao=Float.parseFloat(scan.nextLine());
for (int i = 0; i <xemayl.size(); i++) {
if(xemayl.get(i).getBienso().equalsIgnoreCase(bienso)){
xemayl.get(i).display();
}
}
}
public void tat(){
System.out.println("so xe hoa binh" +xemayl.size());
}
}
.......
/*
* 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 quanlixemay;
import java.util.*;
/**
*
* @author ASUS
*/
public class xemayhanoi extends xemay {
ArrayList<xemay> xemayl=new ArrayList<>();
int n;
Scanner scan=new Scanner(System.in);
public xemayhanoi() {
}
public xemayhanoi(int n, String bienso, String loaixe, String mauxe, float giatien) {
super(bienso, loaixe, mauxe, giatien);
this.n = n;
}
public void nhap(){
System.out.println("nhap so xe ha noi");
n=Integer.parseInt(scan.nextLine());
for (int i = 0; i < n; i++) {
xemay xemay=new xemay();
xemay.nhap();
xemayl.add(xemay);
}
}
public void hienthi(){
System.out.println("danh sach xe may ha noi");
for (int i = 0; i < xemayl.size(); i++) {
xemayl.get(i).display();
}
}
public void timbienso(){
Collections.sort(xemayl, new Comparator<xemay>() {
@Override
public int compare(xemay o1, xemay o2) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
});
hienthi();
}
public void tim(){
float thao=Float.parseFloat(scan.nextLine());
for (int i = 0; i <xemayl.size(); i++) {
if(xemayl.get(i).getBienso().equalsIgnoreCase(bienso)){
xemayl.get(i).display();
}
}
}
public void tat(){
System.out.println("so xe hoa binh" +xemayl.size());
}
}
......
/*
* 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 quanlixemay;
import java.util.*;
/**
*
* @author ASUS
*/
public class xemay {
String bienso, loaixe, mauxe;
float giatien;
Scanner scan = new Scanner(System.in);
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 void nhap(){
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=Integer.parseInt(scan.nextLine());
}
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;
}
public Scanner getScan() {
return scan;
}
public void setScan(Scanner scan) {
this.scan = scan;
}
public void display(){
System.out.println(toString());
}
@Override
public String toString() {
return "xemay{" + "bienso=" + bienso + ", loaixe=" + loaixe + ", mauxe=" + mauxe + ", giatien=" + giatien + ", scan=" + scan + '}';
}
}
.....
/*
* 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 quanlixemay;
import java.util.*;
/**
*
* @author ASUS
*/
public class quanlichung {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
xemayhoabinh hb = new xemayhoabinh();
xemayhanoi hn = new xemayhanoi();
int choise;
do {
menu();
choise = Integer.parseInt(scan.nextLine());
switch (choise) {
case 1:
hb.nhap();
break;
case 2:
hn.nhap();
break;
case 3:
System.out.println("1.sap sep bien so xe hoa binh");
System.out.println("2.sap sep bien so xe ha noi");
System.out.println("chon......");
choise=Integer.parseInt(scan.nextLine());
switch(choise){
case 1:
hb.timbienso();
break;
case 2:
hn.timbienso();
break;
default:
break;
}
break;
case 4:
System.out.println("1.tim bien so xe hoa binh");
System.out.println("2.tim bien so xe ha noi");
System.out.println("chon......");
choise=Integer.parseInt(scan.nextLine());
switch(choise){
case 1:
hb.tim();
break;
case 2:
hn.tim();
break;
default:
break;
}
break;
case 5:
System.out.println("1.thong ke so xe hoa binh");
System.out.println("2.thong ke so xe ha noi");
System.out.println("chon......");
choise=Integer.parseInt(scan.nextLine());
switch(choise){
case 1:
hb.tat();
break;
case 2:
hn.tat();
break;
default:
break;
}
break;
case 6:
System.out.println("thoat");
break;
default:
System.out.println("!!!!!!!");
break;
}
} while (choise != 6);
}
public static void menu() {
System.out.println(" 1.thong tin xe may hoa binh");
System.out.println(" 2.nhap thong tin xe may ha noi");
System.out.println(" 3. Sắp xếp danh sách tăng theo biển số xe.");
System.out.println(" 4. Tìm kiếm thông tin xe theo biển số xe");
System.out.println(" 5. Thống kê số lượng xe đang quản lý.");
System.out.println(" 6.Thoat");
System.out.println(" 7.choise");
}
}
![NguyenHuuThanh [T1907A]](https://www.gravatar.com/avatar/035e4f4fed661b8e1c3e066e43cd5e41.jpg?s=80&d=mm&r=g)
NguyenHuuThanh
2020-03-15 02:56:55
Quanlychung
/*
* 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 java.util.ArrayList;
import Assignment01.XeMay;
import java.util.Collections;
import java.util.Comparator;
/**
*
* @author Minh
*/
public class XeMayHaNoi extends XeMay {
Integer n;
ArrayList<XeMay> xemayhanoi = new ArrayList<>();
public XeMayHaNoi()
{
}
public XeMayHaNoi(Integer n) {
this.n = n;
}
public XeMayHaNoi(Integer n, String bienso, String loaixe, String mauxe, Float giatien) {
super(bienso, loaixe, mauxe, giatien);
this.n = n;
}
public Integer getN() {
return n;
}
public void setN(Integer n) {
this.n = n;
}
public ArrayList<XeMay> getXemayhanoi() {
return xemayhanoi;
}
public void setXemayhanoi(ArrayList<XeMay> xemayhanoi) {
this.xemayhanoi = xemayhanoi;
}
@Override
public void nhap()
{
System.out.println("Nhap vao so luong xe");
Scanner scan = new Scanner(System.in);
n = Integer.parseInt(scan.nextLine());
for ( int i = 0 ; i < n ; i++)
{
XeMay xemayhn = new XeMay();
xemayhn.nhap();
xemayhanoi.add(xemayhn);
}
}
@Override
public void hienthi()
{
System.out.println("Hien thi danh sach xe");
for ( int i = 0; i < xemayhanoi.size() ; i++)
{
xemayhanoi.get(i).hienthi();
}
}
public void sapxep()
{
Collections.sort(xemayhanoi, new Comparator<XeMay>(){
@Override
public int compare(XeMay o1 , XeMay o2){
int t1 = Integer.parseInt(o1.getBienso());
int t2 = Integer.parseInt(o2.getBienso());
if (t1 > t2)
{
return 1;
}
return -1;
}
});
for (int i = 0; i < xemayhanoi.size(); i++)
{
xemayhanoi.get(i).hienthi();
}
}
public void timkiem()
{
Scanner scan = new Scanner(System.in);
System.out.println("nhap thong tin bien so xe");
String bsx = scan.nextLine();
for (int i = 0; i < xemayhanoi.size() ; i++)
{
if(xemayhanoi.get(i).getBienso().equalsIgnoreCase(bsx)){
xemayhanoi.get(i).hienthi();
}
}
}
public void thongke(){
System.out.println(xemayhanoi.size());
}
}
xmhb
/*
* 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 java.util.ArrayList;
import Assignment01.XeMay;
import java.util.Collections;
import java.util.Comparator;
/**
*
* @author Minh
*/
public class XeMayHoaBinh extends XeMay {
Integer n;
ArrayList<XeMay> xemayhoabinh = new ArrayList<>();
public XeMayHoaBinh()
{
}
public XeMayHoaBinh(Integer n) {
this.n = n;
}
public XeMayHoaBinh(Integer n, String bienso, String loaixe, String mauxe, Float giatien) {
super(bienso, loaixe, mauxe, giatien);
this.n = n;
}
public Integer getN() {
return n;
}
public void setN(Integer n) {
this.n = n;
}
public ArrayList<XeMay> getXemayhoabinh() {
return xemayhoabinh;
}
public void setXemayhoabinh(ArrayList<XeMay> xemayhoabinh) {
this.xemayhoabinh = xemayhoabinh;
}
@Override
public void nhap()
{
System.out.println("Nhap so luong xe may");
Scanner scan = new Scanner(System.in);
n = Integer.parseInt(scan.nextLine());
for (int i = 0 ; i< n ; i++)
{
XeMay xemay = new XeMay();
xemay.nhap();
xemayhoabinh.add(xemay);
}
}
@Override
public void hienthi()
{
System.out.println("In ra danh sach xe");
for ( int i = 0 ; i < xemayhoabinh.size() ; i++)
{
xemayhoabinh.get(i).hienthi();
}
}
public void sapxep()
{
Collections.sort(xemayhoabinh, new Comparator<XeMay>(){
@Override
public int compare(XeMay o1 , XeMay o2){
int t1 = Integer.parseInt(o1.getBienso());
int t2 = Integer.parseInt(o2.getBienso());
if (t1 > t2)
{
return 1;
}
return -1;
}
});
for (int i = 0; i < xemayhoabinh.size(); i++)
{
xemayhoabinh.get(i).hienthi();
}
}
public void timkiem()
{
Scanner scan = new Scanner(System.in);
System.out.println("nhap thong tin bien so xe");
String bsx = scan.nextLine();
for (int i = 0; i < xemayhoabinh.size() ; i++)
{
if(xemayhoabinh.get(i).getBienso().equalsIgnoreCase(bsx)){
xemayhoabinh.get(i).hienthi();
}
}
}
public void thongke(){
System.out.println(xemayhoabinh.size());
}
}
xmhn
/*
* 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 java.util.ArrayList;
import Assignment01.XeMay;
import java.util.Collections;
import java.util.Comparator;
/**
*
* @author Minh
*/
public class XeMayHaNoi extends XeMay {
Integer n;
ArrayList<XeMay> xemayhanoi = new ArrayList<>();
public XeMayHaNoi()
{
}
public XeMayHaNoi(Integer n) {
this.n = n;
}
public XeMayHaNoi(Integer n, String bienso, String loaixe, String mauxe, Float giatien) {
super(bienso, loaixe, mauxe, giatien);
this.n = n;
}
public Integer getN() {
return n;
}
public void setN(Integer n) {
this.n = n;
}
public ArrayList<XeMay> getXemayhanoi() {
return xemayhanoi;
}
public void setXemayhanoi(ArrayList<XeMay> xemayhanoi) {
this.xemayhanoi = xemayhanoi;
}
@Override
public void nhap()
{
System.out.println("Nhap vao so luong xe");
Scanner scan = new Scanner(System.in);
n = Integer.parseInt(scan.nextLine());
for ( int i = 0 ; i < n ; i++)
{
XeMay xemayhn = new XeMay();
xemayhn.nhap();
xemayhanoi.add(xemayhn);
}
}
@Override
public void hienthi()
{
System.out.println("Hien thi danh sach xe");
for ( int i = 0; i < xemayhanoi.size() ; i++)
{
xemayhanoi.get(i).hienthi();
}
}
public void sapxep()
{
Collections.sort(xemayhanoi, new Comparator<XeMay>(){
@Override
public int compare(XeMay o1 , XeMay o2){
int t1 = Integer.parseInt(o1.getBienso());
int t2 = Integer.parseInt(o2.getBienso());
if (t1 > t2)
{
return 1;
}
return -1;
}
});
for (int i = 0; i < xemayhanoi.size(); i++)
{
xemayhanoi.get(i).hienthi();
}
}
public void timkiem()
{
Scanner scan = new Scanner(System.in);
System.out.println("nhap thong tin bien so xe");
String bsx = scan.nextLine();
for (int i = 0; i < xemayhanoi.size() ; i++)
{
if(xemayhanoi.get(i).getBienso().equalsIgnoreCase(bsx)){
xemayhanoi.get(i).hienthi();
}
}
}
public void thongke(){
System.out.println(xemayhanoi.size());
}
}
![Minh Nghia [T1907A]](https://www.gravatar.com/avatar/ecca255d725eed36a872105205af1b8e.jpg?s=80&d=mm&r=g)
Minh Nghia
2020-03-14 14:45:10
/*
* 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 Administrator
*/
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 input(){
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 display(){
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 xeco.info;
/**
*
* @author Administrator
*/
public interface IXe {
public void input();
public void display();
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package quanlichung.xemay;
import hanoi.xemay.XeMayHaNoi;
import hoabinh.xemay.XeMayHoaBinh;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author Administrator
*/
public class QuanLyChung {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int choose,n;
ArrayList<XeMayHoaBinh> HBList = new ArrayList<>();
ArrayList<XeMayHaNoi> HNList = new ArrayList<>();
XeMayHoaBinh xmhb = new XeMayHoaBinh();
XeMayHaNoi xmhn = new XeMayHaNoi();
do{
menu();
choose = Integer.parseInt(scan.nextLine());
switch(choose){
case 1:
xmhb.input();
break;
case 2:
xmhn.input();
break;
case 3:
System.out.println("1. Hoa Binh");
System.out.println("2. Ha Noi");
System.out.println("Choose:");
n = Integer.parseInt(scan.nextLine());
switch(choose){
case 1:
xmhb.sort();
break;
case 2:
xmhn.sort();
break;
default:
break;
}
break;
case 4:
System.out.println("1. Hoa Binh");
System.out.println("2. Ha Noi");
System.out.println("Choose:");
n = Integer.parseInt(scan.nextLine());
switch(choose){
case 1:
xmhb.search();
break;
case 2:
xmhn.search();
break;
default:
break;
}
break;
case 5:
System.out.println("1. Hoa Binh");
System.out.println("2. Ha Noi");
System.out.println("Choose:");
n = Integer.parseInt(scan.nextLine());
switch(choose){
case 1:
xmhb.thongKeSL();
break;
case 2:
xmhn.thongKeSL();
break;
default:
break;
}
break;
case 6:
System.out.println("Thoat.");
break;
default:
System.out.println("INPUT FAILED !!!");
break;
}
}while(choose != 6);
}
public static void menu(){
System.out.println("1. Nhập thông tin cho n xe máy tại tỉnh Hòa Bình.");
System.out.println("2. Nhập thông tin cho n xe máy tại tỉnh Hà Nội.");
System.out.println("3. Sắp xếp danh sách tăng theo biển số xe.");
System.out.println("4. Tìm kiếm thông tin xe theo biển số xe.");
System.out.println("5. Thống kê số lượng xe đang quản lý.");
System.out.println(" 6. Thoát");
}
}
/*
* 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.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import xeco.info.XeMay;
/**
*
* @author Administrator
*/
public class XeMayHoaBinh extends XeMay{
Scanner scan = new Scanner(System.in);
int n;
ArrayList<XeMay> xeMayHBList = new ArrayList<>();
public XeMayHoaBinh() {
}
public XeMayHoaBinh(int n, String bienso, String loaixe, String mauxe, float giatien) {
super(bienso, loaixe, mauxe, giatien);
this.n = n;
}
@Override
public void input(){
System.out.println("Nhap so luong xe may HB:");
n = Integer.parseInt(scan.nextLine());
for (int i = 0; i < n; i++) {
XeMay xemayhb = new XeMay();
xemayhb.input();
xeMayHBList.add(xemayhb);
}
}
@Override
public void display(){
System.out.println("Danh sach xe may HB");
for (int i = 0; i < xeMayHBList.size(); i++) {
xeMayHBList.get(i).display();
}
}
public void sort(){
Collections.sort(xeMayHBList, new Comparator<XeMay>() {
@Override
public int compare(XeMay o1, XeMay o2) {
if(o1.getBienso().equalsIgnoreCase(o2.getBienso())){
return 1;
}return -1;
}
});
display();
}
public void search(){
System.out.println("Nhap bien so xe can tim:");
String bienSo = scan.nextLine();
for (int i = 0; i < xeMayHBList.size(); i++) {
if(xeMayHBList.get(i).getBienso().equalsIgnoreCase(bienSo)){
xeMayHBList.get(i).display();
}
}
}
public void thongKeSL(){
System.out.println("So luong xe quan ly tai HB :" + xeMayHBList.size());
}
}
/*
* 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.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import xeco.info.XeMay;
/**
*
* @author Administrator
*/
public class XeMayHaNoi extends XeMay {
Scanner scan = new Scanner(System.in);
int n;
ArrayList<XeMay> xeMayHNList = 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;
}
@Override
public void input(){
System.out.println("Nhap so luong xe may HN:");
n = Integer.parseInt(scan.nextLine());
for (int i = 0; i < n; i++) {
XeMay xemayhn = new XeMay();
xemayhn.input();
xeMayHNList.add(xemayhn);
}
}
@Override
public void display(){
System.out.println("Danh sach xe may HN :");
for (int i = 0; i < xeMayHNList.size(); i++) {
xeMayHNList.get(i).display();
}
}
public void sort(){
Collections.sort(xeMayHNList, new Comparator<XeMay>() {
@Override
public int compare(XeMay o1, XeMay o2) {
if(o1.getBienso().equalsIgnoreCase(o2.getBienso())){
return 1;
}return -1;
}
});
display();
}
public void search(){
System.out.println("Nhap bien so xe can tim:");
String bienSo = scan.nextLine();
for (int i = 0; i < xeMayHNList.size(); i++) {
if(xeMayHNList.get(i).getBienso().equalsIgnoreCase(bienSo)){
xeMayHNList.get(i).display();
}
}
}
public void thongKeSL(){
System.out.println("So luong xe quan ly tai HB :" + xeMayHNList.size());
}
}