-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangleP.java
More file actions
89 lines (78 loc) · 2.55 KB
/
Copy pathRectangleP.java
File metadata and controls
89 lines (78 loc) · 2.55 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
import java.text.DecimalFormat;
public class RectangleP extends Product{
// The new line separator:
private final String NL = System.getProperty("line.separator");
/**
* This atribute stores the rectangle length in cm
*/
private double length;
/**
* This atribute stores the rectangle width in cm
*/
private double width;
/**
* Constructor method
*
* @param id
* the Product's id
* @param material
* the Product's material object
* @param lenth
* the rectangle's lenth in cm
* @param width
* the rectangle's width in cm
*/
public RectangleP(String id, Material material, double length, double width) {
super(id,material);
this.length = length;
this.width = width;
}
/**
* Getter method of atribute length
* @return atribute length
*/
public double getLength() {
return this.length;
}
/**
* Getter method of atribute width
* @return atribute width
*/
public double getWidth() {
return this.width;
}
/**
* This method calculates and returns the price of the
* rectangular product.
*
* The price of the rectangular product is calculated as:
* (its area in m2) x (price per m2 of the material)
*
* @return price of the rectangular product
*/
public double price() {
double area;
area = (length/100) * (width/100);
return (area * this.getMaterial().getPricePerm2());
}
/**
* This method generates and returns an String with
* the information of the rectangular product object.
*
* Note that this method has to access to the Material
* atribute of the class to get some information.
*/
public String toString() {
DecimalFormat myFormat1 = new DecimalFormat("#0.00");
DecimalFormat myFormat2 = new DecimalFormat("#,##0.00");
StringBuilder sb = new StringBuilder();
sb.append(super.toString());
sb.append("Product description: " + NL);
sb.append(" Rectangle made on " + this.getMaterial().getName() + NL);
sb.append(" Material price: " + myFormat1.format(this.getMaterial().getPricePerm2()) + " euros per m2" + NL);
sb.append(" Length: " + myFormat2.format(this.length) + " cm" + NL);
sb.append(" Width: " + myFormat2.format(this.width) + " cm" + NL);
sb.append("Product price: " + myFormat2.format(this.price()) + " euros" + NL);
return sb.toString();
}
}