-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMemoriaS.java
More file actions
executable file
·101 lines (76 loc) · 1.87 KB
/
MemoriaS.java
File metadata and controls
executable file
·101 lines (76 loc) · 1.87 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
public abstract class MemoriaS {
public static final int BYTE = 1;
public static final int KB = 2;
public static final int MB = 3;
public static final int GB = 4;
protected double total;
protected double utilizadoKb;
protected int unidade;
protected double getEspacoDisponivelKB(){
return this.total - this.utilizadoKb;
}
protected double getConverteKB(double _valor){
switch (this.unidade) {
case BYTE:
_valor = _valor / 1024;
break;
case MB:
_valor = _valor * 1024;
break;
case GB:
_valor = _valor * 1048576;
break;
}
return _valor;
}
abstract double getPerda();
abstract double getEspacoDisponivelRealKB();
public double getUtilizadoKB(){
return this.utilizadoKb;
}
public boolean GravaKB(int newTamanho){
if (this.getEspacoDisponivelRealKB() >= this.getConverteKB(newTamanho)){
this.utilizadoKb += this.getConverteKB(newTamanho);
return true;
} else
return false;
}
public String getUnidade(){
String _tmp;
switch (this.unidade) {
case BYTE:
_tmp = "BYTE";
break;
case KB:
_tmp = "KILOBYTE";
break;
case MB:
_tmp = "MEGABYTE";
break;
case GB:
_tmp = "GIGABYTE";
break;
default:
_tmp = "";
}
return _tmp;
}
public double getPercentualDisponivel(){
return (this.getEspacoDisponivelRealKB() / this.total) * 100;
}
public String toString(){
String _tmp = "Percentual Disponível " + this.getPercentualDisponivel() + "%\n";
_tmp += "Espaço Total " + this.total + "KB\n";
_tmp += "Espaço Disponível Real " + this.getEspacoDisponivelRealKB() + "KB\n";
_tmp += "Perda " + this.getPerda() + "%";
return _tmp;
}
public MemoriaS(int newTotal, int newUnidade){
this.utilizadoKb = 0;
this.unidade = newUnidade;
this.total = this.getConverteKB(newTotal);
}
public MemoriaS(int newTotal){
this(newTotal, KB);
}
}