-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanel.java
More file actions
117 lines (94 loc) · 3.3 KB
/
Panel.java
File metadata and controls
117 lines (94 loc) · 3.3 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
package secondWeek;
/**
* This Panel class extends the RealEstate Class and implements the Panel Interface.
*
* It includes two additional properties: an integer field 'floor' and a boolean 'isInsulated'.
* The property type influences the price.
*/
import secondWeek.Genre.Genre;
import secondWeek.interfaces.PanelInterface;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Panel extends RealEstate implements PanelInterface {
private static final Logger LOGGER = Logger.getLogger(Panel.class.getName());
int floor;
boolean isInsulated;
public Panel(String city,
int price,
int sqm,
int numberOfRooms,
Genre genre,
int floor,
boolean isInsulated) {
super(city, price, sqm, numberOfRooms, genre);
this.floor = floor;
this.isInsulated = isInsulated;
}
@Override
public boolean hasSameAmount() { // Not yet implemented because instruction not understood.
return false;
}
/**
* This method calculates and returns the cost of a room in real estate.
*
* @return The cost of the room as a decimal number.
*/
@Override
public double roomPrice() {
LOGGER.info("Calling roomPrice method for Panel class\n");
return ((double) price * sqm) / numberOfRooms;
}
/**
* Calculates the total price of the property.
* If the property is insulated, a 5% increase is applied.
* Additionally, there's a 5% increase for properties on and below the 2nd floor,
* and a 5% decrease for properties on the 10th floor or above.
*
* @return the total cost of the property after all adjustments.
*/
@Override
public long totalPrice() {
LOGGER.info("Calling totalPrice of Panel class Method\n");
long total = (long) price * sqm;
double forInsulated = (0.05 * total);
try {
if (isInsulated) total += forInsulated;
if (floor <= 2) {
total += forInsulated;
} else if (floor >= 10) {
total -= forInsulated;
}
} catch (Exception exception) {
LOGGER.log(Level.WARNING, "Problem with arithmetic ", exception);
}
return total;
}
/**
* This method provides complete information about a Panel real estate.
* @return All the details of the real estate.
*/
@Override
public String toString() {
LOGGER.info("Calling toString method for Panel class\n");
String forma
= "\nPANEL\nFloor => %d\nIsInsulated => %b\nCity => %s\nPrice => %d\nSquare meter => %d\nNumber of rooms => %d\nGenre => %s\nTotal Price => %d\nAverage sqm per room => %d\n";
return String.format(forma,
floor,
isInsulated,
city,
price,
sqm,
numberOfRooms,
genre,
totalPrice(),
average()
);
}
public int getFloor() {
return floor;
}
public boolean isInsulated() {
return isInsulated;
}
}