Write a Database class that creates and maintain a list of multimedia items. Your class must use the subclasses defined above to provide the following minimum functionality: a) add an item to the list b) remove an item to the list c) print out a list of items (to the screen) d) depreciates each item
import java.util.ArrayList;
public class Database {
private ArrayList<Item>items;
public Database(){
items = new ArrayList<>();
}
public void addItem(Item item){
items.add(item);
}
public void removeItem(String name){
for (int i = 0; i < items.size(); i++) {
if(items.get(i).getName().equals(name)){
items.remove(i);
break;
}
}
}
public void printList(){
for (Item item:items) {
System.out.println(item);
}
}
public void depreciateItems(){
for (Item item:items) {
item.setCost(0);
}
}
}
Comments
Leave a comment