Answer to Question #265635 in Computer Networks for nothando

Question #265635

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


1
Expert's answer
2021-11-13T23:51:41-0500
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);
 }
 }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS