By GokiSoft.com| 19:56 13/02/2023|
Java Basic

Exam - Kiểm tra 60 phút lập trình OOP - Quản lý thiết bị máy tính - Lập trình OOP BT2208

Thiết kế lớp class Device gồm các thuộc tính sau:

- id: int

- name: String

- manufacturer: String

- importedDate: Date

+ void input: void -> method

void display: void -> method

Thiết kế lớp Computer kế thừa từ lớp Device gồm các thuộc tính

- cpu: String

- ram: String

Thiết kế lớp Monitor kế thừa từ lớp Device gồm các thuộc tính

- size: String (đơn vị inch, cm, m, ..)

Yêu cầu: Tạo getter/setter, hàm tạo tương ứng, và toString() cho từng class object & thiết kế ham nhập và hàm hiển thị.

Tạo 1 mảng Device[] list = new Device[5] trong class Main (test chương trình)

Thực hiện các chức năng sau:

1. Nhập thông tin thiết bị. (Hỏi người dùng thiết bị cần nhập Computer hay Monitor) -> Nhập đủ 5 thiết bị là kết thúc nhập

2. Hiển thị thông tin thiết bị

3. Hiển thị số Computer được nhập vào

4. Hiển thị số Monitor được nhập vào.

5. Thoát.

Liên kết rút gọn:

https://gokisoft.com/2208

Bình luận

avatar
GokiSoft.com [Teacher]
2021-08-03 12:14:52


#Monitor.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 lesson12.bt2208;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class Monitor extends Device{
    String size;

    public Monitor() {
    }

    public String getSize() {
        return size;
    }

    public void setSize(String size) {
        this.size = size;
    }

    @Override
    public void input() {
        super.input(); //To change body of generated methods, choose Tools | Templates.
        
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap Size: ");
        size = scan.nextLine();
    }

    @Override
    public String toString() {
        return super.toString() + ", size=" + size;
    }
}


#Main.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 lesson12.bt2208;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class Main {
    public static void main(String[] args) {
        Device[] list = new Device[5];
        Scanner scan = new Scanner(System.in);
        int choose;
        
        do {
            showMenu();
            choose = Integer.parseInt(scan.nextLine());
            
            switch(choose) {
                case 1:
                    input(list);
                    break;
                case 2:
                    display(list);
                    break;
                case 3:
                    countComputer(list);
                    break;
                case 4:
                    countMonitor(list);
                    break;
                case 5:
                    System.out.println("Thoat!!!");
                    break;
                default:
                    System.out.println("Nhap sai!!!");
                    break;
            }
        } while(choose != 5);
        
    }
    
    static void showMenu() {
        System.out.println("1. Nhap thong tin");
        System.out.println("2. Hien thi");
        System.out.println("3. Dem so Computer");
        System.out.println("4. Dem so Monitor");
        System.out.println("5. Thoat");
        System.out.println("Chon: ");
    }

    static void input(Device[] list) {
        System.out.println("Nhap thong tin 5 thiet bi: ");
        Scanner scan = new Scanner(System.in);
        int choose;
        
        for (int i = 0; i < 5; i++) {
            System.out.println("====== Khoi tao thiet bi thu: " + (i+1));
            System.out.println("1. Khoi tao Computer");
            System.out.println("2. Khoi tao Monitor");
            System.out.println("Chon: ");
            
            choose = Integer.parseInt(scan.nextLine());
            
            switch(choose) {
                case 1:
                    list[i] = new Computer();
                    break;
                default:
                    list[i] = new Monitor();
                    break;
            }
            
            list[i].input();
        }
    }

    static void display(Device[] list) {
        System.out.println("Hien thi thong tin thiet bi");
        
        for (Device device : list) {
            device.display();
        }
    }

    static void countComputer(Device[] list) {
        int count = 0;
        for (Device device : list) {
            if(device instanceof Computer) {
                count++;
            }
        }
        
        System.out.println("So thiet bi Computer: " + count);
    }

    static void countMonitor(Device[] list) {
        int count = 0;
        for (Device device : list) {
            if(device instanceof Monitor) {
                count++;
            }
        }
        
        System.out.println("So thiet bi Monitor: " + count);
    }
}


#Device.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 lesson12.bt2208;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Diep.Tran
 */
public class Device {
    int id;
    String name, manufacturer;
    Date importedDate;

