Sort by

recency

|

594 Discussions

|

  • + 0 comments

    1) Inherit from Book You create a new class MyBook that uses Book as its base.

    2) Constructor with 3 inputs:

    title, author, and price

    Use super() to send title and author to the parent (Book).

    Then use self.price = price to save the price in this class.

    3) Use self to store values

    self.title, self.author, and self.price This means you’re saving the data inside the object so it can be used later.

    4) Implement the display() method print()

  • + 0 comments
    from abc import ABCMeta, abstractmethod
    class Book(object, metaclass=ABCMeta):
        def __init__(self,title,author):
            self.title=title
            self.author=author   
        @abstractmethod
        def display(): pass
    
    #Write MyBook class
    class MyBook(Book):
        def __init__(self, title, author, price):
            super().__init__(title,author)
            self.price = price
        def display(self):
            print('Title:',self.title)
            print('Author:',self.author)
            print('Price:',self.price)
    
    title=input()
    author=input()
    price=int(input())
    new_novel=MyBook(title,author,price)
    new_novel.display()
    
  • + 0 comments

    Python 3

    from abc import ABCMeta, abstractmethod class Book(object, metaclass=ABCMeta): def init(self,title,author): self.title=title self.author=author
    @abstractmethod def display(): pass

    Write MyBook class

    class MyBook: def init(self, title, author, price): self.title = title self.author = author self.price = price def display(self):

        print(f"Title: {self.title}")
        print(f"Author: {self.author}")
        print(f"Price: {self.price}")
    

    title=input() author=input() price=int(input()) new_novel=MyBook(title,author,price) new_novel.display()

  • + 0 comments

    ----------------MY full code ----- import java.io.; import java.util.;

    abstract class Book { String title; String author;

    Book(String title, String author) {
        this.title = title;
        this.author = author;
    }
    
    abstract void display();
    

    }

    class MyBook extends Book { int price;

    MyBook(String title, String author, int price) {
        super(title, author);
        this.price = price;
    }
    
    void display() {
        System.out.println("Title: " + title);
        System.out.println("Author: " + author);
        System.out.println("Price: " + price);
    }
    

    }

    public class Solution {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
    
        String title = scanner.nextLine();
        String author = scanner.nextLine();
        int price = scanner.nextInt();
        scanner.close();
    
        Book new_novel = new MyBook(title, author, price);
        new_novel.display();
    }
    

    }

  • + 0 comments

    abstract class Book { String title; String author;

    Book(String title, String author) {
        this.title = title;
        this.author = author;
    }
    
    abstract void display();
    

    }

    class MyBook extends Book { int price;

    MyBook(String title, String author, int price) {
        super(title, author);
        this.price = price;
    }
    
    void display() {
        System.out.println("Title: " + title);
        System.out.println("Author: " + author);
        System.out.println("Price: " + price);
    }
    

    }