Python 3 I Overview This checkpoint is intended to help you

Python 3

I. Overview This checkpoint is intended to help you practice the syntax of basic inheritance. In looking at the collection of books next to your bed, you notice that they fall into a few different categories. First, you have your regular books and novels, second, your textbooks, and finally, your collection of picture books You quickly recognize that they all have many things in common, but there are some slight differences in the properties of these different kinds of books

Solution

import java.util.*;
public class Book{
    String title;
    String author;
    int publicationYear;

    void promptBookInfo(){
        Scanner sc = new Scanner(System.in);
        System.out.print(\"Enter the title: \");
        this.title = sc.nextLine();
        System.out.print(\"Enter the Author: \");
        this.author = sc.nextLine();
        System.out.print(\"Enter the publication year: \");
        this.publicationYear = sc.nextInt();
        sc.close();
    }

    void displayBookInfo(){
        System.out.println(this.title + \" (\" + this.publicationYear + \") by \" + this.author);
    }
}

class TextBook extends Book{
    String subject;

    void promptSubject(){
        Scanner sc = new Scanner(System.in);
        System.out.print(\"Enter the subject: \");
        this.subject = sc.nextLine();
        sc.close();
    }

    void displaySubject(){
        System.out.println(this.subject);
    }
}

class PictureBook extends Book{
    String illustrator;

    void promptIllustrator(){
        Scanner sc = new Scanner(System.in);
        System.out.print(\"Enter the illustrator: \");
        this.illustrator = sc.nextLine();
        sc.close();
    }

    void displayIllustrator(){
        System.out.println(this.illustrator);
    }

}

class Driver{
    public static void main(String[] args) {
        Book book = new Book();
        book.promptBookInfo();
        book.displayBookInfo();

        TextBook textBook = new TextBook();
        textBook.promptBookInfo();
        textBook.promptSubject();
        textBook.displayBookInfo();
        textBook.displaySubject();

        PictureBook pictureBook = new PictureBook();
        pictureBook.promptBookInfo();
        pictureBook.promptIllustrator();
        pictureBook.displayBookInfo();
        pictureBook.displayIllustrator();
    }
}

Python 3 I. Overview This checkpoint is intended to help you practice the syntax of basic inheritance. In looking at the collection of books next to your bed, y
Python 3 I. Overview This checkpoint is intended to help you practice the syntax of basic inheritance. In looking at the collection of books next to your bed, y

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site