this.congSuat = congSuat;
}
public HangDienMay() {
}
public HangDienMay(String maHang) {
super(maHang);
}
public String getThoiGianBH() {
return thoiGianBH;
}
public void setThoiGianBH(String thoiGianBH) {
this.thoiGianBH = thoiGianBH;
}
public String getDienAp() {
return dienAp;
}
public void setDienAp(String dienAp) {
this.dienAp = dienAp;
}
public String getCongSuat() {
return congSuat;
}
public void setCongSuat(String congSuat) {
this.congSuat = congSuat;
}
public void nhap() throws Exception{
super.nhap();
Scanner input = new Scanner(System.in);
System.out.println("\t Thời gian bảo hành: ");
thoiGianBH = input.nextLine();
System.out.println("\t Điện áp: ");
dienAp = input.nextLine();
System.out.println("\t Công suất: ");
congSuat = input.nextLine();
}
public String xuat(){
return super.xuat() + String.format("%-10s|%-10s|%-10s|", getThoiGianBH(), getDienAp(), getCongSuat());
}
}
/*
MAIN
*/
public class Main {
static ArrayList<HangDienMay> hdm = new ArrayList<>();
static HangDienMay objHDM = new HangDienMay();
public static void main(String[] args) {
nhap();
xuat();
}
private static void nhap() {
boolean mcheck = true;
do {
try {
objHDM.nhap();
mcheck = true;
hdm.add(objHDM);
} catch (Exception e) {
System.out.println(e.getMessage());
mcheck = false;
}
} while (mcheck);
}
private static void xuat() {
System.out.printf("%-10s|%-10s|%-10s|%-10s|%-10s|%-10s|%-10s|", "Mã hàng","Tên hàng","NSX","Giá","Thời gian bảo hành","Điện áp","Công suất");
System.out.println("");
for (HangDienMay hangDM : hdm) {
System.out.println(hangDM.xuat());
}
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.