Creating a LinkedList and adding userdefined data and performing various operations on it

 

import java.util.Comparator;

public class Book implements Comparable {

int id, quantity;
String author, publisher, name;

Book(int id, String author, String publisher, String name, int quantity) {
this.id = id;
this.name = name;
this.author = author;
this.publisher = publisher;
this.quantity = quantity;
}

@Override
public String toString() {
return (id + " " + author + " " + publisher + " " + name + " " + quantity);
}

@Override
public boolean equals(Object obj) {
if (obj instanceof Book) {
Book b = (Book) obj;
return (
this.id == b.id &&
this.author.equals(b.author) &&
this.publisher.equals(b.publisher) &&
this.name.equals(b.name) &&
this.quantity == b.quantity
);
} else {
return false;
}
}
@Override
public int compareTo(Object obj) {
if (obj instanceof Book) {
Book b = (Book) obj;
return (this.quantity-b.quantity);
} else{
return 0;
}
}
}

import java.util.Collections;
import java.util.LinkedList;

public class LinkedListUserdefined {

public static void main(String[] args) {
//creating a LinkedList
LinkedList<Book> ll = new LinkedList<>();
//Creating object on Book
Book b1 = new Book(1, "Rahul", "Vijay", "JAVA INVENT", 8);
Book b2 = new Book(2, "Galvin", "Willy", "Networking", 2);
Book b3 = new Book(3, "John", "Player", "Communication", 12);

//adding element to list
ll.add(b1);
ll.add(b2);
ll.add(b3);

//Travesing List using for each loop
for (Book b : ll) {
System.out.println(
b.id +
" " +
b.name +
" " +
b.author +
" " +
b.publisher +
" " +
b.quantity
);
}
//printing list by overrding toString method
System.out.println(ll);
//Creating object of Book
Book b4 = new Book(2, "Galvin", "Willy", "Networking", 2);
//finding if b4 is in LinkedList or not
System.out.println(ll.contains(b4));

//sorting our LinkedList
Collections.sort(ll);
System.out.println(ll);
}
}

Google Script for Data Entry Form in Google Spreadsheet

// function to validate the entry made by user in user form function validateEntry (){ // declare a variable and referernece of active goog...