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
|
public class Author
{
private String name;
private char gender;
private String email;
public Author(String name,String email,char gender)
{
this.name=name;
this.gender=gender;
this.email=email;
}
public String getName()
{
return this.name;
}
public String getEmail()
{
return this.email;
}
public void setEmail(String email)
{
this.email=email;
}
public char getGender()
{
return this.gender;
}
public String toString()
{
return("name:"+name+", gender:"+gender+", email:"+email);
}
}
public class Book
{
private String name;
private Author[] authors;
private double price;
private int qty;
public Book(String name,Author[] authors,double price)
{
this.name=name;
this.authors=authors;
this.price=price;
this.qty=0;
}
public Book(String name,Author[]authors,double price,int qty)
{
this.name=name;
this.authors=authors;
this.price=price;
this.qty=qty;
}
public String getName()
{
return this.name;
}
public Author[] getAuthors()
{
return this.authors;
}
public double getPrice()
{
return this.price;
}
public void setPrice(double price)
{
this.price=price;
}
public int getQty()
{
return this.qty;
}
public void setQty(int qty)
{
this.qty=qty;
}
public String toString()
{
return("Book name: "+name+" Author "+java.util.Arrays.toString(authors)+" price "+price+" qty "+qty);
}
public Author[] getAuthorsName()
{
Author[]authorsName=new Author[2];
authorsName[0]=Author.authors;
authorsName[1]=Author.authors;
return authorsName;
}
}
public class TestBook
{
public static void main(String[] args)
{
Author[]authors=new Author[2];
authors[0]=new Author("Tan"," AhTeck@somewhere.com",'m');
authors[1]=new Author("Paul","Paul@somewhere.com",'m');
Book javaDummy=new Book("java for dummy",authors,19.99,10);
System.out.println(javaDummy);
}
} |
Partager