In: Computer Science
Consider the following incomplete declaration of a Book class for 1a-1c.
public class Book
{
private String title, author, edition;
private int numPages;
public Book { //part (a) } //default
public Book(String t, String a, String e, int np) { //part (b) }
public String getTitle() {…} //returns the title of this Book
public String getAuthor() {…} //returns the author of this Book
public String getEdition() {…} //returns the edition of this Book
public int getNumPages() {…} //returns numPages of this Book
public void printBookInfo() {
System.out.print(title + “ written by “ + author);
}
}
1a) Write the default constructor for the Book class. Our default book will have the following values:
title: Surviving CSC330 in Times of Crisis
author: Richard Weir
edition: 1
numPages = 100
1b) Write the parameterized constructor for the Book class. All instance variables need to be assigned values.
1c) Declare an instance of the Book class called myBook. myBook can have any values you would like (that are appropriate!).
class Book
{
private String title, author, edition;
private int numPages;
public Book() { // part (a)
title = "Surviving CSC330 in Times of Crisis";
author = "Richar Weir";
edition = "1";
numPages = 100;
}
public Book(String t, String a, String e, int np) { // part (b)
title = t;
author = a;
edition = e;
numPages = np;
}
public String getTitle() {
return title;
} // returns the title of this Book
public String getAuthor() {
return author;
} // returns the author of this Book
public String getEdition() {
return edition;
} // returns the edition of this Book
public int getNumPages() {
return numPages;
} // returns numPages of this Book
public void printBookInfo() {
System.out.print(title + " written by " + author);
}
}
Answer 1.c:
Book myBook = new Book("Java","Uday","1.12",10000);
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME