Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class BookTester{
- public static void main(String[] args){
- ArrayList <Book> books = new ArrayList<Book>();
- books.add(new Book("Book 1", 350));
- books.add(new Book("Book 2", 72));
- books.add(new Book("Book 3", 220));
- books.add(new Book("Book 4", 120));
- books.add(new Book("Book 5", 90));
- books.add(new Book("Book 6", 120));
- books.add(new Book("Book 7", 170));
- books.add(new Book("Book 8", 400));
- books.set(1, new Book("Book 3", 220));
- books.add(1, new Book("Book 5", 90));
- System.out.println("The book at position 3 is: "+books.get(3).getTitle());
- System.out.println("The ammount in the array is: "+books.size());
- for(int i = 0; i < books.size(); i++){
- if(books.get(i).getPages() == 120){
- books.remove(i);
- }
- int totalPages = 0;
- totalPages += book.getPages();
- }
- System.out.println("The total number of pages are: "+totalPages);
- for(Book book : books){
- System.out.println(book.getTitle());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement