-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFurniture.java
More file actions
82 lines (72 loc) · 2.67 KB
/
Copy pathFurniture.java
File metadata and controls
82 lines (72 loc) · 2.67 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
public class Furniture {
String furnitureType;
String material;
double pricePerUnit;
int quantity;
public Furniture(){
furnitureType = "null";
material = "null";
pricePerUnit = 0;
quantity = 0;
}
public Furniture(String f, String m,double p, int q) // normal constructor
{
furnitureType = f;
material = m;
pricePerUnit = p;
quantity = q;
}
public String getMaterial() {return material;}
public String getFurnitureType() {return furnitureType;}
public double getPricePerunit() {return pricePerUnit;}
public int getQuantity() {return quantity;}
public void setMaterial(String mat) {material = mat;}
public void setFurnitureType(String fT) {furnitureType = fT;}
public void setPricePerUnit(double ppU) {pricePerUnit = ppU;}
public void setQuantity(int quan) {quantity = quan;}
public double calcPriceFurniture() {
double discount;
switch(material)
{
case "Wood": discount = (1-0.2);
break;
case "wood": discount = (1-0.2);
break;
case "Rattan": discount = (1-0.15);
break;
case "rattan": discount = (1-0.15);
break;
case "Metal": discount = (1-0.10);
break;
case "metal": discount = (1-0.10);
break;
case "Bamboo": discount = (1-0.05);
break;
case "bamboo": discount = (1-0.05);
break;
default: discount = 0.0;
break;
}
return pricePerUnit*quantity*discount;
}
public void afterMath() {
System.out.println(material+" "+furnitureType+", The price is RM"+calcPriceFurniture());
}
public static void main(String[] args) {
Furniture[] arrFurniture = new Furniture[4];
String[] material = {"Wood","Rattan","Metal","Bamboo"};
double highestPrice=0;
Furniture highestPriceMaterial = new Furniture();
for(int i=0;i<arrFurniture.length; i++) {
arrFurniture[i] = new Furniture("Chair", material[i], 100, 1);
System.out.println("\nFor the furniture :-");
arrFurniture[i].afterMath();
if(arrFurniture[i].calcPriceFurniture()>highestPrice){
highestPrice = arrFurniture[i].calcPriceFurniture();
highestPriceMaterial = arrFurniture[i];
}
}
System.out.println("\n\nThe most expensive furniture is :-");
highestPriceMaterial.afterMath();
}
}