Testing
public class Book {
protected String title;
static int count = 0;
protected double startTime;
public Book(String title) {
this.title = title;
this.startTime = System.nanoTime();
count++;
}
public String toString() {
return "Title: " + title;
}
public int getBookCount() {
return count;
}
public double shelfLife() {
return (System.nanoTime() - startTime);
}
public boolean readyToRemove() {
return (this.shelfLife() > 2 * 1000000000);
}
}
class Novel extends Book {
private String author;
private int checkouts;
Novel(String title, String author) {
super(title);
this.author = author;
this.checkouts = 0;
}
Novel(String title) {
this(title, "Unknown");
}
@Override
public String toString() {
return "Title: " + title + " by " + author;
}
public String getAuthor() {
return this.author;
}
public void setAuthor(String author) {
this.author = author;
}
public void checkout() {
checkouts++;
this.startTime = System.nanoTime();
}
public int getCheckouts() {
return this.checkouts;
}
}
class Textbook extends Book {
private String publishingCompany;
Textbook(String title, String publishingCompany) {
super(title);
this.publishingCompany = publishingCompany;
}
Textbook(String title) {
this(title, "Unknown");
}
public String getPublishingCompany() {
return this.publishingCompany;
}
public void setPublishingCompany(String publishingCompany) {
this.publishingCompany = publishingCompany;
}
@Override
public String toString() {
return "Title: " + title + " by " + publishingCompany;
}
}
public class Tester {
public static void main(String[] args) {
System.out.println("---------------------------------------------------");
System.out.println("Part 1:");
Book[] books1 = {
new Book("Crime and Punishment"),
new Book("Lord of the Flies"),
new Book("Big Bird"),
new Book("The Great Gatsby")
};
for (Book b : books1) {
System.out.println(b);
System.out.println("ID: " + b.hashCode());
}
System.out.println();
System.out.println("Book Count: " + Book.count);
System.out.println("---------------------------------------------------");
System.out.println("Part 2:");
Novel[] novels1 = {
new Novel("The Scarlett Letter", "Nathaniel Hawthorne"),
new Novel("Brave New World"),
};
Textbook[] textbooks1 = {
new Textbook("AP Calculus BC", "College Board"),
new Textbook("Java for Dummies")
};
novels1[1].setAuthor("Aldous Huxley");
textbooks1[1].setPublishingCompany("John Doe");
for (Novel b : novels1) {
System.out.println(b);
System.out.println("ID: " + b.hashCode());
System.out.println("Shelf Life: " + b.shelfLife());
}
for (Textbook b : textbooks1) {
System.out.println(b);
System.out.println("ID: " + b.hashCode());
System.out.println("Shelf Life: " + b.shelfLife());
}
System.out.println("---------------------------------------------------");
System.out.println("Part 3:");
Novel n1 = new Novel("The Hobbit");
Novel n2 = new Novel("The Lord of the Rings");
Textbook t1 = new Textbook("AP Physics C: Mechanics");
Textbook t2 = new Textbook("AP Physics C: Electricity and Magnetism");
System.out.println("Is n1 ready to remove? " + n1.readyToRemove());
System.out.println("Is n2 ready to remove? " + n2.readyToRemove());
System.out.println("Is t1 ready to remove? " + t1.readyToRemove());
System.out.println("Is t2 ready to remove? " + t2.readyToRemove());
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
n1.checkout();
System.out.println("Is n1 ready to remove? " + n1.readyToRemove());
System.out.println("Is n2 ready to remove? " + n2.readyToRemove());
System.out.println("Is t1 ready to remove? " + t1.readyToRemove());
System.out.println("Is t2 ready to remove? " + t2.readyToRemove());
}
}
Tester.main(null);
public class Wowza {
public void do(int[] arr) {
arr = {0,0,0,0};
}
public void print() {
int[] arr = {9,9,9,9};
do(arr);
for (int num : arr) {
System.out.println(num);
}
}
public static void main(String[] args) {
print();
}
}