Skip to content
Snippets Groups Projects
Commit 75288ab6 authored by Malori Alvarez's avatar Malori Alvarez
Browse files

TP 5-6

parent 49cc8bd7
No related branches found
No related tags found
No related merge requests found
package tp5;
public class Book {
//attributs
private String code;
private final String TITLE;
private /*final*/ String author;
private final int PUBLICATIONYEAR;
//constructeurs
public Book(String code, String title, String author, int publicationYear){
this.code = code;
this.TITLE = title;
this.author = author;
this.PUBLICATIONYEAR = publicationYear;
}
//getters
public String getCode() {
return code;
}
public String getTITLE() {
return TITLE;
}
public String getAuthor() {
return author;
}
public int getPUBLICATIONYEAR() {
return PUBLICATIONYEAR;
}
//sept heure
public void setCode(String code) {
this.code = code;
}
public void setAuthor(String author) {
this.author = author;
}
//méthodes
public String toString(){
return this.code.toUpperCase() + ":" + this.TITLE + "->" + this.author + "," + this.PUBLICATIONYEAR;
}
public boolean equals(Object other){
if(this==other)return true;
if(this==null) return false;
//classe
if(this.getClass()!=other.getClass()){return false;}
Book autreNomQueOther = (Book) other;
//primitifs
if(this.PUBLICATIONYEAR != autreNomQueOther.PUBLICATIONYEAR) return false;
//objets
if(this.author==null) {if(autreNomQueOther.author != null) return false;}
else if(!this.author.equals(autreNomQueOther.author))return false;
}
}
package tp5;
import java.util.ArrayList;
//shift alt O
public class Library {
private ArrayList<Book> catalog;
public Library(){
this.catalog=new ArrayList<Book>();
}
public void useLibrary(){
if(catalog.isEmpty()){
}else{
}
}
public Book getBook(String code){
Book res = null;
for(int i=0;i<catalog.size();i++)
if(code.equals(catalog.get(i).getCode())){
res = catalog.get(i);
return res;
}
return null;
}
boolean addBook(Book b){
for(int i=0;i<catalog.size();i++)
if(equals(b,catalog.get(i),b)){
add(b);
return true;
}
return false;
}
}
package tp6;
import java.util.ArrayList;
public class Company {
private ArrayList<Employee> staff = new ArrayList<>();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment