Repository navigation
Expand file tree
/
Copy pathLiterature.java
More file actions
179 lines (142 loc) · 3.76 KB
/
Copy pathLiterature.java
File metadata and controls
179 lines (142 loc) · 3.76 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
176
177
178
179
package gruppeinnlevering;
import java.time.LocalDate;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author norby
*/
public abstract class Literature {
private LocalDate date;
private double purchasePrice;
private double retailPrice;
private int numberInStock;
private int year;
private String publisher;
public Literature(String publisher, long purchasePrice, int numberRecieved, int year) {
setRetailPrice(purchasePrice);
setNumberInStock(numberRecieved);
setYearIssued(year);
setPublisher(publisher);
}
/**
* Returns the titles price for the paper
*
* @return the titles price for the paper
*/
public double getPurchasePrice() {
return this.purchasePrice;
}
/**
* Returns the price out to the customer
*
* @return the price out to the customer
*/
public double getRetailPrice() {
return this.retailPrice;
}
/**
* Returns the number of papers of this type
*
* @return paperStorage int that tells how many papers there left.
*/
public int getNumberInStock() {
return numberInStock;
}
/**
* set retail price
*
* @param purchasePrice
*/
public void setRetailPrice(double purchasePrice) {
if (purchasePrice <= 0) {
throw new IllegalArgumentException("Purchase price can't be negative or zero");
}
this.retailPrice = purchasePrice * 1.5;
this.purchasePrice = purchasePrice;
}
/**
* set number in stock when object is created
*
* @param numberRecieved
*/
public void setNumberInStock(int numberRecieved) {
if (numberRecieved <= 0) {
throw new IllegalArgumentException("Number recieved can't be negative or zero");
}
this.numberInStock = numberRecieved;
}
/**
* Change the number od issues of the given object
*
* @param numberToBuy
*/
public void SellLiterature(int numberToBuy) {
numberInStock = numberInStock - numberToBuy;
if (numberInStock < 0) {
numberInStock = 0;
}
}
public boolean checkForNull(String checkString, String parameterName) {
boolean check = false;
try {
if (checkString != null) {
check = true;
}
} catch (NullPointerException e) {
System.out.println(parameterName + ":" + "is null");
}
return check;
}
/**
* updates the number of issues of the given object
*
* @param numberToAdd
*/
public void AddToStock(int numberToAdd) {
numberInStock = numberInStock + numberToAdd;
}
/**
* set the year this book was issued
*
* @param year
*/
private void setYearIssued(int year) {
if (year <= 0) {
throw new IllegalArgumentException("year can't be negative or zero");
}
this.year = year;
}
/**
*
* @return year issued
*/
public int getYearIssued() {
return this.year;
}
/**
* sets the name of publisher
*
* @param publisher
*/
private void setPublisher(String publisher) {
if (publisher == null) {
publisher = "";
}
publisher.trim();
if (publisher.isEmpty()) {
throw new IllegalArgumentException("Publisher can't be null");
}
this.publisher = publisher.toUpperCase();
}
/**
*
* @return name of publisher
*/
public String getPublisher() {
return this.publisher.toUpperCase();
}
}