Repository navigation
Expand file tree
/
Copy pathmainbook.java
More file actions
48 lines (43 loc) · 1.54 KB
/
Copy pathmainbook.java
File metadata and controls
48 lines (43 loc) · 1.54 KB
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
public class book {
public String title;
public double price;
public String ISBN;
public String genre;
public String author;
public book(){
title = "Ready Player One";
price = 458;
ISBN = "ABR4212";
genre = "Fiction";
author = "Ernest Cline";
}
public book(String title, double price, String genre ) throws InvalidPriceException,InvalidGenreException
{
this.title = title;
if (price<0)
throw new InvalidPriceException("Price cannot be negative");
this.price = price;
if (!genre.equals("Fiction") && !genre.equals("Non-fiction") && !genre.equals("Auto-biography"))
throw new InvalidGenreException("Invalid genre");
this.genre = genre;
}
public book(String title, double price, String ISBN, String genre, String author) throws InvalidPriceException,InvalidGenreException
{
this.title = title;
if (price<0)
throw new InvalidPriceException("Price cannot be negative");
this.price = price;
this.ISBN = ISBN;
if (!genre.equals("Fiction") && !genre.equals("Non-fiction") && !genre.equals("Auto-biography"))
throw new InvalidGenreException("Invalid genre");
this.genre = genre;
this.author = author;
}
public book(book b){
this.title = b.title;
this.price = b.price;
this.ISBN = b.ISBN;
this.genre = b.genre;
this.author = b.author;
}
}