Tham khao 3
package lab06;
import java.util.Scanner;
public class XeTai extends XeOTo{
String maXe;
String bienSoXe;
float trongTai;
public XeTai() {
super();
;
;
trongTai=0;
}
public XeTai(String ten, String hang, int nam, String ma, String bsx, float tt) {
super(ten, hang, nam);
maXe=ma;
bienSoXe=bsx;
trongTai=tt;
}
public void nhapThongTin(){
Scanner sc=new Scanner(System.in);
System.out.println("Nhap ma xe: ");
maXe=sc.nextLine();
System.out.println("Nhap ten xe: ");
tenXe=sc.nextLine();
System.out.println("Nhap bien so xe: ");
bienSoXe=sc.nextLine();
System.out.println("Nhap hang san xuat: ");
hangSX=sc.nextLine();
System.out.println("Nhap nam san xuat: ");
namSX=sc.nextInt();
System.out.println("Nhap trong tai: ");
trongTai=sc.nextFloat();
}
public void hienThiThongTin(){
System.out.println("Ma xe: "+maXe);
System.out.println("Ten xe: "+tenXe);
System.out.println("Bien so xe: "+bienSoXe);
System.out.println("Hang san xuat: "+hangSX);
System.out.println("Nam san xuat: "+namSX);
System.out.println("Trong tai: "+trongTai);
}
}
************************************************************************
package lab06;
public class XeOTo {
String tenXe;
String hangSX;
int namSX;
public XeOTo() {
;
;
namSX=0;
}
public XeOTo(String ten, String hang, int nam) {
tenXe=ten;
hangSX=hang;
namSX=nam;
}
}
************************************************************************
package lab06;
import java.util.Scanner;
public class QuanLyXeTai {
public QuanLyXeTai() {
}
public static void main(String[] args) {
int chon, i, n=0;
Scanner sc=new Scanner(System.in);
XeTai xt[]=new XeTai[100];
do{
//In menu
System.out.println("1. Nhap them mot xe tai.");
System.out.println("2. Tim kiem xe tai.");
System.out.println("3. Danh sach xe tai.");
System.out.println("4. Ket thuc!");
//Nhap gia tri chon
System.out.println("Nhap so de chon cong viec: ");
chon=sc.nextInt();
//xu ly
if(chon==1){
xt[n]=new XeTai();
System.out.println("Nhap thong tin xho xe tai: ");
xt[n].nhapThongTin();
n++;
}
else if(chon==2){
System.out.println("Nhap vao bien so xe can tim: ");
sc.nextLine();
String bsx=sc.nextLine();
for(i=0;i<n;i++){
if(xt[i].bienSoXe.equals(bsx)){
System.out.println("Xe tai ban can tim la: ");
xt[i].hienThiThongTin();
break;
}
}
if(i==n){
System.out.println("Khong tim duoc xe tai co bien so: "+bsx);
}
}
else if(chon==3){
XeTai obj=new XeTai();
for(i=0;i<n;i++){
for(int k=i;k<n;k++){
if(xt[i].trongTai>xt[k].trongTai){
obj=xt[i];
xt[i]=xt[k];
xt[k]=obj;
}
}
} System.out.println("********************************************");
System.out.println("DANH SACH XE TAI");
for(i=0;i<n;i++){
System.out.println("Thong tin xe tai thu "+(i+1)+" la: ");
xt[i].hienThiThongTin();
}
}
else if(chon==4){
System.out.println("Ket thuc chuong trinh.");
}
else{
System.out.println("Gia tri chon khong dung. Moi ban chon lai!");
}
}while(chon!=4);
} }
Bạn đang đọc truyện trên: Truyen247.Pro