-
Notifications
You must be signed in to change notification settings - Fork 0
/
Money.java
127 lines (105 loc) · 3.11 KB
/
Money.java
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
package lab1;
import java.util.ArrayList;
import java.util.Vector;
import java.util.Collections;
import java.util.Scanner;
public class Money {
private String valute;
private double cash;
public String getValute() {
return valute;
}
public void setValute(String valute) {
this.valute = valute;
}
public void setCash(double cash) {
this.cash = cash;
}
private boolean vid;
public Double getCash()
{
return this.cash;
}
public Money() {}
public Money(String valute, double cash, boolean vid)
{
this.valute = valute;
this.cash = cash;
this.vid = vid;
}
public Money(String valute, double cash)
{
this.valute = valute;
this.cash = cash;
}
public static void main(String[] args) {
Vector<Money> mon = getVec();
print(mon, 0);
avg(mon);
print(mon, 1);
System.out.println("Введите ключ");
Scanner sc = new Scanner(System.in);
int key1 = sc.nextInt();
delKey(mon, key1);
print(mon, 2);
refresh(mon);
print(mon,3);
}
public static Vector<Money> getVec()
{
Vector<Money> mon = new Vector<>();
Money rub = new Money("rubl", 150, true);
Money dol = new Money("dollar", 400, true);
Money cent = new Money("cent", 1, false);
Money crona = new Money("crona", 25, true);
Money bit = new Money("bitcoin", 26);
Collections.addAll(mon, rub, dol, cent, crona, bit);
return mon;
}
public static Vector<Money> refresh(Vector<Money> arr)
{
ArrayList<Double> cash = new ArrayList<>();
for (Money a: arr) {
if (a.valute.equals("AVG")) continue;
cash.add(a.cash);
}
double z = Collections.min(cash);
System.out.println("Minimum is "+z);
for (Money a:arr)
a.cash = a.cash - z;
return arr;
}
public static Vector<Money> delKey(Vector<Money> arr, int key)
{
System.out.println(arr.elementAt(key)+" removed");
arr.remove(key);
print(arr,3);
return arr;
}
public static void print(Vector<Money> arr, int x)
{
System.out.println("\nTask"+x);
for (Money a: arr)
System.out.println(a);
}
public static Vector<Money> avg(Vector<Money> arr)
{
float sum = 0;
int count = 0;
for (Money a: arr)
{
sum+=a.cash;
count++;
}
arr.add(0,new Money("AVG",sum/count));
return arr;
}
@Override
public String toString() {
String s;
if (this.valute.equals("AVG")) return this.valute + " , количество: "+this.cash;
if (this.valute.equals("bitcoin")) s = "криптовалюта";
else s = this.vid? "банкнота":"монета";
return this.valute + " , количество: "+this.cash+" , вид: "+s;
}
}