-
Notifications
You must be signed in to change notification settings - Fork 25
/
Bookstore.java
97 lines (91 loc) · 1.91 KB
/
Bookstore.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
package OOPS.Examples;
class Author
{
private String fName;
private String lName;
public Author (String firstName, String lastName)
{
fName = firstName;
lName = lastName;
}
public void setFName (String firstName)
{
fName = firstName;
}
public void setLName (String lastName)
{
lName = lastName;
}
public String getFName()
{
return fName;
}
public String getLName()
{
return lName;
}
public String toString()
{
String name = (fName + " " + lName);
return name;
}
}
class Book
{
private String title;
private Author author;
private double price;
public Book(String t, Author a, double p)
{
title = t;
author = a;
price = p;
}
public void setTitle(String t)
{
title = t;
}
public void setAuthor(Author a)
{
author = a;
}
public void setPrice(double p)
{
price = p;
}
public String getTitle()
{
return title;
}
public Author getAuthor()
{
return author;
}
public double getPrice()
{
return price;
}
public String toString()
{
String temp = ("Title: " + title + "\nAuthor: " + author + "\nPrice: Rs " + price);
return temp;
}
}
public class Bookstore
{
public static void main(String[] args)
{
// Various test cases for the different methods present in the Book class.
Author author1 = new Author("Herbert","Schildert");
Book Book1 = new Book("Object Oriented Programming Systems", author1 ,1000);
System.out.println(Book1 + "\n"); // Printing the values of Book1
Author author2 = new Author("J.K","Rowling");
Book Book2 = new Book("Harry potter",author2,700); // Creating a second object.
System.out.println(Book2 + "\n");
Book2.setTitle("Percy Jackson"); // Updating it's values.
Author author3 = new Author("Rick","Riordan");
Book2.setAuthor(author3);
Book2.setPrice(735);
System.out.println("Title : " + Book2.getTitle() + "\nAuthor : " + Book2.getAuthor() + "\nPrice : Rs " + Book2.getPrice());
}
}