[codes=java]import java.io.*;
import java.util.*;
abstract class nv
{
protected String manv;
protected String tennv;
protected String trinhdo;
protected int luongcb;
public void nhap()
{
Scanner x=new Scanner(System.in);
System.out.print(“Nhap ma NV: “);
manv=x.nextLine();
System.out.print(“Nhap ten NV: “);
tennv=x.nextLine();
System.out.print(“Trinh do: “);
trinhdo=x.nextLine();
System.out.print(“Luong cb: “);
luongcb=x.nextInt();
}
abstract public int luong();
public void xuat()
{
System.out.print(manv+”\t”+tennv+”\t”+trinhdo);
}
}
class nvql extends nv
{
private String chuyenmon;
private int pccv;
Scanner x=new Scanner(System.in);
public void nhap()
{
super.nhap();
System.out.print(“Chuyen mon: “);
chuyenmon=x.nextLine();
System.out.print(“Phu cap chuc vu (int): “);
pccv=x.nextInt();
}
public int luong()
{
return luongcb+pccv;
}
public void xuat()
{
super.xuat();
System.out.print(“\t”+chuyenmon+”\t”+pccv);
}
}
class nvnc extends nv
{
private String chuyenmon;
private int pcdh;
Scanner x=new Scanner(System.in);
public void nhap()
{
super.nhap();
System.out.print(“Chuyen mon: “);
chuyenmon=x.nextLine();
System.out.print(“Phu cap doc hai (int): “);
pcdh=x.nextInt();
}
public int luong()
{
return luongcb+pcdh;
}
public void xuat()
{
super.xuat();
System.out.print(chuyenmon+”\t”+pcdh);
}
}
class test
{
public static void main (String[] args) {
int chon,tt=0,i=0, n=100;
Scanner x=new Scanner(System.in);
nv m[]=new nv[n];
do{
System.out.print(“\nChon loai nhan vien, muon thoat bam 0:\n”);
System.out.print(“1. Nhan vien quan ly\n”);
System.out.print(“2. Nhan vien nghien cuu\n”);
System.out.print(“3. Xuat danh sach\n”);
chon=x.nextInt();
switch(chon)
{
case 1:
{
m[i]= new nvql();
m[i].nhap();
tt=1;
i++;
break;
}
case 2:
{
m[i]= new nvql();
m[i].nhap();
tt=1;
i++;
break;
}
case 3:
{
for(int j=0; j {
m[j].xuat();
System.out.print(“\tluong: “+m[j].luong()+”\n”);
}
break;
}
default:
tt=0;
break;
}
}while(tt!=0);
}
}[/codes]
Last modified on December 4th, 2020 at 11:47 pm
Nam Le
lequocnam
0 responds