Question

In: Computer Science

Consider the following incomplete declaration of a Book class for 1a-1c. public class Book {   ...

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!).

Solutions

Expert Solution

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


Related Solutions

Consider the following incomplete declaration of a Book class for 1a-1c. public class Book {   ...
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...
Consider the following incomplete declaration of a Name class for 2a-2c. public class Name something missing...
Consider the following incomplete declaration of a Name class for 2a-2c. public class Name something missing {    private String first;    private String last;    public Name(String firstName, String lastName)    {       first = firstName;      last = lastName;    }    //additional methods } 2a) In the first two parts, you will modify the Name class so that it implements the Comparable interface. Show here what should go in place of something missing in the first line...
Consider a class Book that contains information about a Book. The class should has the following...
Consider a class Book that contains information about a Book. The class should has the following attributes: • The title of the book • The author of the book • Year of publication (e.g. 1994) • The number of people that have rated this book as a 1 (Terrible) • The number of people that have rated this book as a 2 (Bad) • The number of people that have rated this book as a 3 (OK) • The number...
A incomplete definition of a class Temperature is given below: public class Temperature { private double...
A incomplete definition of a class Temperature is given below: public class Temperature { private double value[] = {36.5, 40, 37, 38.3}; } [6] (i) Copy and put it in a new class. Write a method toString() of the class, which does not have any parameters and returns a string containing all the values separated by newlines. When the string is printed, each value should appear on a line in the ascending order of their indexes. Copy the content of...
Consider the following declaration: typedef struct{                                  &nbsp
Consider the following declaration: typedef struct{                                          int A;                                          char B[10];                                          float C;                                          char D;                                  }rectype;                                   typedef rectype matrix[121][4][5];                                   matrix A1; Compute the address of element A1[120][3][3] given the base address at 2000.
Assume you have created the following data definition class: public class Book {    private String title;...
Assume you have created the following data definition class: public class Book {    private String title;    private double cost;       public String getTitle() { return this.title; }    public double getCost() { return this.cost; }       public void setTitle(String title) {       this.title = title;    } // Mutator to return true/false instead of using exception handling public boolean setCost(double cost) {       if (cost >= 0 && cost < 100) {          this.cost = cost;          return true;       }       else {          return false;       }...
Write C++ program Consider the following SimpleString class: class simpleString {     public:          simpleString( );...
Write C++ program Consider the following SimpleString class: class simpleString {     public:          simpleString( );                                 // Default constructor          simpleString(int mVal );                    // Explicit value constructor          ~simpleString() { delete [ ] s;}          // Destructor void readString();                              // Read a simple string          void writeString() const;                    // Display a simple string char at(int pos) const;                       // Return character at (pos)          int getLength() const;                        // Return the string length          int getCapacity() const;...
submit the following files: Main.java Consider the following code: import java.util.Scanner; public class Main { public...
submit the following files: Main.java Consider the following code: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String input = ""; System.out.println("Enter the first number: "); input = in.nextLine(); int a = 0; int b = 0; a = Integer.parseInt(input); System.out.println("Enter the second number: "); input = in.nextLine(); b = Integer.parseInt(input); int result = 0; result = a/b; System.out.println("a/b : " + result); } Copy the code to your Main.java file...
To be done in Java Consider the partially complete book class given.    Make the following...
To be done in Java Consider the partially complete book class given.    Make the following additions to the book class. Add a getAuthor() and a getTitle() method to the book class. They should take no parameters and should return a String. Change the 3-parameter constructor for the class so that it correctly initializes the member variables. Write an accessor method called getPages(). Add a zero parameter getDetails() method to the Book class. It should assemble the information for a...
1A. Is pentane hydrophilic or hydrophobic? 1B. Is pentanol hydrophilic or hydrophobic? 1C. Explain how the...
1A. Is pentane hydrophilic or hydrophobic? 1B. Is pentanol hydrophilic or hydrophobic? 1C. Explain how the chemical difference between pentane and pentanol changes their relationship to water.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT