01-Interface.ts


Dosyayı İndir
interface RigidBody{
	
	name:string;
	
	getArea():number;
	
	getVolume():number;
	
}


class RightPrism implements RigidBody{

	name:string;

	width:number;
	
	height:number;
	
	depth:number;
	
	constructor(name:string,width:number,height:number,depth:number){
		this.name=name;
		this.width=width;
		this.height=height;
		this.depth=depth;
	}
	
	getArea():number{
		return 2*(this.width*this.height + this.width*this.depth + this.height*this.depth);
	}
	
	getVolume():number{
		return this.width*this.height*this.depth;
	}
}

class Cylinder implements RigidBody{
	

	name:string;
	
	radius:number;
	
	depth:number;
	
	constructor(name:string,radius:number,depth:number){
		this.name=name;
		this.radius=radius;
		this.depth=depth;
	}
	
	getArea():number  {
		return 2*Math.PI*this.radius*this.radius+2*Math.PI*this.radius*this.depth;
	}
	
	 getVolume(): number{
		return Math.PI*this.radius*this.radius*this.depth;
	}
}
function writeRigidBody(rigidBody:RigidBody){
	console.log(rigidBody.name+" Alan: "+rigidBody.getArea()+" Oylum: "+rigidBody.getVolume());
}
var rightPrism=new RightPrism("Dikdörtgen Prizma",3,4,12);
console.log(rightPrism.name+" Alan: "+rightPrism.getArea()+" Oylum: "+rightPrism.getVolume());

var cylinder=new Cylinder("Silindir",3,12);
console.log(cylinder.name+" Alan: "+cylinder.getArea()+" Oylum: "+cylinder.getVolume());


var rigidBody1:RigidBody=new RightPrism("Dikdörtgen Prizma",3,4,12);
writeRigidBody(rigidBody1);

var rigidBody2:RigidBody=new Cylinder("Silindir",3,12);
writeRigidBody(rigidBody2);
				
Dosyayı İndir

Bu Sayfayı Paylaş:




Bu Sayfayı Paylaş:

İletişim Bilgileri

Takip Et

Her Hakkı Saklıdır. Bu sitede yayınlanan tüm bilgi ve fikirlerin kullanımından fibiler.com sorumlu değildir. Bu sitede üretilmiş , derlenmiş içerikleri, fibiler.com'u kaynak göstermek koşuluyla kendi sitenizde kullanılabilirsiniz. Ancak telif hakkı olan içeriklerin hakları sahiplerine aittir