-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab6Task2.java
75 lines (75 loc) · 1.53 KB
/
Lab6Task2.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
class Book
{
private int qty;
private String name;
private double price;
private Author []authors;
Book(String name, Author []authors, double price)
{
this.name=name;
this.authors=authors;
this.price=price;
}
Book(String name, Author []authors, double price , int qty)
{
this.name=name;
this.authors=authors;
this.price=price;
this.qty=qty;
}
public void setPrice(double pr)
{
price=pr;
}
public void setQty(int qt)
{
qty=qt;
}
public Author[] getAuthors()
{
return authors;
}
public double getPrice()
{
return price;
}
public int getQty()
{
return qty;
}
public String getName()
{
return name;
}
public String getAuthorName()
{
return " ";
}
public String toString()
{
String authorlist="";
for(int i=0;i<authors.length;i++)
{
if (i<=2)
authorlist+=authors[i].toString()+",";
else
authorlist+=authors[i].toString();
}
return ("Book[name="+name+" , authors={"+authorlist+"} , price="+price+", Qty="+qty+"]");
}
}
class Lab6Task2
{
public static void main(String[] args)
{
Author auth1=new Author("Abdul Jabbar","[email protected]",'m');
Author auth2=new Author("ali","[email protected]",'m');
Author auth3=new Author("inayat","[email protected]",'m');
Author auth4=new Author("chandio","[email protected]",'m');
Author[] a1={auth1,auth2,auth3,auth4};
Book b1=new Book("JAVA",a1,250.0,150);
System.out.println(b1);
System.out.println();
System.out.println(auth3);
}
}