AuthorAndBook.java
70 linesjava
DOWNLOAD
1// Aim: Program to perform Abstract Class operations (AuthorAndBookTask and Book).
2public class AuthorAndBook {
3    private String name;
4    private String email;
5    private char gender;
6
7    public AuthorAndBook(String name, String email, char gender) {
8        this.name = name;
9        this.email = email;
10        this.gender = gender;
11    }
12
13    public String getName() {
14        return name;
15    }
16
17    public String getEmail() {
18        return email;
19    }
20
21    public char getGender() {
22        return gender;
23    }
24
25    @Override
26    public String toString() {
27        return "AuthorAndBook[name=" + name + ", email=" + email + ", gender=" + gender + "]";
28    }
29}
30
31class Book {
32    private String name;
33    private AuthorAndBook author;
34    private double price;
35    private int qtyInStock;
36
37    public Book(String name, AuthorAndBook author, double price, int qtyInStock) {
38        this.name = name;
39        this.author = author;
40        this.price = price;
41        this.qtyInStock = qtyInStock;
42    }
43
44    public String getName() {
45        return name;
46    }
47
48    public AuthorAndBook getAuthor() {
49        return author;
50    }
51
52    public double getPrice() {
53        return price;
54    }
55
56    public int getQtyInStock() {
57        return qtyInStock;
58    }
59
60    @Override
61    public String toString() {
62        return "Book[name=" + name + ", " + author + ", price=" + price + ", qtyInStock=" + qtyInStock + "]";
63    }
64
65    public static void main(String[] args) {
66        AuthorAndBook author = new AuthorAndBook("J.K. Rowling", "jkrowling@example.com", 'F');
67        Book book = new Book("Harry Potter", author, 29.99, 100);
68        System.out.println(book);
69    }
70}