-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.txt
1207 lines (1071 loc) · 36.7 KB
/
test.txt
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
class Barband {
private int id;
private ArrayList<Cow> cows = new ArrayList<>();
private int capacity;
private HashMap<Food,Integer> feed = new HashMap<>();
public Barband(int id, int capacity) {
this.id = id;
this.capacity = capacity;
}
public int getId() {
return id;
}
public ArrayList<Cow> getCows() {
return cows;
}
public int getCapacity() {
return capacity;
}
public HashMap<Food, Integer> getFeed() {
return feed;
}
public void addCow(Cow cow){
cows.add(cow);
}
private boolean hasFood(Food food){
for (Food f : feed.keySet()) {
if (f.getName().equals(food.getName()))
return true;
}
return false;
}
public void feedBarband(Food food, int amount){
if (hasFood(food)){
feed.replace(food,feed.get(food) + amount);
}
else {
feed.put(food,amount);
}
}
private Cow[] getSortedCows(){
Cow[] sortedCows = new Cow[cows.size()];
sortedCows = cows.toArray(sortedCows);
Cow temp;
for (int i = 0; i < sortedCows.length; i++) {
for (int j = 1; j < sortedCows.length - i; j++) {
if (sortedCows[j - 1].getHunger() < sortedCows[j].getHunger()){
temp = sortedCows[j - 1];
sortedCows[j - 1] = sortedCows[j];
sortedCows[j] = temp;
}
else if (sortedCows[j - 1].getHunger() == sortedCows[j].getHunger()){
if (sortedCows[j - 1].getAge() > sortedCows[j].getAge()){
temp = sortedCows[j - 1];
sortedCows[j - 1] = sortedCows[j];
sortedCows[j] = temp;
}
else if (sortedCows[j - 1].getAge() == sortedCows[j].getAge()){
if (sortedCows[j - 1].getId() > sortedCows[j].getId()){
temp = sortedCows[j - 1];
sortedCows[j - 1] = sortedCows[j];
sortedCows[j] = temp;
}
}
}
}
}
return sortedCows;
}
private Food[] getSortedFeed(){
Food[] sortedFeed = new Food[feed.size()];
sortedFeed = feed.keySet().toArray(sortedFeed);
Food temp;
for (int i = 0; i < sortedFeed.length; i++) {
for (int j = 1; j < sortedFeed.length - i; j++) {
if (sortedFeed[j - 1].getInterestDegree() < sortedFeed[j].getInterestDegree()){
temp = sortedFeed[j - 1];
sortedFeed[j - 1] = sortedFeed[j];
sortedFeed[j] = temp;
}
}
}
return sortedFeed;
}
private int getAmountOfFeed(){
int amount = 0;
for (Food food : feed.keySet()) {
amount += feed.get(food);
}
return amount;
}
private boolean areCowsHungry(){
for (Cow cow : cows) {
if (cow.getHunger() > 0)
return true;
}
return false;
}
public void feedCows(){
while (areCowsHungry() && getAmountOfFeed() > 0){
for (Cow cow : getSortedCows()) {
if (cow.getHunger() > 0 || getAmountOfFeed() > 0) {
for (Food food : getSortedFeed()) {
cow.eat(food);
feed.replace(food, feed.get(food) - 1);
if (feed.get(food) == 0)
feed.remove(food);
break;
}
}
}
}
}
public void removeCow(int cowId){
for (Cow cow : cows) {
if (cow.getId() == cowId){
cows.remove(cow);
break;
}
}
}
}
class Storage {
private int capacity;
private HashMap<Food,Integer> feed = new HashMap<>();
public int getCapacity() {
return capacity;
}
public HashMap<Food, Integer> getFeed() {
return feed;
}
public boolean hasEnoughFood(String foodName, int amount){
for (Food food : feed.keySet()) {
if (food.getName().equals(foodName)){
return feed.get(food) >= amount;
}
}
return false;
}
public void decreaseFood(String foodName, int amount){
for (Food food : feed.keySet()) {
if (food.getName().equals(foodName)) {
feed.replace(food, feed.get(food) - amount);
break;
}
}
}
private boolean hasFood(Food food) {
for (Food f : feed.keySet()) {
if (f.getName().equals(food.getName()))
return true;
}
return false;
}
public void addFood(Food food, int amount){
if (hasFood(food)){
feed.replace(food,feed.get(food) + amount);
}
else {
feed.put(food,amount);
}
}
public void increaseCapacity(int amount){
capacity += amount;
}
}
class Cow {
private int id;
private int age;
private int hunger;
private int weight;
private int milk;
private int producedMilk;
private Barband barband;
private int noMilkDays;
private HashMap<Food,Integer> feedInDay = new HashMap<>();
private int neededFood;
private int maxPower;
public static int maxAge = 50;
public static int minWeight = 100;
public Cow(int id, Barband barband) {
this.id = id;
this.barband = barband;
this.weight = 200;
this.age = 0;
this.hunger = 0;
this.milk = 0;
this.producedMilk = 0;
this.noMilkDays = 0;
this.neededFood = 5;
this.maxPower = 25;
}
public int getId() {
return id;
}
public int getAge() {
return age;
}
public int getHunger() {
return hunger;
}
public int getWeight() {
return weight;
}
public int getMilk() {
return milk;
}
public int getMaxPower() {
return maxPower;
}
public int getProducedMilk() {
return producedMilk;
}
public Barband getBarband() {
return barband;
}
public void increaseNeededFood(){
neededFood += (age - 1)/10;
}
public void increseMaxPower(){
maxPower += 5 * (age - 1)/ 10;
}
public int getNoMilkDays() {
return noMilkDays;
}
public int getNeededFood() {
return neededFood;
}
public void makeHungry(){
hunger += neededFood;
feedInDay.clear();
}
public void loseWeight(){
weight -= hunger;
}
public void gainWeight(){
for (Food food : feedInDay.keySet()) {
weight += feedInDay.get(food) * food.getWeightPerKilo();
}
}
private boolean hasEatenFood(Food food){
for (Food f : feedInDay.keySet()) {
if (f.getName().equals(food.getName()))
return true;
}
return false;
}
public void eat(Food food){
hunger -= 1;
if (hasEatenFood(food))
feedInDay.replace(food,feedInDay.get(food) + 1);
else
feedInDay.put(food,1);
}
public void produceMilk(){
for (Food food : feedInDay.keySet()) {
this.milk += feedInDay.get(food) * food.getMilkPerKilo();
}
if (milk > maxPower)
milk = maxPower;
}
public void milk() {
this.producedMilk += this.milk;
this.milk = 0;
noMilkDays = 0;
}
public void move(Barband barband){
this.barband = barband;
}
public void increaseNoMilkDays(){
noMilkDays++;
}
public void dryMilk(){
milk = 0;
}
public void grow(){
age++;
}
}
class Food {
private String name;
private int milkPerKilo;
private int weightPerKilo;
private int interestDegree;
public Food(String name, int milkPerKilo, int weightPerKilo, int interestDegree) {
this.name = name;
this.milkPerKilo = milkPerKilo;
this.weightPerKilo = weightPerKilo;
this.interestDegree = interestDegree;
}
public String getName() {
return name;
}
public int getMilkPerKilo() {
return milkPerKilo;
}
public int getWeightPerKilo() {
return weightPerKilo;
}
public int getInterestDegree() {
return interestDegree;
}
}
class Tank {
private int id;
private int capacity;
private int emptySpace;
private int[] expirationDate = new int[3];
public Tank(int id, int capacity) {
this.id = id;
this.capacity = capacity;
this.emptySpace = capacity;
expirationDate[0] = expirationDate[1] = expirationDate[2] = 0;
}
public int getId() {
return id;
}
public int getCapacity() {
return capacity;
}
public int getEmptySpace() {
return emptySpace;
}
public int[] getExpirationDate() {
return expirationDate;
}
public void setExpirationDate(int[] date) {
expirationDate[2] = date[2] + 3;
expirationDate[1] = date[1];
expirationDate[0] = date[0];
if (expirationDate[2] > 30){
expirationDate[2] -= 30;
expirationDate[1] += 1;
if (expirationDate[1] > 12){
expirationDate[1] = 1;
expirationDate[0] += 1;
}
}
}
public void addMilk(int amount){
this.emptySpace -= amount;
}
public void sellMilk(int amount){
this.emptySpace += amount;
}
public void empty(){
this.emptySpace = capacity;
}
}
class View {
public Scanner scanner = new Scanner(System.in);
private Food[] getSortedFeed(HashMap<Food,Integer> feed){
Food[] sortedFeed = new Food[feed.size()];
sortedFeed = feed.keySet().toArray(sortedFeed);
Food temp;
for (int i = 0; i < sortedFeed.length; i++) {
for (int j = 1; j < sortedFeed.length - i; j++) {
if (sortedFeed[j - 1].getInterestDegree() < sortedFeed[j].getInterestDegree()){
temp = sortedFeed[j - 1];
sortedFeed[j - 1] = sortedFeed[j];
sortedFeed[j] = temp;
}
}
}
return sortedFeed;
}
private Tank[] getSortedTanks(ArrayList<Tank> tanks){
Tank[] sortedTanks = new Tank[tanks.size()];
sortedTanks = tanks.toArray(sortedTanks);
Tank temp;
for (int i = 0; i < sortedTanks.length; i++) {
for (int j = 1; j < sortedTanks.length - i; j++) {
if (sortedTanks[j - 1].getId() > sortedTanks[j].getId()){
temp = sortedTanks[j - 1];
sortedTanks[j - 1] = sortedTanks[j];
sortedTanks[j] = temp;
}
}
}
return sortedTanks;
}
private Cow[] getSortedCows(ArrayList<Cow> cows){
Cow[] sortedCows = new Cow[cows.size()];
sortedCows = cows.toArray(sortedCows);
Cow temp;
for (int i = 0; i < sortedCows.length; i++) {
for (int j = 1; j < sortedCows.length - i; j++) {
if (sortedCows[j - 1].getProducedMilk() < sortedCows[j].getProducedMilk()){
temp = sortedCows[j - 1];
sortedCows[j - 1] = sortedCows[j];
sortedCows[j] = temp;
}
else if (sortedCows[j - 1].getProducedMilk() == sortedCows[j].getProducedMilk()){
if (sortedCows[j - 1].getId() > sortedCows[j].getId()){
temp = sortedCows[j - 1];
sortedCows[j - 1] = sortedCows[j];
sortedCows[j] = temp;
}
}
}
}
return sortedCows;
}
private int[] bubbleSort(int[] cowsId){
int temp;
for (int i = 0; i < cowsId.length; i++) {
for (int j = 1; j < cowsId.length - i; j++) {
if (cowsId[j - 1] > cowsId[j]){
temp = cowsId[j - 1];
cowsId[j - 1] = cowsId[j];
cowsId[j] = temp;
}
}
}
return cowsId;
}
public void showBarband(Barband barband){
System.out.println("barband " + barband.getId());
System.out.println("number of cows: " + barband.getCows().size());
System.out.println("capacity: " + barband.getCapacity());
System.out.println("the remaining food:");
for (Food food : getSortedFeed(barband.getFeed())) {
System.out.println(food.getName() + " " + barband.getFeed().get(food));
}
System.out.println("cows:");
int[] cowsId = new int[barband.getCows().size()];
int itr = 0;
for (Cow cow : barband.getCows()) {
cowsId[itr] = cow.getId();
itr++;
}
for (int i : bubbleSort(cowsId)) {
System.out.println(i);
}
}
public void showCow(Cow cow){
System.out.println("cow " + cow.getId());
System.out.println("age: " + cow.getAge());
System.out.println("hunger: " + cow.getHunger());
System.out.println("weight: " + cow.getWeight());
System.out.println("milk: " + cow.getMilk());
System.out.println("milk produced: " + cow.getProducedMilk());
}
public void printInvalidDate(){
System.out.println("invalid date");
}
public void printInvalidBarband(){
System.out.println("invalid barband");
}
public void printInvalidCow(){
System.out.println("invalid cow");
}
public void printNotEnoughSpace(int barbandId){
System.out.println("there is not enough space in barband " + barbandId);
}
public void printNotEnoughSpace(){
System.out.println("there is not enough space");
}
public void printNoMilk(){
System.out.println("cow has no milk");
}
public void printMilkedSuccess(){
System.out.println("cow milked successfully");
}
public void printCowAdded(int cowId){
System.out.println("cow added. cow num: " + cowId);
}
public void showFarm(DairyFarm dairyFarm){
System.out.println("dairy farm");
System.out.println("number of barbands: " + dairyFarm.getBarbands().size());
System.out.println("number of cows: " + dairyFarm.getCows().size());
System.out.println("storage capacity: " + dairyFarm.getStorage().getCapacity());
System.out.println("milk tank num: " + dairyFarm.getTanks().size());
System.out.println("max milk production: " + dairyFarm.getMaxMilkProduction());
}
public void showStorage(Storage storage){
System.out.println("storage");
System.out.println("capacity: " + storage.getCapacity());
System.out.println("inventory:");
for (Food food : getSortedFeed(storage.getFeed())) {
System.out.println(food.getName() + " " + storage.getFeed().get(food));
}
}
public void showTanks(ArrayList<Tank> tanks){
for (Tank tank : getSortedTanks(tanks)) {
System.out.println("tank " + tank.getId());
System.out.println("capacity: " + tank.getCapacity());
System.out.println("empty space: " + tank.getEmptySpace());
if (tank.getEmptySpace() != tank.getCapacity()) {
if (tank.getExpirationDate()[2] > 10 && tank.getExpirationDate()[1] > 10)
System.out.println("expiration date: " + tank.getExpirationDate()[0] +
"/" + tank.getExpirationDate()[1] + "/" + tank.getExpirationDate()[2]);
else if (tank.getExpirationDate()[2] > 10 && tank.getExpirationDate()[1] < 10)
System.out.println("expiration date: " + tank.getExpirationDate()[0] +
"/" + "0" + tank.getExpirationDate()[1] + "/" + tank.getExpirationDate()[2]);
if (tank.getExpirationDate()[2] < 10 && tank.getExpirationDate()[1] > 10)
System.out.println("expiration date: " + tank.getExpirationDate()[0] +
"/" + tank.getExpirationDate()[1] + "/" + "0" + tank.getExpirationDate()[2]);
else if (tank.getExpirationDate()[2] < 10 && tank.getExpirationDate()[1] < 10)
System.out.println("expiration date: " + tank.getExpirationDate()[0] +
"/" + "0" + tank.getExpirationDate()[1] + "/" + "0" + tank.getExpirationDate()[2]);
}
else
System.out.println("expiration date:");
}
}
public void printInvalidfood(){
System.out.println("invalid food name");
}
public void printNotEnoughMilk(){
System.out.println("there is not enough milk");
}
public void printSellSuccess(){
System.out.println("milk sold successfully");
}
public void printButcherSuccess(){
System.out.println("cow butchered successfully");
}
public void printMoveSuccess(){
System.out.println("cow moved successfully");
}
public void printInvalidTank(){
System.out.println("invalid tank");
}
public void showRanks(ArrayList<Cow> cows){
for (Cow cow : getSortedCows(cows)) {
System.out.print(cow.getId());
System.out.print(" ");
System.out.println(cow.getProducedMilk());
}
}
public void printInvalidCommand(){
System.out.println("invalid command");
}
}
public class DairyFarm {
private ArrayList<Barband> barbands = new ArrayList<>();
private ArrayList<Cow> cows = new ArrayList<>();
private ArrayList<Tank> tanks = new ArrayList<>();
private ArrayList<Food> feed = new ArrayList<>();
private Storage storage = new Storage();
private View view = new View();
private int[] date = new int[3];
private int barbandIdGenerator = 0;
private int tankIdGenerator = 0;
private int maxMilkProduction;
public DairyFarm() {
addFoodToFeed("barley",4,4,80);
addFoodToFeed("alfalfa",3,3,60);
addFoodToFeed("straw",2,0,20);
maxMilkProduction = 0;
}
public ArrayList<Barband> getBarbands() {
return barbands;
}
public ArrayList<Cow> getCows() {
return cows;
}
public ArrayList<Tank> getTanks() {
return tanks;
}
public Storage getStorage() {
return storage;
}
public int getMaxMilkProduction() {
for (Cow cow : cows) {
maxMilkProduction += cow.getMaxPower();
}
return maxMilkProduction;
}
private void setDate(String date) {
int year = Integer.valueOf(date.split("/")[0]);
int month = Integer.valueOf(date.split("/")[1]);
int day = Integer.valueOf(date.split("/")[2]);
this.date[0] = year;
this.date[1] = month;
this.date[2] = day;
}
private boolean isValidDate(String date){
if (!date.matches("\\d{4}/\\d{2}/\\d{2}"))
return false;
else {
String[] details = date.split("/");
if (details[0].charAt(0) == '0' || Integer.valueOf(details[1]) > 12 || Integer.valueOf(details[2]) > 30
|| Integer.valueOf(details[1]) == 0 || Integer.valueOf(details[2]) == 0)
return false;
}
return true;
}
private void addBarband(int capacity){
barbandIdGenerator++;
Barband newBarband = new Barband(barbandIdGenerator, capacity);
barbands.add(newBarband);
}
private boolean isValidBarband(int barbandId){
for (Barband barband : barbands) {
if (barband.getId() == barbandId)
return true;
}
return false;
}
private void showBarband(int barbandId){
for (Barband barband : barbands) {
if (barband.getId() == barbandId) {
view.showBarband(barband);
break;
}
}
}
private boolean isValidCow(int cowId){
for (Cow cow : cows) {
if (cow.getId() == cowId)
return true;
}
return false;
}
private void showCow(int cowId){
for (Cow cow : cows) {
if (cow.getId() == cowId) {
view.showCow(cow);
break;
}
}
}
private boolean hasBarbandSpace(int barbandId){
for (Barband barband : barbands) {
if (barband.getId() == barbandId)
return barband.getCapacity() > barband.getCows().size();
}
return false;
}
private int[] getCowsId(){
int[] cowsId = new int[cows.size()];
int itr = 0;
for (Cow cow : cows) {
cowsId[itr] = cow.getId();
itr++;
}
for (int i = 0; i < cowsId.length; i++) {
for (int j = 1; j < cowsId.length - i; j++) {
int temp;
if (cowsId[j - 1] > cowsId[j]){
temp = cowsId[j - 1];
cowsId[j - 1] = cowsId[j];
cowsId[j] = temp;
}
}
}
return cowsId;
}
private void addCow(int barbandId){
int cowIdGenerator;
if (cows.size() == 0)
cowIdGenerator = 1;
else{
if (getCowsId()[cows.size() - 1] == cows.size()) {
cowIdGenerator = cows.size() + 1;
}
else {
cowIdGenerator = 1;
for (int i : getCowsId()) {
if (cowIdGenerator != i) {
break;
}
cowIdGenerator++;
}
}
}
for (Barband barband : barbands) {
if (barband.getId() == barbandId){
Cow newCow = new Cow(cowIdGenerator, barband);
barband.addCow(newCow);
cows.add(newCow);
break;
}
}
view.printCowAdded(cowIdGenerator);
}
private void addTank(int capacity){
tankIdGenerator++;
Tank newTank = new Tank(tankIdGenerator, capacity);
tanks.add(newTank);
}
private boolean hasFoodInStorage(String foodName, int amount){
return storage.hasEnoughFood(foodName, amount);
}
private void feedBarband(int barbandId, String foodName, int amount){
for (Barband barband : barbands) {
if (barband.getId() == barbandId){
for (Food food : feed) {
if (food.getName().equals(foodName)) {
barband.feedBarband(food, amount);
storage.decreaseFood(foodName,amount);
break;
}
}
}
}
}
private void feedCows(int barbandId){
for (Barband barband : barbands) {
if (barband.getId() == barbandId){
barband.feedCows();
break;
}
}
}
private void showStorage(){
view.showStorage(storage);
}
private void showTanks(){
view.showTanks(tanks);
}
private boolean hasTankSpace(int cowId, int tankId){
for (Cow cow : cows) {
if (cow.getId() == cowId){
for (Tank tank : tanks) {
if (tank.getId() == tankId){
return cow.getMilk() <= tank.getEmptySpace();
}
}
}
}
return false;
}
private boolean hasCowMilk(int cowId){
for (Cow cow : cows) {
if (cow.getId() == cowId)
return cow.getMilk() > 0;
}
return false;
}
private void milkCow(int cowId, int tankId){
for (Cow cow : cows) {
if (cow.getId() == cowId){
for (Tank tank : tanks) {
if (tank.getId() == tankId){
if (tank.getEmptySpace() == tank.getCapacity()){
tank.setExpirationDate(date);
}
tank.addMilk(cow.getMilk());
cow.milk();
view.printMilkedSuccess();
}
}
}
}
}
private boolean isValidFood(String foodName){
for (Food food : feed) {
if (food.getName().equals(foodName))
return true;
}
return false;
}
private boolean hasStorageSpace(int amount){
int emptySpace = storage.getCapacity();
for (Food food : storage.getFeed().keySet()) {
emptySpace -= storage.getFeed().get(food);
}
return amount <= emptySpace;
}
private void addFoodToStorage(String foodName, int amount){
for (Food food : feed) {
if (food.getName().equals(foodName)){
storage.addFood(food,amount);
break;
}
}
}
private boolean isValidTank(int tankId){
for (Tank tank : tanks) {
if (tank.getId() == tankId)
return true;
}
return false;
}
private boolean isMilkExpired(int tankId){
for (Tank tank : tanks) {
if (tank.getId() == tankId){
if (date[0] > tank.getExpirationDate()[0])
return true;
else if (date[0] == tank.getExpirationDate()[0]){
if (date[1] > tank.getExpirationDate()[1])
return true;
else if (date[1] == tank.getExpirationDate()[1]){
if (date[2] > tank.getExpirationDate()[2])
return true;
}
}
return false;
}
}
return false;
}
private boolean hasEnoughMilk(int tankId, int amount){
for (Tank tank : tanks) {
if (tank.getId() == tankId){
return tank.getCapacity() - tank.getEmptySpace() >= amount;
}
}
return false;
}
private void sellMilk(int tankId, int amount){
for (Tank tank : tanks) {
if (tank.getId() == tankId){
tank.sellMilk(amount);
break;
}
}
view.printSellSuccess();
}
private void emptyTank(int tankId){
for (Tank tank : tanks) {
if (tank.getId() == tankId){
tank.empty();
break;
}
}
}
private void cowDie(int cowId){
for (Cow cow : cows) {
if (cow.getId() == cowId){
for (Barband barband : barbands) {
if (barband.getId() == cow.getBarband().getId()){
barband.removeCow(cowId);
break;
}
}
cows.remove(cow);
break;
}
}
}
private void moveCow(int cowId, int barbandId){
for (Cow cow : cows) {
if (cow.getId() == cowId){
for (Barband barband : barbands) {
if (barband.getId() == cow.getBarband().getId())
barband.removeCow(cowId);
}
}
}
for (Cow cow : cows) {
if (cow.getId() == cowId){
for (Barband barband : barbands) {
if (barband.getId() == barbandId) {
cow.move(barband);
barband.addCow(cow);
}
}
}
}
view.printMoveSuccess();
}
public void increaseStorage(int amount){
storage.increaseCapacity(amount);
}
private void addFoodToFeed(String foodName, int milkPerKilo, int weightPerKilo, int interestDegree){
Food newFood = new Food(foodName,milkPerKilo,weightPerKilo,interestDegree);
feed.add(newFood);
}
public void passDay(){
ArrayList<Integer> dyingCows = new ArrayList<>();
for (Cow cow : cows) {