0% found this document useful (0 votes)
35 views

Seminar 6 Në Java: //variabla Instance

The document describes an exercise to create an Author class and a Book class with a composition relationship between them. The Author class contains attributes like name, birthplace, etc. and methods to display author details. The Book class contains attributes like title, author, price, etc. and a method to display book details. The main method creates an Author object, a Book object linked to that author, and calls display methods to output author and book details to the console.

Uploaded by

ONIMA Music
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Seminar 6 Në Java: //variabla Instance

The document describes an exercise to create an Author class and a Book class with a composition relationship between them. The Author class contains attributes like name, birthplace, etc. and methods to display author details. The Book class contains attributes like title, author, price, etc. and a method to display book details. The main method creates an Author object, a Book object linked to that author, and calls display methods to output author and book details to the console.

Uploaded by

ONIMA Music
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Seminar 6 në Java 2021

Ushtrim 1:
Krijoni klasat Autor dhe Libër. Implementoni përbërje mes këtyre klasave, që do të thotë se
klasa Liber të ketë një variabël instance nga klasa Autor.

public class Autor {


//variabla instance
String emri;
String vendlindja;
String ditelindja;
String email;
int nrCmimeveFitues;
int nrLiber;

//konstruktori
public Autor (String e, String v, String d, String em, int c,
int l){
this.emri = e;
this.vendlindja = v;
this.ditelindja = d;
this.email = em;
this.nrCmimeveFitues = c;
this.nrLiber = l;
}

//set dhe get


public void setEmri(String e){
this.emri = e;
}
public String getEmri(){
return this.emri;
}
public void setVendlindja(String v){
this.vendlindja=v;
}
public String getVendlindja(){
return this.vendlindja;
}
public void setDitelindja(String d){
this.ditelindja=d;
}
public String getDitelindja(){
return this.ditelindja;
}
public void setEmail(String e){
this.email=e;
}
public String getEmail(){
return this.email;

1
Seminar 6 në Java 2021
}
public void setNrCmime(int c){
this.nrCmimeveFitues=c;
}
public int getNrCmime(){
return this.nrCmimeveFitues;
}
public void setNrLiber(int n){
this.nrLiber=n;
}
public int getNrLiber(){
return this.nrLiber;
}

public void afisho(){


System.out.println(this.emri+", lindur ne
"+this.vendlindja+" ka fituar "+this.nrCmimeveFitues+" cmime si
autor.");
}
}

public class Liber {


//variabla instance
String titull;
Autor autori; //Lidhja me klasen Autor
int cmimi;
String ISBN;
String shtepiaBotuese;

public Liber(String t, Autor a, int c, String i, String s){


this.titull=t;
this.autori=a;
this.cmimi=c;
this.ISBN=i;
this.shtepiaBotuese=s;
}
//set dhe get
public void setTitull(String t){
this.titull=t;
}
public String getTitull(){
return this.titull;
}
public void setAutori(Autor a){
this.autori=a;
}
public Autor getAutori(){
return this.autori;
}
2
Seminar 6 në Java 2021
public void setCmimi(int c){
this.cmimi=c;
}
public int getCmimi(){
return this.cmimi;
}
public void setISBN(String i){
this.ISBN=i;
}
public String getISBN(){
return this.ISBN;
}
public void setShtepiaBotuese(String s){
this.shtepiaBotuese=s;
}
public String getShtepiaBotuese(){
return this.shtepiaBotuese;
}

public void afisho(){


System.out.println("Libri me titull "+this.titull+"
\nShkruar nga "+this.autori.emri+ "\n Botuar nga Shtepia Botuese
"+this.getShtepiaBotuese());
}
}

public class App {


public static void main(String[] args) throws Exception {
//The Code of the Extraordinary Mind, Vishen Lakhiani
Autor a1=new Autor("Vishen Lakhiani", "Kuala Lumpur,
Malaysia","14/01/1976", "email", 3, 2);
Liber l1=new Liber("The Code of the Extraordinary Mind",a1,
14, "1623367085","Rodale Books");
a1.afisho();
l1.afisho();
}
}

Në Console:

Vishen Lakhiani, lindur ne Kuala Lumpur, Malaysia ka fituar 3 cmime si autor.


Libri me titull The Code of the Extraordinary Mind
Shkruar nga Vishen Lakhiani
Botuar nga Shtepia Botuese Rodale Books

You might also like