Repository navigation
Expand file tree
/
Copy pathWoodItem.java
More file actions
126 lines (112 loc) · 2.48 KB
/
Copy pathWoodItem.java
File metadata and controls
126 lines (112 loc) · 2.48 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
/**
* Class defining the elements of a wood type
*/
package model;
import java.text.NumberFormat;
/**
* @author Trevor Helms
*
*/
public class WoodItem {
String type;
Double baseDeliveryTime;
Double price;
Double realizedDeliveryTime;
/**
* Default constructor
*/
public WoodItem() {
this.type = "Empty";
this.baseDeliveryTime = 0.0;
this.price = 0.0;
this.realizedDeliveryTime = 0.0;
}
/**
* Constructor of a WoodItem element with parameters
* @param type Name of the wood type
* @param baseDeliveryTime base delivery time
* @param price price per Bare Foot
*/
public WoodItem(String type, Double baseDeliveryTime, Double price) {
this.type = type;
this.baseDeliveryTime = baseDeliveryTime;
this.price = price;
this.realizedDeliveryTime = baseDeliveryTime;
}
/**
* Returns the realized (actual) delivery time after mulitplying by the modifier
*
* @param qty BF of the wood being ordered
* @return Realized delivery time
*/
public Double getRealizedDeliveryTime(int qty) throws Exception {
double modifier = 0;
if (qty <= 0) {
throw new Exception("Length of wood cannot be 0");
}
else if (qty > 0 && qty <= 100) {
modifier = 1;
}
else if (qty > 100 && qty <= 200) {
modifier = 2;
}
else if (qty > 200 && qty <= 300) {
modifier = 3;
}
else if (qty > 300 && qty <= 400) {
modifier = 4;
}
else if (qty > 400 && qty <= 500) {
modifier = 5;
}
else if (qty > 500 && qty <= 1000) {
modifier = 5.5;
}
else {
throw new Exception("Cannot order more than 1000 BF of any one type of wood.");
}
return modifier * baseDeliveryTime;
}
/**
* Get the type of Wood
*
* @return Name of the WoodItem
*/
public String getType() {
return type;
}
/**
* Get the base delivery time
*
* @return the baseDeliverytime
*/
public Double getBaseDeliveryTime() {
return baseDeliveryTime;
}
/**
*
* Get the price per Bare Foot
*
* @return the price for 1 Bare Foot of this WoodItem
*/
public Double getPrice() {
return price;
}
/**
* Return the price for 1 Bare Foot in a currency formatted way
* @return Currency formatted price
*/
public String getPriceFormatted() {
NumberFormat formatter = NumberFormat.getCurrencyInstance();
String moneyString = formatter.format(price);
return moneyString;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
* You may implement this method to fit your needs
*/
@Override
public String toString() {
return type;
}
}