IEPSEvereInfo2013-2016
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
Le Deal du moment :
Smartphone Xiaomi 14 – 512 Go- 6,36″ 5G ...
Voir le deal
599 €

EXAM 2015 ma version

2 participants

Aller en bas

EXAM 2015 ma version Empty EXAM 2015 ma version

Message par PhilippeL Mer 1 Avr - 8:57

ci dessous ma solution pour l'exam poo 2015

Il est à noter que je n'ai pas utilisé les Array mais uniquement les ArrayList. On avait  droit à une certaine liberté donc voila  bounce

Chapter
Code:

public class Chapter {
 
 int pageBegin;
 int pageEnd;
 String title;

 public Chapter(String title,int pageBegin, int pageEnd) {
 super();
 this.pageBegin = pageBegin;
 this.pageEnd = pageEnd;
 this.title = title;
 }

 public String toString() {
 return "Chapter [pageBegin=" + pageBegin + ", pageEnd=" + pageEnd
 + ", title=" + title + "]";
 }
}

Book
Code:
import java.util.ArrayList;

public class Book {
 String author;
 ArrayList<Chapter> chapters;
 int nbr;
 int nChapters;
 double price;
 String title;
 
 public Book(String author, String title) {
 super();
 this.chapters = new ArrayList<Chapter>();
 this.author = author;
 this.title = title;
 }

 public void addChapters(ArrayList<Chapter> chapters) {
 this.chapters = chapters;
 }

 public void setAuthor(String author) {
 this.author = author;
 }

 public String getAuthor() {
 return this.author;
 }

 public void setNbr(int nbr) {
 this.nbr = nbr;
 }

 public int getNChapters(){
 return this.chapters.size();
 }
 
 public void setPrice(double price) {
 this.price = price;
 }

 public void setTitle(String title) {
 this.title = title;
 }
 public String getTitle(){
 return this.title;
 }
 
 public String toString() {

 return this.title + " (" + this.author +", "+ this.getNChapters() + " chapters)";
 }
}



ITBook
Code:
public class ITBook extends Book {
 String language;

 public ITBook(String author, String title) {
 super(author, title);
 }
 
 public String getLanguage() {
 return language;
 }

 public void setLanguage(String language) {
 this.language = language;
 }

 public String toString() {
 return "ITBook [language=" + language + ", toString()="
 + super.toString() + ", getClass()=" + getClass()
 + ", hashCode()=" + hashCode() + "]";
 }
}

Rack
Code:
import java.util.ArrayList;

public class Rack {

 public final int MAX_BOOKS=50;
 ArrayList<Book> books;
 int currentSize;
 String name;
 
 public Rack(String name) {
 super();
 this.name = name;
 this.books = new ArrayList<Book>();
 }
 
 public boolean add(Book b){
 boolean addBook ;
 addBook = (this.books.size() < MAX_BOOKS)? true: false;
 if(addBook) books.add(b);
 return addBook;
 }

 public String getName() {
 return name;
 }

 public void setName(String name) {
 this.name = name;
 }
 
 public ArrayList<Book> getBooks() {
 return books;
 }

 public Book getBook(String title) {
 Book book = null;
 for(Book bk : books){
 if(bk.getTitle().equals(title)) book = bk;
 }
 return book;
 }
 
 public ArrayList<Book> getBooks(String author) {
 ArrayList<Book> bookSelection = null;
 for(Book bk : books){
 if(bk.getAuthor().equals(author)) bookSelection.add(bk);
 }
 
 return bookSelection;
 }
 
 public int getCurrentSize() {
 return this.books.size();
 }

 public String toString() {
 String msg = "";
 msg+=this.name;
 msg+="\n";
 for(Book b : this.books){
 msg+="\t";
 msg += b.toString();
 msg+="\n";
 }
 
 return msg;
 }
}

Library

Code:
import java.util.ArrayList;