    public Device() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getManufacturer() {
        return manufacturer;
    }

    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }

    public Date getImportedDate() {
        return importedDate;
    }

    public void setImportedDate(Date importedDate) {
        this.importedDate = importedDate;
    }
    
    public void input() {
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap ID: ");
        id = Integer.parseInt(scan.nextLine());
        
        System.out.println("Nhap Ten: ");
        name = scan.nextLine();
        
        System.out.println("Nhap NSX: ");
        manufacturer = scan.nextLine();
        
        System.out.println("Nhap Ngay (dd/mm/YYYY): ");
        String dateStr = scan.nextLine();
        
        importedDate = convertStringToDate(dateStr);
    }
    
    public void display() {
        System.out.println(this);
    }

    @Override
    public String toString() {
        return "id=" + id + ", name=" + name + ", manufacturer=" + manufacturer + ", importedDate=" + convertDateToString(importedDate);
    }
    
    public Date convertStringToDate(String str) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/mm/yyyy");
        
        try {
            return simpleDateFormat.parse(str);
        } catch (ParseException ex) {
            Logger.getLogger(Device.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
    
    public String convertDateToString(Date date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/mm/yyyy");
        
        return simpleDateFormat.format(date);
    }
}


#Computer.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 lesson12.bt2208;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class Computer extends Device{
    String cpu, ram;

    public Computer() {
    }

    public String getCpu() {
        return cpu;
    }

    public void setCpu(String cpu) {
        this.cpu = cpu;
    }

    public String getRam() {
        return ram;
    }

    public void setRam(String ram) {
        this.ram = ram;
    }

    @Override
    public void input() {
        super.input(); //To change body of generated methods, choose Tools | Templates.
        
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap RAM: ");
        ram = scan.nextLine();
        
        System.out.println("Nhap CPU: ");
        cpu = scan.nextLine();
    }

    @Override
    public String toString() {
        return super.toString() + ", cpu=" + cpu + ", ram=" + ram;
    }
}


avatar
Trần Văn Lâm [T2008A]
2021-03-09 13:40:43


#Computer.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 test1;

import java.text.SimpleDateFormat;
import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Computer extends Device{
    String cpu;
    String ram;

    public Computer() {
    }

    public Computer(String cpu, String ram) {
        this.cpu = cpu;
        this.ram = ram;
    }

    public String getCpu() {
        return cpu;
    }

    public void setCpu(String cpu) {
        this.cpu = cpu;
    }

    public String getRam() {
        return ram;
    }

    public void setRam(String ram) {
        this.ram = ram;
    }
    
    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap id:");
        id = scan.nextInt();
        System.out.println("Nhap ten:");
        name = scan.nextLine();
        System.out.println("Nhap nha san xuat:");
        manufacture = scan.nextLine();
        System.out.println("Nhap ngay:");
        date = scan.nextLine();
        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
        date = formatter.format(importedDate);
        System.out.println("Nhap cpu");
        cpu = scan.nextLine();
        System.out.println("Nhap ram:");
        ram = scan.nextLine();
    }

    @Override
    public void diplay() {
        System.out.println("id:" + id);
        System.out.println("Ten:" +name);
        System.out.println("Nha san xuat:"+ manufacture);
        System.out.println("Ngay sx" + importedDate);
        System.out.println("cpu:" +cpu);
        System.out.println("ram:" +ram);
    }

    @Override
    public String toString() {
        return "Computer{" + "cpu=" + cpu + ", ram=" + ram + '}';
    }
    
}


#Device.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 test1;

import java.util.Date;

/**
 *
 * @author Administrator
 */
public abstract class Device {
    int id;
    String name;
    String manufacture;
    Date importedDate;
    String date;

    public Device() {
    }
    public abstract void input();
    public abstract void diplay();
    
