Worksheet Template-Java Programming 2
Worksheet Template-Java Programming 2
WORKSHEET 1
1. Aim: Being a student, you read from CSE Textbooks and DVD from
your online lecture, Literature review and Novels from online Library.
You want to implement a bookshelf with this class and methods.
2. Source Code:
import java.util.ArrayList;
import java.util.List;
class Item {
private String title;
private String type;
class Bookshelf {
private List<Item> contents;
public Bookshelf() {
contents = new ArrayList<>();
}
bookshelf.addItem(textbook);
bookshelf.addItem(dvd);
bookshelf.addItem(review);
bookshelf.addItem(novel);
bookshelf.listContents();
bookshelf.removeItem(dvd);
bookshelf.listContents();
}
}
3. Screenshot of Outputs:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Learning Outcomes
(i) We learn about java programming.
(ii) We learn about Constructor.
(iii)We learn about java methods.
(iv)We learn about inheritance.