Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-15-2008, 11:09 PM
Member
 
Join Date: Nov 2008
Posts: 5
Rep Power: 0
trojansc82 is on a distinguished road
Default How do I store multiple Strings with an inherited class?
I am creating two classes that are inherited from a class Item, CD and CD player. I have been able to create the CD and CD Player classes by using the "extends" keyword, but I do not know how to store several Strings in the field "features".

Here is what I need to add:

Quote:
Change StockManager unit test class to perform the following additional tasks:
• add the following products
o A CD, id=110, name="Dr. Love’s Greatest Hits”, suggested retail price=17.95, Artist=”Dr. Love”, Record Label=”Artista”; tracks: “Hold on”, “Go away”, “Give some time”, “You bet – you loose”

o A CD, id=15, name=”Romance Music”, suggested retail price=15.98, Artist=”Various”, Record Label=”EMI”, tracks: ”Slow moves”, “Sweet Love”, “Serenity in time”

o A CD Player, id=32, name=”Philcosoft”, Manufacturer=”Zing Electronics”, price=155.56, features: “MP3”, “RW”, “Progressing Scan”
Now I know how to use the external method calls using dot notation, but I do not know how to add the "tracks" and "features" fields so that they store multiple Strings.

Here is my coding for the StockManager class:

Code:
import java.util.ArrayList;
/*
 * Class StockManager 
 * get info about the stock
 * A.K.
 * October 25, 2008
 */

public class StockManager 
{
    
    // list of products
     
    ArrayList<Product> list;
    
    /*
     * Constructor for objects of class StockManager
     * create new list of products
     */
    public StockManager()
    {
        list=new ArrayList<Product>();
    }
    
    /*
     * add product to the list
     */
    public void addProduct(Product p)
    {
        list.add(p);
    }
    /*
     * Print inventory info if its' quantity equals
     * to quantity
     * @param quantity
     */
    public void printInventoryExceptions(int quantity)
    {
        int i;
        int counter=0;
        for(i=0;i<list.size();i++)
            if(list.get(i).getQuantity()<=quantity)
            {
                counter++;
                System.out.println(list.get(i).getName());
                System.out.println(list.get(i).getQuantity());
            }
        if(counter==0)
            System.out.println("There aren't any product exceptions in the stock");
    }
    
    /*
     * find product with certain name and return it
     * @return product
     */
    private Product findProduct(String name)
    {
        int i;
    
        for(i=0;i<list.size();i++)
            if(list.get(i).getName().equalsIgnoreCase(name))
            {
                Product p=new Product(list.get(i).getID(),list.get(i).getName());
                return p;
            }
        return null;
        
    }
    /*
     * print product of certain name
     * @param name
     */
    public void printProduct(String name)
    {
        Product p=findProduct(name);
        System.out.println("There are "+p.getQuantity()+ " "+p.getName()+ " for product id "+p.getID());
        
    }

}
The CD Class:

Code:
/**
 * Write a description of class CD here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class CD extends Product
{
    // instance variables - replace the example below with your own
    private String artist;
    private String cdLabel;
    private int numberOfTracks;
    private double retailPrice;
    
    

    /**
     * Constructor for objects of class CD
     */
    public CD(int id, String title, String theArtist, String label, int tracks, double price)
    {
        // initialise instance variables
        super(id, title);
        cdLabel = label;
        artist = theArtist;
        numberOfTracks = tracks;
        retailPrice = price;
       
    }

    public String getArtist()
    {
        return artist;
    }

    public void changeArtist(String newArtist)
    {
        artist = newArtist;
    }
    
    public String getLabel()
    {
        return cdLabel;
    }
    
    public void changeLabel(String newCDLabel)
    {
        cdLabel = newCDLabel;
    }
    
    public int getNumberOfTracks()
    {
        return numberOfTracks;
    }
    
    public double getRetailPrice()
    {
        return retailPrice;
    }
    

}
The code for the CDPlayer class:

Code:
/**
 * Write a description of class CDPlayer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class CDPlayer extends Product
{
    // instance variables - replace the example below with your own
    private String manufacturer;
    private String listOfFeatures;
    private double retailPrice;

    /**
     * Constructor for objects of class CDPlayer
     */
    public CDPlayer(int id, String title, String madeBy, String features, double price)
    {
        // initialise instance variables
        super(id, title);
        manufacturer = madeBy;
        listOfFeatures = features;
        retailPrice = price;
       
    }


}
Any help would be much appreciated!
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
inherited from the Component class ronald christian New To Java 1 10-24-2008 08:55 PM
How to store and access multiple calendars using a J2ME application thirupathik CLDC and MIDP 0 07-13-2008 02:47 PM
How to store Multiple calendars in PIM Database thirupathik CDC and Personal Profile 0 07-13-2008 02:45 PM
Can I store multiple objects in an array lareauk New To Java 9 05-29-2008 04:57 AM
Can I use vectors to store multiple types of objects Nathand Advanced Java 6 04-28-2008 08:55 AM


All times are GMT +2. The time now is 06:27 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org