I wouldn't normally ask for help like this but im getting quite desperate. I really need help with a java assignment that I'm really struggling with (I haven't done any coding in over 2 years so lost just about any knowledge i had)


the assignment needs to have a collection that will store the following items

[IMG]http://i18.photobucket.com/albums/b102/cck1990/items.png[/IMG]

they all share 3 attributes in common so i have a base class then i have the 6 different items inheriting from this

public abstract class Item
{
    
    public String author;
    public int pubYear;
    public String titleOfPub;
    public int numberOfCopies;
    
    /**
     * requires : author != null, pubYear != null, titleOfPub != null
     * modifies : this
     * effects  : sets author, pub year,and titleOfPub  
     * @param author the item's author, year the items publication year, title the item's title
     */
    
    public Item(String author, int year, String title, int copies)
        {
            this.author = author;
            pubYear = year;
            titleOfPub = title;
            numberOfCopies = copies;
       
        }
 
    /** 
     *  modifies : nothing.   
     * @return     the name of the author
     */
    public String getAuthor()
        {
            return author;
        }
        
     /** 
     *  modifies : nothing.   
     * @return     the name of the year of publication 
     */
    
    public int getpubYear()
        {
            return pubYear;
        }
        
    /** 
     *  modifies : nothing.   
     * @return     the name of the publication
     */
    
    public String getTitleOfPub()
        {
            return titleOfPub;
        }
    
    public void addCopy()
    {
        numberOfCopies++;
    }
    
    public void removeCopies()
    {
        numberOfCopies--;
    }
    
}
public class Book extends Item
{
    // instance variables - replace the example below with your own
     
    private String placeOfPub;
    private String publisher;
    private int edition;
    

   /**
     * requires : author != null
     * modifies : this
     * effects  : sets author, pub year,and titleOfPub, placeOfPub, publisher, edition
     * @param author the book's author, year the book's publication year, title the book's title, placeOfPub the place the book was published, publisher the books publisher, edition the books edition
     */
    public Book(String author, int pubYear, String titleOfPub, int numberOfCopies, String place, String publisher, int edition)
    {
        super (author, pubYear, titleOfPub, numberOfCopies);
        placeOfPub = place;
        publisher = publisher;
        edition = edition;
    }

    /** 
     *  modifies : nothing.   
     * @return     the name of the place of publication 
     */
    public String getPlaceofPub()
    {
        return placeOfPub;
    }
    
    /** 
     *  modifies : nothing.   
     * @return     the name of the publisher
     */
    
    public String getPublisher()
    {
        return publisher;
    }
    
    /** 
     *  modifies : nothing.   
     * @return     the number of the edition
     */
    public int getEdition()
    {
        return edition;
    }
    
   
}

thats the code i have for the base class and one of the subclasses

these are the requirements

1. Your program should permit:
a. Adding each type of item;
b. The listing of all items in the library;
c. The listing of all items of a given type;
d. list the unique titles for a given author
e. list the number of copies of a given title
f. Delete an item of a given type based on the name of the author and the title;
g. It should be possible to read and write the contents of the collection to a persistent store. Initially this is to be a simple text file. However, future developments may include making use of a database
3. The user interface for the program must be a text based

It is the collection and the rest of the requirements im having trouble with, with not doing any coding i just really cant do it.

I wouldn't be asking for this much help if i wasn't desperate

Recommended Answers

All 5 Replies

You need to ask specific questions about the parts you are having trouble with.

At the moment im trying to make a factory to create the different type of items and store them in the collection but having real trouble with it

What part is giving you trouble? What does your factory do so far?

public class Factory
{
    Library L;
    public Factory (Library L)
    {
        this.L = L;
    }
    
    public void createItem (Library<String> args, String mediaType)
    {
        if (mediaType.equals("Book"))
        {
            new Book(args);

            Library.addItem(b);
        }
        
        else if (mediaType.equals("Book Chapter"))
        {
        }
    }
}

thats what i have so far, having trouble getting the constructor for making the new object sorted

To construct I normally would use:

L = new Library();

I've also seen others use the newInstance() method.

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.