Probabilmente per molti di voi il mio problema sarà irrisorio, ma sono bloccato da due ore e mi sto innervosendo. Così, se magari qualcuno sa come aiutarmi...
Dunque, sto facendo un esercizio per un esame, si tratta di costruire il solito negozio di libri.
Due metodi principali: buyBook-ordina dei libri che vengono a far parte del negozio-
e sellBook-vende un libro al cliente tra quelli presenti in negozio.
Sul primo nessun problema, ma per quanto riguarda il secondo, non riesco a fare in modo che il metodo afferri gli elementi contenuti nel vettore dei libri presenti in negozio.
Di seguito, il codice:
codice:
public class BookStore {
	
	private Vector	<BookStoreBook> storebooks;
	private Vector <Transaction> transactions;
	private Double money;
	private String owner;
	
	public BookStore (){
		storebooks = new Vector <BookStoreBook>();
		transactions = new Vector <Transaction>();
		owner = "Andrea";
		money = 5000.00;
	}
	
	public Boolean buyBook (Integer isbn,Integer units, Double costPrice){
		
		BookStoreBook storebook= new BookStoreBook (isbn, units, costPrice); 
		
		Double order = (Double)(costPrice*units);
		if (order <= money){
		money -= order;
		System.out.println (money);
		storebooks.add (storebook);
		storebook.getIsbn();
		Boolean isSold = false;
		Double saldo = -(order);
		Transaction boughtBook = new Transaction (isSold, isbn, saldo);
		transactions.add(boughtBook);
		System.out.println (transactions);
		System.out.println (storebooks);
		System.out.println(saldo);
	return true;

	
	}
		System.err.println ("Andrea's credit is unfortunately over");
				return false;
	}
	
	public boolean sellBook(Integer isbn) {
		for (Integer i = 0; i < storebooks.size(); i++) {
			
			BookStoreBook bookstorebook = storebooks.get(i);
		
			Integer currentIsbn = bookstorebook.getIsbn();
			System.out.println (bookstorebook.getIsbn());
			if (isbn.equals(currentIsbn)) {
				
		System.out.println("The book "+ bookstorebook.getIsbn()+ " costs " +bookstorebook.getSellingPrice());
					System.out.println("This book has been sold succesfully!");
					Boolean isSold = true;
					Double saldo = bookstorebook.getSellingPrice();
					Transaction currentTransaction = new Transaction(isSold, isbn, saldo);
					transactions.add(currentTransaction);			
					return true;
				}
			else {
				System.out
						.println("Error: Book not available");
			}
		
		return false;
	}
		return false;
	}
Non so...può darsi abbia sbagliato qualcosa nel costruttore BookStoreBook???
codice:
public class BookStoreBook extends Book{
	
        Integer isbn;
	
	Integer units;
	
	private Double costPrice;
	
	private Double sellingPrice;
	
	public BookStoreBook (Integer isbn, Integer units, Double costPrice){
		
		super (title, author, yearOfPublishing);
	}
	
	public BookStoreBook(String title, String author, 
						Integer yearOfPublishing,Integer isbn, 
						Double sellingPrice ) {
		super (title, author, yearOfPublishing);
		this.isbn = isbn;
		this.sellingPrice += costPrice * 0.2;
	}
Grazie mille in anticipo per l'aiuto!