-
Notifications
You must be signed in to change notification settings - Fork 0
/
Book.Author Task-2 OOP.java
105 lines (88 loc) · 2.1 KB
/
Book.Author Task-2 OOP.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
class Author
{
public String name;
public String Email;
public char gender;
public Author(){}
public Author(String name, String Email, char gender)
{
this.name=name;
this.Email=Email;
this.gender=gender;
}
public String getname()
{
return name;
}
public String getEmail()
{
return Email;
}
public void setEmail(String Email)
{
this.Email=Email;
}
public char getGender()
{
return gender;
}
public String toString()
{
//System.out.println();
return "Author[name="+name+", email="+Email+", Gender="+gender;
}
}
class Book {
private String name_of_book;
private double price;
private int qty;
public Author authors =new Author();
public Book(String name_of_book, Author obj_of_Author, double price)
{
this.name_of_book=name_of_book;
this.price=price;
this.authors=obj_of_Author;
}
public Book(String name_of_book, Author obj_of_Author, double price, int qty)
{
this.name_of_book=name_of_book;
this.price=price;
this.qty=qty;
this.authors=obj_of_Author;
}
public String getName( )
{ System.out.print("Name of book is ");
return name_of_book;
}
public double getPrice()
{
System.out.print("price of book is ");
return price;
}
public void setprice(double price)
{
this.price=price;
}
public int getQty()
{ System.out.print("Books Quantity");
return qty;
}
public void setqty(int qty)
{
this.qty=qty;
}
public void tostring()
{
System.out.println("Book[name="+name_of_book+" , price="+price+" , qty="+qty);
System.out.println("Author[name="+authors.name+" ,Email="+authors.Email+" , Gender="+authors.gender);
}
}
public class Task2 {
public static void main(String[] args)
{
Author author=new Author("Robert", "lafore@gmail.com",'M');
Book book= new Book("Cpp",author,40.25,50);
book.tostring();
}
}