public class Media {
private final String title;
private final String support;
private int nbCopies;
}
public int getNbCopies() {d. The constructor
return nbCopies;
}
public void setNbCopies(int nbCopies) {
this.nbCopies = nbCopies;
}
public String getTitre() {
return titre;
}
public String getSupport() {
return support;
}
public Media(Title String, String support){e. Method display()
this.title = title;
this.support = support;
nbCopies = 1;
}
void display(){f. Boolean method isEquals(Media el)
if(this.support=="Book" & & this.titre=="Poly de TO2" & & this.nbEx(exte)==2)
System.out.print(this.title+ "(" + this.support+ ") x"+this.nbEx(eX));
}
boolean isEqualsA(Media el){
if( support==el.support & & title==el.title)
return true;
return false;
}
public class Main {3. Creation of the Mediatheque
public static void main(String[] args) {
//creation of three Media
Media instances m = new Media("title1", "support1");
Media m2 = new Media("title2", "support2");
Media m3 = new Media("title3", "support3");
//test equality
boolean isEqualA = m.isEqualsA(m2);
if(isEquals)
System.out.println("Media("+m.getTitle()+", "+m.getSupport()+") is equal to Media("+m2.getTitle()+", "+m2.getSupport()+")" );
else
System.out.println("+m.getTitle()+", "+m.getSupport()+") is not equal to Media("+m2.getTitle()+", "+m2.getSupport()+")" );
/************************************
* Médiathèque class
*/
Médiathèque mt = new Médiathèque();
//add
mt.add(m);
mt.added(m2);
mt.added(m2);
mt.added(m3);
//display
mt.display();
}
}
public class Media Library {b. The constructor
ArrayListcontent;
}
Mediatheque(){c. The method adds(Media el)
this.contenu = new ArrayList();
}
void adds(Media el){
if(!this.content.contains(el))
this.content.add(el);
else{
/* if there already exists
* increase the value of nbExemplar
*/
//index of el in the list
int index = this.content.indexOf(el);
//read the nbCopies attribute and increment
int nbCopies = this.content.get(index).getNbCopies() + 1;
//update the nbCopies
System.out.println(this.content.get(index).getTitle());
this.content.get(index).setNbEx(nbEx)
}
}
void displays(){
for(Media media: this.contenu)
System.out.println(media.getTitre()+" "+media.getSupport()+" "+media.getNbCopies());
}
public class Media {Mediatheque.java
private final String title;
private final String support;
private int nbCopies;
public Media(String title, String support){
this.title = title;
this.support = support;
nbCopies = 1;
}
void display(){
if(this.support=="Book" & & this.titre=="Poly de TO2" & & this.nbEx(exte)==2)
System.out.print(this.title+ "(" + this.support+ ") x"+this.nbEx(eX));
}
boolean isEqualsA(Media el){
if( support==el.support & & title==el.title)
return true;
return false;
}
public int getNbCopies() {
return nbCopies;
}
public void setNbCopies(int nbCopies) {
this.nbCopies = nbCopies;
}
public String getTitre() {
return titre;
}
public String getSupport() {
return support;
}
}
import java.util.ArrayList;
public class Media Library {
ArrayListcontent;
Media Library(){
this.contenu = new ArrayList();
}
void adds(Media el){
if(!this.content.contains(el))
this.content.add(el);
else{
/* if there already exists
* increase the value of nbExemplar
*/
//index of el in the list
int index = this.content.indexOf(el);
//read the nbCopies attribute and increment
int nbCopies = this.content.get(index).getNbCopies() + 1;
//update the nbCopies
System.out.println(this.content.get(index).getTitle());
this.content.get(index).setNbEx(nbEx)
}
}
void display(){
for(Media media: this.content)
System.out.println(media.getTitle()+" "+media.getSupport()+" "+media.getNbCopies());
}
}
public class Main {
public static void main(String[] args) {
//creation of three Media
Media instances m = new Media("title1", "support1");
Media m2 = new Media("title2", "support2");
Media m3 = new Media("title3", "support3");
//test equality
boolean isEqualA = m.isEqualsA(m2);
if(isEquals)
System.out.println("Media("+m.getTitle()+", "+m.getSupport()+") is equal to Media("+m2.getTitle()+", "+m2.getSupport()+")" );
else
System.out.println("+m.getTitle()+", "+m.getSupport()+") is not equal to Media("+m2.getTitle()+", "+m2.getSupport()+")" );
/************************************
* Médiathèque class
*/
Médiathèque mt = new Médiathèque();
//add
mt.add(m);
mt.added(m2);
mt.added(m2);
mt.added(m3);
//display
mt.display();
}
}
Please disable your ad blocker and refresh the window to use this website.