Skip to content
Snippets Groups Projects
Commit 34f45813 authored by Samuel Turpin's avatar Samuel Turpin :computer:
Browse files

vivaitalia

parent 8225dc8c
Branches
No related tags found
No related merge requests found
package td05;
import java.util.ArrayList;
import java.util.Scanner;
public class Calculatrice
......
package tp05;
public class Book
{
private String code;
private final String title;
private final String author;
private final int publicationYear;
private int user; // 0 = default
public Book(String c, String t, String a, int p, int u)
{
this.code = c;
this.title = t;
this.author = a;
this.publicationYear = p;
this.user = u;
}
public String getCode()
{
return code;
}
public String getTitle()
{
return title;
}
public String getAuthor()
{
return author;
}
public int getPubliYear()
{
return publicationYear;
}
public int getUser()
{
return user;
}
public boolean borrow(int borrower)
{
this.user = borrower;
if(this.getUser() != 0)
{
return true;
}
return false;
}
public boolean giveBack()
{
if(this.isAvailable())
{
return false;
}
else
{
this.user = 0;
return true;
}
}
public boolean equals(Book obj)
{
if(this == obj) { return true; }
if(this.getCode().equals(obj.getCode())) { return true; }
if((this.getAuthor().equals(obj.getAuthor())) && (this.getTitle().equals(obj.getTitle()))) { return true; }
if(this == null || obj == null) { return false; }
return false;
}
public boolean isAvailable()
{
if(this.getUser() == 0)
{
return true;
}
return false;
}
@Override
public String toString()
{
return "Code : "+getCode()+" | Nom : "+getTitle()+" | Auteur : "+getAuthor()+" | Publication : "+getPubliYear()+'\n';
}
}
\ No newline at end of file
package tp05;
import java.util.ArrayList;
public class Library
{
private ArrayList<Book> books = new ArrayList<>();
public Book getBook(String code)
{
for(int i = 0; i <= books.size() - 1; i++)
{
if(code.equals(books.get(i).getCode()))
{
return books.get(i);
}
}
return null;
}
public boolean addBook(Book b)
{
return books.add(b);
}
public boolean removeBook(String aCode)
{
for(int i = 0; i <= books.size() - 1; i++)
{
if(aCode.equals(books.get(i).getCode()))
{
return books.remove(i) != null;
}
}
return false;
}
public boolean removeBook(Book b)
{
return books.remove(b);
}
public String borrowings()
{
String str = "";
for(int i = 0; i <= books.size() - 1; i++)
{
if(books.get(i).getUser() == 0)
{
str=str+books.get(i);
}
}
return str;
}
public boolean borrow(String code, int borrower)
{
for(int i = 0; i <= books.size() - 1; i++)
{
if(code.equals(books.get(i).getCode()))
{
return books.get(i).borrow(borrower);
}
}
return false;
}
public boolean giveBack(String code)
{
for(int i = 0; i <= books.size() - 1; i++)
{
if(code.equals(books.get(i).getCode()))
{
return books.get(i).giveBack();
}
}
return false;
}
@Override
public String toString()
{
String str = "";
for(int i = 0; i <= books.size() - 1; i++)
{
Book b = books.get(i);
str=str+"Code : "+b.getCode()+" | Nom : "+b.getTitle()+" | Auteur : "+b.getAuthor()+" | Publication : "+b.getPubliYear()+'\n';
}
return str;
}
}
\ No newline at end of file
package tp05;
public class Main {
public static void main(String[] args) {
System.out.println("Ok");
System.out.println("Oui");
}
}
package tp05;
public class UseLibrary
{
public static void main(String[] args)
{
Library lib = new Library();
lib.addBook(new Book("mc", "Minecaft", "None", 2010, 0));
lib.addBook(new Book("nes", "Nees 1985", "N", 2000, 0));
lib.addBook(new Book("fr", "Ma France", "Geaul", 1956, 0));
System.out.println(lib.getBook("nes"));
System.out.println(lib);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment