Hi all I'm sure you hear this all the time but "I'm a student who sucks at Java looking for help"

My assignment is to (short version)
Task Overview:You need to write five classes – Shop, Item, CD, Game, and ElectronicGame. The Shop stores a Vector of Items. The items can be a CD, a game, or an electronic game, all of which have a lot in common in addition to slight differences - so inheritance is used. Item is an abstract class which is extended by CD and Game (CD stores the artist, Game the maximum number of players), and ElectronicGame extends Game (storing the platform the game is for such as PC, Xbox, or PS2).

You should test each of your classes and then run a system test using the Ass1Test class that has been written for you, checking your output against the expected output that is supplied.

so far I have item (mostly written out) and I'm fairly sure I wont have a problem with CD, Game and or ElectronicGame however when I try to code the vector for shop (and also when I test out code my lecturer has given us in class notes (which I will provide) I get an error message stating <identifier> expected on the line of the vector. I'm running Blue J version 2.1.3 (Java version (1.4.2_11). Here's the lecturer's code (hopefully something wrong with it :P

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 (Book class included in case you needed it for de-bugging)
public class Book
{
    private String mAuthor;
    private String mTitle;
    private boolean mBorrowed;
    private int mBorrowedCount;

    public Book(String author, String title)
    {
        mAuthor = author;
        mTitle = title;
        mBorrowed = false;
        mBorrowedCount = 0;
    }

    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;
    }
}

I appologise for the novel and thank you in advance for any help you can give.

Jarell

It is because you are using Generics (which first came out in JDK 1.5.0) and are compiling with a JDK 1.4.2 compiler. You need to upgrade your JDK to a 1.5 version.

Cool, thank you!!! :D you wouldn't happen to know where to do upgrade that would you?

Thank you very much :D and now to fail my assignment yay :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.