-
Notifications
You must be signed in to change notification settings - Fork 0
/
bars.java
114 lines (103 loc) · 2.34 KB
/
bars.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
public class bars{
class Bar{
private long length;
private long price;
public Bar(long l, long p){
this.length = l;
this.price = p;
}
public String toString(){
return ""+this.length;
}
public long get_length(){
return this.length;
}
public long get_price(){
return this.price;
}
}
class Bars{
//this class shows how Bar is cut
private Bar parent;
//this is bar taken from pricelist
private long remainder;
//this shows what length is still available
private long[] tab = new long[1];
//lengths of sections which are made from paren bar
private int how_many = 0;
//number of sections
public Bars(Bar a){
this.remainder = a.length;
this.parent = a;
}
public String toString(){
String help = ""+this.parent;
for(int i=0;i<how_many;i++){
help = help+" "+tab[i];
}
return help;
}
public boolean addBar(long l){
//returns true if bar fits in remainder, else return false
//if tab is too small to add next section it is going to be enlaged two times
if(this.remainder >= l){
if(this.how_many < this.tab.length){
tab[how_many] = l;
}else{
long[] help = new long[2*how_many];
for(int i=0;i<how_many;i++){
help[i] = this.tab[i];
}
help[how_many] = l;
this.tab = help;
}
how_many++;
this.remainder = remainder - l;
return true;
}else{
return false;
}
}
}
class BarsSet{
//this shows how bars from pricelists are cut
private Bars[] tab = new Bars[1];
private int how_many = 0;
//shows how many bars are in table
private long remainders = 0;
//this is going to be final amount of remainders
private long price = 0;
//final price
/*public void removeBars(){
if(how_many != 0){
tab[how_many-1] = null;
how_many--;
}
}*/
public void addBars(Bars a){
if(this.how_many < this.tab.length){
tab[how_many] = a;
}else{
Bars[] help = new Bars[2*how_many];
for(int i=0;i<how_many;i++){
help[i] = this.tab[i];
}
help[how_many] = a;
this.tab = help;
}
how_many++;
this.remainders = this.remainders + a.remainder;
this.price = this.price + a.parent.price;
}
public long get_price(){
return this.price;
}
public String toString(){
String help = this.price+"\n"+this.remainders;
for(int i=0;i<how_many;i++){
help = help+"\n"+this.tab[i];
}
return help;
}
}
}