public class Library {
 public final int MAX_BOOKS=2500;
 int currentSize;
 String name;
 ArrayList<Rack> racks;
 
 public Library(String name, Rack rack){
 this.name = name;
 this.racks = new ArrayList<Rack>();
 this.racks.add(rack);
 }
 
 public boolean addRack(Rack r){
 boolean addRack ;
 
 addRack = (this.racks.size() < MAX_BOOKS)? true: false;
 if(addRack) racks.add(r);
 return addRack;
 }
 
 public boolean addRacks(){
 boolean addRack ;
 
 addRack = (this.racks.size() < MAX_BOOKS)? true: false;
 if(addRack){
 Rack r = new Rack("IT");
 racks.add(r);
 }
 return addRack;
 }
 
 public Book getBook(String title){
 Book book = null;
 for(Rack r : racks){
 book = r.getBook(title);
 
 if(book != null)return book;
 }
 return book;
 }
 
 public ArrayList<Book> getBooks(String author){
 ArrayList<Book> books = null;
 for(Rack r : racks){
 books = r.getBooks(author);
 
 if(books != null)return books;
 }
 return books;
 }
 
 
 //still need to be implemented
 public Rack getRack(Book book){
 //this.racks.
 return null;
 }
 //still need to be implemented
 public void sellBook(Book book){
 
 }
 
 public ArrayList<Rack> getRacks(){
 return this.racks;
 }
 
 public int getCurrentSize(){
 return racks.size();
 }
 
 public void addBook(Book b, String category){
 for(Rack r : racks){
 if(r.getName().equals(category)){
 r.add(b);
 
 break;
 }
 }
 }
 
 public String toString(){
 String msg = "";
 msg+=this.name.toUpperCase();
 msg+=":";
 msg+="\n";
 msg+="==========================";
 msg+="\n";
 for(Rack r : this.racks){
 msg+=r.toString();
 msg+="\n";
 }
 return msg;
 }
}

TestLibrary: main class

Code:
import java.util.ArrayList;


public class TestLibrary {
 public static void main(String[] args) {
 
 Rack rackIT = new Rack("IT");
 Rack rackBD = new Rack("BD");
 Rack rackScience = new Rack("SCIENCE FICTION");
 
 Library lib = new Library("librairie du coin", rackIT);
 lib.addRack(rackBD);
 lib.addRack(rackScience);
 
 Book headFirstDP = new Book("unknown", "heads first design pattern");
 Book javaPremierL = new Book("DE Lannoy", "Java premier langage");
 Book twoTower = new Book("Tolkien"," the two tower");
 
 headFirstDP.addChapters(genericChpt());
 javaPremierL.addChapters(genericChpt());
 twoTower.addChapters(genericChpt());
 
 lib.addBook(headFirstDP, "IT");
 lib.addBook(javaPremierL, "IT");
 lib.addBook(twoTower, "SCIENCE FICTION");
 
 System.out.println(lib);

 }
 
 // this could have been put in the book class but it's not in the uml diagram like a bunch of stuff
 public static ArrayList<Chapter> genericChpt(){
 ArrayList<Chapter> randomChpt = new ArrayList<Chapter>();
 int nbrChpt  =(int) (7* Math.random());
 for(int i=0 ; i <= nbrChpt; i++){
 randomChpt.add(new Chapter("dummy chpt", 1, (int)(40* Math.random())));
 }
 return randomChpt;
 }
}
PhilippeL
PhilippeL

Messages : 119
Date d'inscription : 18/10/2013

Revenir en haut Aller en bas

EXAM 2015 ma version Empty Re: EXAM 2015 ma version

Message par Fab Mer 20 Mai - 3:34

Merci!

C'est pas top ; mais on fera avec!

What a Face
Fab
Fab

Messages : 350
Date d'inscription : 18/10/2013
Age : 40
Localisation : Hannut

https://ieps.forumgratuit.be/

Revenir en haut Aller en bas

Revenir en haut

- Sujets similaires

 
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum