I have an assignment due... well last Monday but I've been having a problem with Vectors, the jist of my trouble is I had to code a vector for my assignment which didnt work so I tried running the teacher's example in one of our lectures (as showen below) I keep getting an <identifier> expected error and was wondering if anyone here could help me de-bug (as I'm awful at de-bugging... and Java for that matter)
import java.util.*;
public class Library { private Vector<Book> mBooks = new Vector<Book>();
public Library() { }
public void addBook(Book newBook) { mBooks.add(newBook); }
public void printAllBalances() { System.out.println("The library contains the following books:"); for (Book nextBook : mBooks) { nextBook.display(); } }
public void getTotalBorrowings() { int total = 0; for (Book nextBook : mBooks) { total += nextBook.getBorrowedCount(); } System.out.println("There have been a total of " + total + " borrowings from the library"); } }
Book (just incase it was needed) public class Book { private String mAuthor; private String mTitle; private boolean mBorrowed; private int mBorrowedCount;
public boolean borrowBook() { if (mBorrowed) { System.out.println("Sorry, " + mTitle + " by " + mAuthor + " is already borrowed"); return false; } else { mBorrowed = true; mBorrowedCount++; return true; } }
public void returnBook() { if (mBorrowed) { mBorrowed = false; } else { System.out.println("Error - this book was not borrowed so can't be returned"); } } public void display() { System.out.print(mTitle + " by " + mAuthor + " has been borrowed " + mBorrowedCount + " times and is currently "); if (mBorrowed) System.out.println("out"); else System.out.println("in"); } public int getBorrowedCount() { return mBorrowedCount; } }
Any help would be most appreciated and please dont flame me I already know I'm crap at Java :P
I know there are 2 sections of code here I added the book class in case you needed to see it :( So nothing wrong with the code meens something wrong with my java program >.< Thanks for your help :)