Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

package assignment;

public class Computer extends Electronic{


private int cpu;
private int memory;
public Computer(String brand,int price,int warranty,int cpuSpeed,int memory){
this.setBrand(brand);
this.setPrice(price);
this.setWarranty(warranty);
this.cpu=cpuSpeed;
this.memory=memory;
}
@Override

public void print(){

System.out.println("Brand :"+this.getBrand()+"Price :"+"$"+this.getPrice()+

" Warranty :"+this.getWarranty()+" month "+"cpu speed :"+cpu+"HZ"+" Memory


size :"+memory+"mb");

}
public void setCpu(int cpuSpeed){
this.cpu=cpuSpeed;
}
public int getCpuSpeed(){
return cpu;

}
public void setMemory(int memory){
this.memory=memory;
}
public int getMemory(){
return memory;
}
}

Jo, [11.05.22 08:41]


package assignment;

public class ElectronicMain {


public static void main(String[] args) {

Electronic cphone=new CellPhone("Nokia TS200;",300,18,3.5,true);


Electronic comp=new Computer("Dell D2100;",1000,24,1500,512);
Electronic l =new Laptop("HP N5170",1500,24,900,256,15);
Electronic[] elec ={cphone,comp,l};
for(Electronic arr: elec){

arr.print();
}

}
}

package assignment;
public class Laptop extends Computer {
private double displaySize;

public Laptop(String brand,int price,int warranty,int cpuSpeed,int memory,double displaysize){


super(brand, price, warranty, cpuSpeed, memory);
this.setBrand(brand);
this.setPrice(price);
this.setWarranty(warranty);
this.setCpu(cpuSpeed);
this.setMemory(memory);
this.displaySize=displaysize;

}
@Override
public void print(){
System.out.println("Brand :"+this.getBrand()+" Price :"+"$"+this.getPrice()+"
Warranty :"+this.getWarranty()+" month "+
" cpu speed :"+this.getCpuSpeed()+"HZ "+" Memory :"+this.getMemory()+"mb "+"Display
size :"+displaySize);
}
}

Jo, [11.05.22 08:41]


package assignment;

public class CellPhone extends Electronic{

private double batteryLife;


private boolean webEnabled;

public CellPhone(String brand,int price,int warranty,double batterylife,boolean webEnabled){


this.setBrand(brand);
this.setPrice(price);
this.setWarranty(warranty);
this.batteryLife=batterylife;
this.webEnabled=webEnabled;
}
@Override
public void print(){
System.out.println("Brand :"+this.getBrand()+"Price :"+"$"+this.getPrice()
+" Warranty :"+this.getWarranty()+" month "+"cpu speed :"+batteryLife+"HR"+"
webEnabled :"+webEnabled);

}
}

package assignment;
public class Electronic {
private String brand;
private double price;
private int warranty;
public void print(){
System.out.println("brand :"+brand);
System.out.println("price :"+price);
System.out.println("warranty :"+warranty);
}
public Electronic() {
}
public void setBrand(String brand){
this.brand=brand;
}
public String getBrand(){
return brand;
}
public void setPrice(int price){
this.price=price;
}
public double getPrice(){
return price;
}
public void setWarranty(int warranty){
this.warranty=warranty;
}
public int getWarranty(){
return warranty;
}
}

You might also like