forked from ghostmkg/programming-language
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDealer.java
More file actions
Latest commit
144 lines (116 loc) · 3.68 KB
/
Copy pathDealer.java
File metadata and controls
144 lines (116 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
packageAssignment;
importjava.util.ArrayList;
publicclassDealerextendsPerson
{
// instance variables
privatedoublecommisionRate;
privateAnimalanimal;
privateArrayList<Animal> animals = newArrayList<>();
publicDealer(Stringname , Stringid , Stringaddress , Stringcontact , doublecommisionRate , Animalanimal , ArrayList<Animal> animals)
{
super(name, id, address, contact);
this.commisionRate = commisionRate;
this.animal = animal;
this.animals = animals;
}
// Getters and Setters
publicdoublegetCommisionRate()
{
returncommisionRate;
}
publicvoidsetCommisionRate(doublecommisionRate)
{
this.commisionRate = commisionRate;
}
publicAnimalgetAnimal()
{
returnanimal;
}
publicvoidsetAnimal(Animalanimal)
{
this.animal = animal;
}
publicArrayList<Animal> getAnimals()
{
returnanimals;
}
publicvoidsetAnimals(ArrayList<Animal> animals)
{
this.animals = animals;
}
//method to add animals into dealers class
publicvoidaddAnimal(Animala)
{
if (!animals.contains(a))
{
animals.add(a);
System.out.println("Animal added...! ");
}
else
System.out.println("Animal is Already avalible!");
}
//method to remove animal , after confirming its avalibility
publicStringremoveAnimal(StringidTag)
{
for(Animalanimal : animals)
{
if(animal.getIdTag().equals(idTag))
{
animals.remove(animal);
animal.setAnimalStatus(true);
return"Animal removed";
}
}
return"animal with ID TAg :" + idTag + " not found";
}
//method to check animals avalibility
//using for each loop
publicStringcontains(StringidTag)
{
for(Animalanimal : animals)
{
if(animal.getIdTag().equals(idTag))
{
return"Animal avalible";
}
}
return"Animal not avalible";
}
//method to display all animal objects
//variable i help us keeep track of the number of animals
publicvoiddisplayObjects()
{
inti = 1;
for (Animalanimal : animals)
{
System.out.println("Animal " + i + " : \n" + animal );
i++;
}
}
// Method to calculate the commision earned by dealer
publicdoublecommision()
{
returnanimal.price()*(commisionRate/100) ;
}
//method for discount on commision in realtime, here we are keeping it 2%
publicdoublerealtimeDiscount()
{
doublediscount = commision() * 0.02;
doublecalculation = commision() - discount;
returncalculation;
}
// it is a commom method that keeps track of the finance of each class
//not added in to string method can only be shown when specifically called
publicvoidmanageFinance()
{
System.out.printf("%-25s%s%s%n%-25s%s%n%-25s%s%n%-25s%s%n" ,
"Commision Rate :" , commisionRate ,"%",
"Animal's Price :" , animal.price() , "Dealer's Commision :" ,
commision() , "Post Discount commision :" , realtimeDiscount());
}
//ToString method
publicStringtoString()
{
returnString.format("%s%n%s%-25s%s%n","----------- Dealer Information -----------", super.toString() , "Dealer's Commision :", commision() );
}
}