in java: finish the methods for shallow and deep copy public class Book { private String title; private String author; private int numPages; public Book(String title, String author, int numPages){ this.title = title; this.author = author; this.numPages = numPages; } public String getTitle(){ return this.title; } public String getAuthor(){ return this.author; } public int getPages(){return this.numPages; } public void setTitle(String newTitle){ this.title = newTitle; } public void setAuthor(String newAuthor){ this.author= newAuthor;} public void setPages(int numPages){ this.numPages = numPages; } public static void shallowCopyBookArray(Book[] orig, Book[] copy){ // FIX ME } public static void deepCopyBookArray(Book[] orig, Book[] copy){ // FIX ME } public static void main(String[] args) { Book[] books = new Book[6]; books[0] = new Book("The Great Gatsby", "F. Scott Fitzgerald", 180); books[4] = new Book("War of the Worlds", "H.G.Wells", 160); Book[] classics = new Book[6]; //shallowCopyBookArray(books, classics); //deepCopyBookArray(books, classics); } }
in java: finish the methods for shallow and deep copy
public class Book {
private String title;
private String author;
private int numPages;
public Book(String title, String author, int numPages){
this.title = title;
this.author = author;
this.numPages = numPages;
}
public String getTitle(){ return this.title; }
public String getAuthor(){ return this.author; }
public int getPages(){return this.numPages; }
public void setTitle(String newTitle){ this.title = newTitle; }
public void setAuthor(String newAuthor){ this.author= newAuthor;}
public void setPages(int numPages){ this.numPages = numPages; }
public static void shallowCopyBookArray(Book[] orig, Book[] copy){
// FIX ME
}
public static void deepCopyBookArray(Book[] orig, Book[] copy){
// FIX ME
}
public static void main(String[] args) {
Book[] books = new Book[6];
books[0] = new Book("The Great Gatsby", "F. Scott Fitzgerald", 180);
books[4] = new Book("War of the Worlds", "H.G.Wells", 160);
Book[] classics = new Book[6];
//shallowCopyBookArray(books, classics);
//deepCopyBookArray(books, classics);
}
}
Step by step
Solved in 5 steps with 1 images