-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.java
More file actions
175 lines (133 loc) · 4.4 KB
/
Book.java
File metadata and controls
175 lines (133 loc) · 4.4 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package src.oopJava;
/*
Author: Spyros Tsioupros
Year: 2021
1st year university project
*/
import java.util.Scanner;
//class that creates book objects
public abstract class Book {
//variables
private String title;
private String fullName;
private String ISBN;
private String publisher;
private int pages;
private int publYear;
private double price;
//constructors
public Book(){}
public Book(String ISBN){
this.ISBN = ISBN;
}
public Book(String title, String fullName, String ISBN, String publisher, int pages, int publYear, double price){
this.title = title;
this.fullName = fullName;
while (!correctISBN(ISBN)){
System.out.print("False ISBN. Enter new ISBN: ");
ISBN = new Scanner(System.in).nextLine();
}
this.ISBN = ISBN;
this.publisher = publisher;
this.pages = pages;
this.publYear = publYear;
this.price = price;
}
//methods
//get@ methods
abstract String getBookCategory();
public String getTitle(){
return title;
}
public String getFullName(){
return fullName;
}
public String getISBN(){
return ISBN;
}
public String getPublisher(){
return publisher;
}
public int getPages(){
return pages;
}
public int getPublYear(){
return publYear;
}
public double getPrice(){
return price;
}
//set@ methods
public void setTitle(String title){
this.title = title;
}
public void setFullName(String fullName){
this.fullName = fullName;
}
public void setISBN(String isbn){
while (!correctISBN(isbn)){
System.out.print("False ISBN. Enter new ISBN: ");
isbn = new Scanner(System.in).nextLine();
}
ISBN=isbn;
}
public void setEkdotis(String publisher){
this.publisher = publisher;
}
public void setSel(int pages){
this.pages = pages;
}
public void setEtEkd(int publYear){
this.publYear = publYear;
}
public void setPrice(double price){
this.price = price;
}
//toString method
public String toString(){
return "Title: "+title+", Full Name: "+fullName+", ISBN: "+ISBN+", Publisher: "+publisher+", Pages: "+pages+", Year of Publish: "+publYear+", Price: "+price;
}
//method to check the input ISBN
public static boolean correctISBN(String isbn){
//initialize of sum
int sum = 0;
//if digits of isbn isn't 10 or 13 then ISBN is false
if(isbn.length() != 13 && isbn.length() != 10){
return false;
}
//else
if(isbn.length() == 10){//if digits are 10 then do...
for(int i = 0; i < isbn.length(); i++){
String s = String.valueOf(isbn.charAt(i));
int temp = Integer.parseInt(s);//trandform the i-st character to integer
temp = temp*(isbn.length()-i);//multiplication with right factor
sum += temp;//sum
}//end of "10 digits" for
//check the sum
if(sum%11 == 0)
return true;
/*else
return false;*/
}//end of "10 digits" if
else if(isbn.length() == 13){//if digits are 13 then do...
for(int i = 0; i < 13; i++){
String s = String.valueOf(isbn.charAt(i));
int temp = Integer.parseInt(s);//trandform the i-st character to integer
if(i%2 == 0){ //if digit is at event number index the factor is 3
temp = temp*1;
sum += temp;//sum
}
else{ //else if digit isn't at event number index the factor is 1
temp = temp*3;
sum += temp;//sum
}
}//end of "13 digits" for
//check the sum
if(sum%10 == 0)
return true;
/*else
return false;*/
}//end of "13 digits" if
return false;
}
}