-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPracticingClasses.java
More file actions
165 lines (144 loc) · 3.68 KB
/
PracticingClasses.java
File metadata and controls
165 lines (144 loc) · 3.68 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
public class PracticingClasses {
public static void main(String args[]) {
// Task 1
enum ClothingType {
DRESS,
SHIRT,
TROUSER,
JACKET,
ACCESSORY,
}
enum Size {
XS,
S,
M,
L,
XL,
XXL,
}
switch(ClothingType) {
case DRESS:
System.out.println("Elegant wear made from traditional fabric");
break;
case SHIRT:
System.out.println("Perfect for formal and casual African wear");
break;
case TROUSER:
System.out.println("Elegant wear made from traditional fabric");
break;
case JACKET:
System.out.println("Elegant wear made from traditional fabric");
break;
case ACCESSORY:
System.out.println("Elegant wear made from traditional fabric");
break;
}
// Task 2
class ClothingItem{
private String name;
private double price;
private Size size;
private ClothingType type;
public int itemCount=0;
public String getName(){
return name;
}
public double getPrice(){
return price;
}
public Size getSize(){
return size;
}
public ClothingType getType(){
return type;
}
public ItemCount getItemCount(){
return itemCount;
}
public void setName( String newName){
name = newName;
}
public void setPrice( String newPrice){
price = newPrice;
}
public void setSize( String newSize){
size = newSize;
}
public void setType( String newType){
type = newType;
}
//Task 3
public ClothingItem(String ModelName,double ModelPrice,Size ModelSize,ClothingType ModelType){
name = ModelName;
price = ModelPrice;
size = ModelSize ;
type = ModelType;
itemCount++;
}
public ClothingItem(String ModelName,ClothingType ModelType){
name = ModelName;
type = ModelType;
size = Size.M;
price = 1000;
itemCount++;
}
public ClothingItem(){
name="Generic African Wear";
price=1000;
size=Size.M;
type=ClothingType.SHIRT;
itemCount++;
}
class ZimStyleApp{
ClothingItem item1 = new ClothingItem(OOP,85,Size.XL,ClothingType.DRESS)
ClothingItem item2 = new ClothingItem(CS,ClothingType.JACKET)
ClothingItem item3 = new ClothingItem()
}
//Task 4
public void displayInfo(){
System.out.println("Name: " + name + " | Type: " + type + " | Size: " + size + " | Price: " + price + " ZiG");
}
public void displayInfo(boolean showPrice){
if(showPrice){
System.out.println("Name: " + name + " | Type: " + type + " | Size: " + size + " | Price: " + price + " ZiG");
}
else{
System.out.println("Name: " + name + " | Type: " + type + " | Size: " + size);
{
}
//Task 6
public void applyDiscount(){
if(price>50) {
double discount=price*(10/100);
double Newprice=price-discount;
System.out.println("The amount of your discount is " +discount+" and the new price is "+Newprice+ " ZiG");
}
else{
System.out.println("No discount");
}
}
//Task 7
ClothingItem[] inventory =new ClothingItem[5];
inventory[0] = object1;
inventory[1] = object2;
inventory[2] = object3;
inventory[3] = object4;
inventory[4] = object5;
for (int i=0,1<inventory.length,i++){
inventory[i].displayInfo();
}
System.out.println("\nTotal items created: " +ClothingItem.getItemCount());
//Task 8
for (int i=0,1<inventory.length,i++){
inventory[i].applyDiscount();
}
//Task 9
double Total=0;
for (int i = 0; i < inventory.length; i++) {
Total += inventory[i].getPrice();
}
double averagePrice = Total/inventory.length;
System.out.printf("The average price is"+ averagePrice);
}
}
}