    public Device(int id, String name, String manufacture, Date importedDate) {
        this.id = id;
        this.name = name;
        this.manufacture = manufacture;
        this.importedDate = importedDate;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getManufacture() {
        return manufacture;
    }

    public void setManufacture(String manufacture) {
        this.manufacture = manufacture;
    }

    public Date getImportedDate() {
        return importedDate;
    }

    public void setImportedDate(Date importedDate) {
        this.importedDate = importedDate;
    }

    @Override
    public String toString() {
        return "Device{" + "id=" + id + ", name=" + name + ", manufacture=" + manufacture + ", importedDate=" + importedDate + '}';
    }
    
}


#Main.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 test1;

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Main {
    public static void main(String[] args) {
        Device[] list = new Device[5];
        Scanner scan = new Scanner(System.in);
        int choose;
        do{
            ShowMenu();
            choose = Integer.parseInt(scan.nextLine());
            System.out.println("Nhap Coputer hay Monior");
            switch (choose){
                case 1:
                    
                    break;
                case 2:
                    break;
                case 3:
                    break;
                case 4 :
                    break;
                case 5 :
                    System.out.println("Thoat");
                    break;
                default:
                    System.out.println("Nhap sai!!!");
                    break;
            
                
        }
            
        }while(choose!=5);
        
    }

    public static void ShowMenu(){
        System.out.println("1.Nhap thong tin thiet bi");
        System.out.println("2.Hien thi thong tin");
        System.out.println("3.Hien thi so Computer");
        System.out.println("4.Hien thi so Monitor");
        System.out.println("5.Thoat");
    }
}


#Monitor.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 test1;

import java.text.SimpleDateFormat;
import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Monitor extends Device{
    String size;

    public Monitor() {
    }

    public Monitor(String size) {
        this.size = size;
    }

    public String getSize() {
        return size;
    }

    public void setSize(String size) {
        this.size = size;
    }

    @Override
    public String toString() {
        return "Monitor{" + "size=" + size + '}';
    }
    
    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap id:");
        id = scan.nextInt();
        System.out.println("Nhap ten:");
        name = scan.nextLine();
        System.out.println("Nhap nha san xuat:");
        manufacture = scan.nextLine();
        System.out.println("Nhap ngay:");
        date = scan.nextLine();
        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
        date = formatter.format(importedDate);
    }

    @Override
    public void diplay() {
        System.out.println("id:" + id);
        System.out.println("Ten:" +name);
        System.out.println("Nha san xuat:"+ manufacture);
        System.out.println("Ngay sx" + importedDate);
        System.out.println("Size:" + size);
    }
    
}


avatar
Triệu Văn Lăng [T2008A]
2021-03-09 07:36:41



/*
 * 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 bai2208;

import java.util.Scanner;

/**
 *
 * @author MTLS
 */
public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Device[] list = new Device[5];

        Computer CPT = new Computer();
        Monitor MT = new Monitor();

        int choose;
        do {
            showMenu();
            choose = Integer.parseInt(scan.nextLine());
            switch (choose) {
                case 1:
                    showMenu1();
                    int choose1 = Integer.parseInt(scan.nextLine());
                    switch (choose1) {
                        case 1:
                            CPT.input();
                            break;
                        case 2:
                            MT.input();
                            break;
                        default:
                            System.out.println("Vui long nhap lai: ");
                            showMenu1();
                            break;
                    }
                    break;
                case 2:
                    CPT.display();
                    MT.display();
                    
                    break;
                case 3:
                    int cp = 0;
                    for(Device a : list) {
                        if (a instanceof Computer ) {
                            cp++;
                        }
                    }
                    System.out.println("so Computer: " + cp);
                    break;
                case 4:
                    int mt = 0;
                    for (Device a : list) {
                        if (a instanceof Monitor) {
                            mt++;
                        }
                    }
                    System.out.println("so Monitor: " + mt);
                    break;
                case 5:
                    System.out.println("Thoat!!!");
                    break;
                default:
                    System.out.println("Vui long nhap lai: ");
                    showMenu();
                    break;
            }
        } while (choose != 5);
    }

    private static void showMenu() {
        System.out.println("1. Nhap thong tin thiet bi");
        System.out.println("2. Hien thi thong tin");
        System.out.println("3. Hien thi so Computer duoc nhap");
        System.out.println("4. Hien thi so Monitor duoc nhap");
        System.out.println("5. Thoat");
        System.out.println("Moi chon: ");
    }

    private static void showMenu1() {
        System.out.println("1. Nhap thong tin Computer");
        System.out.println("2. Nhap thong tin Monitor");
        System.out.println("Moi chon");
    }
}


avatar
Triệu Văn Lăng [T2008A]
2021-03-09 07:36:20



/*
 * 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 bai2208;

import java.text.SimpleDateFormat;
import java.util.Scanner;

/**
 *
 * @author MTLS
 */
public class Monitor extends Device {

    String size;

    public Monitor() {
    }

    public Monitor(String size) {
        this.size = size;
    }

    public String getSize() {
        return size;
    }

    public void setSize(String size) {
        this.size = size;
    }

    @Override
    public String toString() {
        return "Monitor{" + "size=" + size + '}';
    }

    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap thong tin thiet bi");
        for (int i = 1; i <= 5; i++) {
            System.out.println("Nhap ten thiet bi: ");
            name = scan.nextLine();

            System.out.println("Nhap loai: ");
            manufacturer = scan.nextLine();

            System.out.println("Nhap ngay nhap khau: ");
            importedDate = scan.nextLine();
            SimpleDateFormat day = new SimpleDateFormat("dd/mm/yy");

            System.out.println("Nhap size(inch): ");
            size = scan.nextLine();
        }

    }

    @Override
    public void display() {
        for (int i = 1; i <= 5; i++) {
            System.out.println("Ten thiet bi thu " + i + ":" + name);
            System.out.println("Loai: " + manufacturer);
            System.out.println("Ngay nhap khau: " + importedDate);
            System.out.println(this);
        }

    }

}


avatar
Triệu Văn Lăng [T2008A]
2021-03-09 07:35:59



/*
 * 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 bai2208;

import java.text.SimpleDateFormat;
import java.util.Scanner;

/**
 *
 * @author MTLS
 */
public class Computer extends Device {

    String cpu, ram;

    public Computer() {
    }

    public Computer(String cpu, String ram) {
        this.cpu = cpu;
        this.ram = ram;
    }

    public String getCpu() {
        return cpu;
    }

    public String getRam() {
        return ram;
    }

    public void setCpu(String cpu) {
        this.cpu = cpu;
    }

    public void setRam(String ram) {
        this.ram = ram;
    }

    @Override
    public String toString() {
        return "Computer{" + "cpu=" + cpu + ", ram=" + ram + '}';
    }

    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap thong tin thiet bi");
        for (int i = 1; i <= 5; i++) {
            System.out.println("Nhap ten thiet bi thu: " + i + ":");
            name = scan.nextLine();

            System.out.println("Nhap loai: ");
            manufacturer = scan.nextLine();

            System.out.println("Nhap ngay nhap khau: ");
            importedDate = scan.nextLine();
            SimpleDateFormat day = new SimpleDateFormat("dd/mm/yy");

            System.out.println("Nhap cpu: ");
            cpu = scan.nextLine();

            System.out.println("Nhap ram: ");
            ram = scan.nextLine();
        }

    }

    @Override
    public void display() {
        for (int i = 1; i <= 5; i++) {
            System.out.println("Ten thiet bi thu " +i + ":" + name);
            System.out.println("Loai: " + manufacturer);
            System.out.println("Ngay nhap khau: " + importedDate);
            System.out.println(this);
        }

    }

}


avatar
Triệu Văn Lăng [T2008A]
2021-03-09 07:35:34



/*
 * 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 bai2208;

import java.util.Date;

/**
 *
 * @author MTLS
 */
public abstract class Device {

    String name, manufacturer, importedDate;

    public Device() {
    }

    public Device(String name, String manufacturer, String importedDate) {
        this.name = name;
        this.manufacturer = manufacturer;
        this.importedDate = importedDate;
    }

    public String getName() {
        return name;
    }

    public String getManufacturer() {
        return manufacturer;
    }

    public String getImportedDate() {
        return importedDate;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }

    public void setImportedDate(String importedDate) {
        this.importedDate = importedDate;
    }

    @Override
    public String toString() {
        return "Device{" + "name=" + name + ", manufacturer=" + manufacturer + ", importedDate=" + importedDate + '}';
    }

    public abstract void input();

    public abstract void display();
}


avatar
vuong huu phu [T2008A]
2021-03-09 03:30:22



/*
 * 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 javaapplication26;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class test {

    public static void main(String[] args) {
        int lua_chon;
        Scanner scan = new Scanner(System.in);
        Device[] list = new Device[5];
        do {
            menu();
            System.out.println("Nhap su lua chon");
            lua_chon = scan.nextInt();

            switch (lua_chon) {
                case 1:
                    System.out.println(" 1 Nhap thong tin cho computer");
                    System.out.println(" 2 Nhap thong tin cho monitor");
                    System.out.println("Chon");
                    int chon = scan.nextInt();

                    switch (chon) {
                        case 1:
                            for (int i = 0; i < list.length; i++) {
                                Computer pc = new Computer();
                                pc.input();
                                list[i] = pc;
                            }
                            break;

                        case 2:
                            for (int i = 0; i < list.length; i++) {
                                Monitor m = new Monitor();
                                m.input();
                                list[i] = m;
                            }
                            break;
                    }
                    break;
                case 2:
                    for (Device list1 : list) {
                        list1.display();
                    }
                    break;
                case 3:
                    int p = 0;
                    for (Device list1 : list) {
                        if (list1 instanceof Computer) {
                            p++;
                        }
                    }
                    System.out.println("So luong computer = " + p  +" san pham");
                    break;
                case 4:
                    int m = 0;
                    for (Device list1 : list) {
                        if (list1 instanceof Monitor) {
                            m++;
                        }
                    }
                    System.out.println("So luong monitor = " + m +" san pham");
                    break;
                case 5:
                    System.out.println("Thoat!!!!!!!!!");
                    break;

            }
        } while (lua_chon < 6);
    }

    public static void menu() {
        System.out.println("1 Nhap thong tin thiet bi");
        System.out.println("2 Hien thi thong tin thiet bi");
        System.out.println("3 hien thi so computer duoc nhap vao");
        System.out.println("4 hien thi so monitor nhap vao");
        System.out.println("5 thoat!!");
    }
}


avatar
vuong huu phu [T2008A]
2021-03-09 03:30:07



/*
 * 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 javaapplication26;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Admin
 */
