Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design and implement a class called book that contains instance data for the tit

ID: 3639025 • Letter: D

Question

Design and implement a class called book that contains instance data for the title, author, publisher, and copyright date. Define the book constructor to accept and initialize this data. Include a setter and getter methods for all instance data. Include a toString method that returns a nicely formatted, multi-line description of the book. Create a driver class called Bookshelf, whose main method instantiates and updates several Book objects. (Write both the class and the test class).
(I already got the answer of this question, but I forgot a part of this question).

Explanation / Answer

// This is a class definition. // If you instantiate (create a new instance of) this class, then you have an object of type MyClass. public class MyClass { // This is a class variable. The static keyword tells us that all objects // of type MyClass will share the same values of n. If you change it in one // then you have changed it in all of them. static int n = 10; // This is an instance variable. Each MyClass object will have its own copy. int x; // This is the main method. You probably already know that this is where execution // of the program will start public static void main(String[] args) { // Here we can directly access n, since it is static. // Both of these lines will do the same thing, since we using them in MyClass. System.out.println(n); // This is how you access n from within the MyClass.java source file System.out.println(MyClass.n); // This is how you access n from other source files // This will cause an error, since we need an instance of MyClass to access x // System.out.println(MyClass.x); // Here we are instantiating (creating a new instance of) MyClass. MyClass mc = new MyClass(); // We can now access x, since mc is an instance of MyClass System.out.println(mc.x); // This will also work, but it's preferable to use one of the above ways to access static variables. System.out.println(mc.n); } // This is a constructor for MyClass - this is the method called when you say 'new MyClass()' // Constructors are used to set up the initial state of the object. public MyClass() { x = 1; } // This is an instance method - you can call it with: mc.m(); public void m() { } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote