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

Create a class named Book that contains data fields for the title and number of

ID: 3549461 • Letter: C

Question

Create a class named Book that contains data fields for the title and number of pages.

Include get and set methods for these fields. Next, create a subclass named Textbook,

which contains an additional field that holds a grade level for the Textbook and

additional methods to get and set the grade level field. Write an application that

demonstrates using objects of each class. Save the files as Book.java, Textbook.java,

and DemoBook.java.  Add an additional data field to the TextBook class that stores the name of the course that the textbook will be used in, including its get() and set() methods. Demonstrate the usage of the various data fields in the DemoBook class by using their get and set method.



I have it written out except for the additional field fo the Textbook class that stores the name of the course that the textbook will be used in. This is what I have so far:


public class Book {

private String title;

private int pages;


public Book(String title, int pages) {

super();

this.title = title;

this.pages = pages;

}

public String getTitle() {

return title;

}

public void setTitle(String title) {

this.title = title;

}

public int getPages() {

return pages;

}

public void setPages(int pages) {

this.pages = pages;

}


}


public class Textbook extends Book {


private String gradeLevel;

private String courseName;

public Textbook(String title, int pages, String gradeLevel,

String courseName) {

super(title, pages);

this.gradeLevel = gradeLevel;

this.courseName = courseName;

}

public String getGradeLevel() {

return gradeLevel;

}

public void setGradeLevel(String gradeLevel) {

this.gradeLevel = gradeLevel;

}

public String getCourseName() {

return courseName;

}

public void setCourseName(String courseName) {

this.courseName = courseName;

}




}


public class DemoBook {


public static void main(String[] args) {

Book book = new Book("My Notes", 650);

System.out.println("Title: " + book.getTitle() + " " + "Pages: "

+ book.getPages());

Textbook textBook = new Textbook("CPP ", 650, "XYZ", "B.Tech");

System.out.println("Title: " + textBook.getTitle() + " " + "Pages: "

+ textBook.getPages() + " Grade Level: "

+ textBook.getGradeLevel() + " Course: "

+ textBook.getCourseName());

;


}


}

Explanation / Answer


public class Book {

private String title;

private int pages;


public Book(String title, int pages) {

super();

this.title = title;

this.pages = pages;

}

public String getTitle() {

return title;

}

public void setTitle(String title) {

this.title = title;

}

public int getPages() {

return pages;

}

public void setPages(int pages) {

this.pages = pages;

}


}


public class Textbook extends Book {


private String gradeLevel;

private String courseName;

public Textbook(String title, int pages, String gradeLevel, String courseName) {

super(title, pages);

this.gradeLevel = gradeLevel;

this.courseName = courseName;

}

public String getGradeLevel() {

return gradeLevel;

}

public void setGradeLevel(String gradeLevel) {

this.gradeLevel = gradeLevel;

}

public String getCourseName() {

return courseName;

}

public void setCourseName(String courseName) {

this.courseName = courseName;

}


}


public class DemoBook {


public static void main(String[] args) {

Book book = new Book("My Notes", 650);

System.out.println("Title: " + book.getTitle() + " " + "Pages: " + book.getPages());

Textbook textBook = new Textbook("CPP ", 650, "XYZ", "B.Tech");

System.out.println("Title: " + textBook.getTitle() + " " + "Pages: " + textBook.getPages() + " Grade Level: " + textBook.getGradeLevel() + " Course: " + textBook.getCourseName());

textBook.setGradeLevel("B");

textBook.setCourseName("M.Tech");

System.out.println("Book Grade: " + textBook.getGradeLevel() + " " + "Course used: " + textBook.getCourseName());

}


}

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