public class Computer extends Device{
    String cpu,ram;

    @Override
    public void input() {
        try {
            Scanner scan = new Scanner(System.in);
            System.out.println("Nhap id ");
            id = Integer.parseInt(scan.nextLine());
            System.out.println("Nhap ten ");
            Name = scan.nextLine();
            System.out.println("Nhap nha san xuat");
            Manufacturer = scan.nextLine();
            System.out.println("Nhap ngay san xuat");
            date = scan.nextLine();
            SimpleDateFormat formatter = new  SimpleDateFormat("dd/MM/yyyy");
            ImportedDate = formatter.parse(date);
            System.out.println("Nhap cpu");
            cpu = scan.nextLine();
            System.out.println("Nhap ram ");
            ram = scan.nextLine();
            System.out.println("");
        } catch (ParseException ex) {
            Logger.getLogger(Computer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void display() {
        System.out.println(toString());
    }

    public Computer() {
    }

    public Computer(String cpu, String ram) {
        this.cpu = cpu;
        this.ram = ram;
    }

    public String getCpu() {
        return cpu;
    }

    public void setCpu(String cpu) {
        this.cpu = cpu;
    }

    public String getRam() {
        return ram;
    }

    public void setRam(String ram) {
        this.ram = ram;
    }

    @Override
    public String toString() {
        return super.toString() + "cpu = "+ cpu +" ram = "+ ram;
    }

    
}


avatar
vuong huu phu [T2008A]
2021-03-09 03:29:25



/*
 * 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 javaapplication26;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Admin
 */
public class Monitor extends Device{
String size;
    @Override
    public void input() {
    try {
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap id ");
        id = Integer.parseInt(scan.nextLine());
        System.out.println("Nhap ten ");
        Name = scan.nextLine();
        System.out.println("Nhap nha san xuat");
        Manufacturer = scan.nextLine();
        System.out.println("Nhap ngay san xuat");
        date = scan.nextLine();
        SimpleDateFormat formatter = new  SimpleDateFormat("dd/MM/yyyy");
        ImportedDate = formatter.parse(date);
        System.out.println("Nhap size");
        size = scan.nextLine();
    } catch (ParseException ex) {
        Logger.getLogger(Monitor.class.getName()).log(Level.SEVERE, null, ex);
    }
    }

    @Override
    public void display() {
        System.out.println(toString());
    }

    public Monitor() {
    }

    public Monitor(String size) {
        this.size = size;
    }

    public String getSize() {
        return size;
    }

    public void setSize(String size) {
        this.size = size;
    }

    @Override
    public String toString() {
        return super.toString()+" size = "+ size; //To change body of generated methods, choose Tools | Templates.
    }

    
    
}


avatar
vuong huu phu [T2008A]
2021-03-09 03:29:04



/*
 * 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 javaapplication26;

import java.util.Date;

/**
 *
 * @author Admin
 */
public abstract class Device {
    int id;
    String Name,Manufacturer;
    Date ImportedDate;
    String date;
    public abstract void input();
    public abstract void display();

    public Device() {
    }

    public Device(int id, String Name, String Manufacturer, Date ImportedDate) {
        this.id = id;
        this.Name = Name;
        this.Manufacturer = Manufacturer;
        this.ImportedDate = ImportedDate;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return Name;
    }

    public void setName(String Name) {
        this.Name = Name;
    }

    public String getManufacturer() {
        return Manufacturer;
    }

    public void setManufacturer(String Manufacturer) {
        this.Manufacturer = Manufacturer;
    }

    public Date getImportedDate() {
        return ImportedDate;
    }

    public void setImportedDate(Date ImportedDate) {
        this.ImportedDate = ImportedDate;
    }

    @Override
    public String toString() {
        return "id=" + id + ", Name=" + Name + ", Manufacturer=" + Manufacturer + ", ImportedDate=" + ImportedDate;
    }
    
}