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!