0% found this document useful (0 votes)
31 views2 pages

Java Device Management System

The document defines classes for devices, phones, and laptops that inherit from the devices class. It includes constructors, input and output methods, and an update price method. The main method creates objects of each class and calls their output and update price methods.

Uploaded by

Triết Nguyễn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Java Device Management System

The document defines classes for devices, phones, and laptops that inherit from the devices class. It includes constructors, input and output methods, and an update price method. The main method creates objects of each class and calls their output and update price methods.

Uploaded by

Triết Nguyễn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

package Week4;

import [Link];

public class Devices {


private String id,name;
private float price;

Devices() {};
Devices(String id,String name,float price) {
[Link] = id;
[Link] = name;
[Link] = price;
}

void input() {
Scanner sc = new Scanner([Link]);
[Link]("Input devices: ");
id = [Link]();
name = [Link]();
price = [Link]();
}

void output() {
[Link]("ID: %s \nName: %s \nPrice: %f",id,name,price);
}

void updatePrice(float price) {


[Link] = price;
}
}

package Week4;

import [Link];

public class Phone extends Devices{


String os;

Phone() {}
Phone(String id, String name, float price,String os) {
super(id, name, price);
[Link] = os;
};

void input() {
[Link]();
Scanner sc = new Scanner([Link]);
os = [Link]();
}

void output() {
[Link]();
[Link]("\nOS: "+os+"\n");
}

void updatePrice(float price) {


[Link](price);
}

package Week4;

import [Link];

public class Laptop extends Devices {


String cpu;

Laptop() {}
Laptop(String id, String name, float price,String cpu) {
super(id, name, price);
[Link] = cpu;
};

void input() {
[Link]();
Scanner sc = new Scanner([Link]);
cpu = [Link]();
}

void output() {
[Link]();
[Link]("\nCPU: "+cpu+"\n");
}

void updatePrice(float price) {


[Link](price);
}
}

package Week4;

public class Shop {

public static void main(String[] args) {


Phone p1 = new Phone("001","Oppo",1301,"Android");
Phone p2 = new Phone("002","Iphone",2002,"IOS");
Laptop lap1 = new Laptop("003","MSI",8500,"Windows");
Laptop lap2 = new Laptop("004","Dell",7700,"Windows");

[Link]();
[Link]();
[Link]();
[Link]();

[Link](9999999);
[Link](12345);
}

You might also like