• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with ArrayList  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

People, I populei data so that it can facilicitar understanding of those who can help me.

This code put the main method blank just getting the list of data to be implemented according to the suggestions of you.

What do I need?




Order by my data terminal and a date for example:

Terminal 1 - "Data 1"
Dados...

Total valor por Data1: R$ 00,00

---------------------------------------

Terminal 1 - "Data 2"
Dados...

Total valor por Data2: R$ 00,00

-------------------------------------------------------
Total por terminal 1: Valor Data1 + Valor Data2
-------------------------------------------------------

Terminal 2 - Data 1
Dados...

Total valor por Data1: R$ 00,00

----------------------------------------

Terminal 2 - Data 2
Dados...

Total valor por Data2: R$ 00,00

------------------------------------------------------
Total por terminal 2: Valor Data1 + Valor Data2
-------------------------------------------------------


1. package padrao;
2.
3. import java.math.BigDecimal;
4. import java.util.ArrayList;
5. import java.util.List;
6.
7.
8.
9. public class Tratador {
10.
11. class Dado{
12.
13. private String terminal;
14. private String data;
15. private Long agencia;
16. private Long conta;
17. private Integer via;
18. private BigDecimal valor;
19.
20. public String getTerminal() {
21. return terminal;
22. }
23. public void setTerminal(String terminal) {
24. this.terminal = terminal;
25. }
26. public String getData() {
27. return data;
28. }
29. public void setData(String data) {
30. this.data = data;
31. }
32. public Long getAgencia() {
33. return agencia;
34. }
35. public void setAgencia(Long agencia) {
36. this.agencia = agencia;
37. }
38. public Long getConta() {
39. return conta;
40. }
41. public void setConta(Long conta) {
42. this.conta = conta;
43. }
44. public Integer getVia() {
45. return via;
46. }
47. public void setVia(Integer via) {
48. this.via = via;
49. }
50. public BigDecimal getValor() {
51. return valor;
52. }
53. public void setValor(BigDecimal valor) {
54. this.valor = valor;
55. }
56.
57.
58. }
59. public List<Dado>retornoConsulta(){
60.
61. List<Dado>listDados = new ArrayList<Dado>();
62.
63.
64. //1 dado:
65. Dado dado1 = new Dado();
66. dado1.setAgencia(new Long(128));
67. dado1.setConta(new Long(6029));
68. dado1.setData("01/01/2008");
69. dado1.setVia(new Integer(0));
70. dado1.setTerminal("1");
71. dado1.setValor(new BigDecimal(100));
72.
73. //2 dado:
74. Dado dado2 = new Dado();
75. dado2.setAgencia(new Long(128));
76. dado2.setConta(new Long(6029));
77. dado2.setData("12/10/2007");
78. dado2.setVia(new Integer(0));
79. dado2.setTerminal("1");
80. dado2.setValor(new BigDecimal(200));
81.
82. //3 dado:
83. Dado dado3 = new Dado();
84. dado3.setAgencia(new Long(128));
85. dado3.setConta(new Long(6029));
86. dado3.setData("12/10/2007");
87. dado3.setVia(new Integer(0));
88. dado3.setTerminal("1");
89. dado3.setValor(new BigDecimal(300));
90.
91. //4 dado:
92. Dado dado4 = new Dado();
93. dado4.setAgencia(new Long(128));
94. dado4.setConta(new Long(6029));
95. dado4.setData("12/10/2007");
96. dado4.setVia(new Integer(0));
97. dado4.setTerminal("1");
98. dado4.setValor(new BigDecimal(500));
99.
100. //5 dado:
101. Dado dado5 = new Dado();
102. dado5.setAgencia(new Long(128));
103. dado5.setConta(new Long(6029));
104. dado5.setData("12/10/2007");
105. dado5.setVia(new Integer(0));
106. dado5.setTerminal("2");
107. dado5.setValor(new BigDecimal(200));
108.
109. //6 dado:
110. Dado dado6 = new Dado();
111. dado6.setAgencia(new Long(128));
112. dado6.setConta(new Long(6029));
113. dado6.setData("12/10/2007");
114. dado6.setVia(new Integer(0));
115. dado6.setTerminal("2");
116. dado6.setValor(new BigDecimal(400));
117.
118. //7 dado:
119. Dado dado7 = new Dado();
120. dado7.setAgencia(new Long(128));
121. dado7.setConta(new Long(6029));
122. dado7.setData("25/11/2007");
123. dado7.setVia(new Integer(0));
124. dado7.setTerminal("2");
125. dado7.setValor(new BigDecimal(400));
126.
127. //8 dado:
128. Dado dado8 = new Dado();
129. dado8.setAgencia(new Long(128));
130. dado8.setConta(new Long(6029));
131. dado8.setData("25/11/2007");
132. dado8.setVia(new Integer(0));
133. dado8.setTerminal("2");
134. dado8.setValor(new BigDecimal(400));
135.
136. listDados.add(dado1);
137. listDados.add(dado5);
138. listDados.add(dado6);
139. listDados.add(dado7);
140. listDados.add(dado8);
141. listDados.add(dado4);
142. listDados.add(dado3);
143. listDados.add(dado2);
144.
145.
146. return listDados;
147. }
148.
149.
150. public static void main(String[] args) {
151.
152. List<Dado>listaDados = new Tratador().retornoConsulta();
153.
154.
155.
156. }
157. }
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what your question is. What are you asking?
 
Everson Junior
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Preciso de salvar os dados em um List para posteriormente exibi eles assim:


------------------------------------------
Terminal 1 - Date 01/01/2008

Cod 1 Values: R$100
Cod 2 Values: R$200

total per day 01/01/2008: R$300,00


Terminal 1 - Date 10/01/2008

Cod 3 Values: R$50
Cod 4 Values: R$30

total per day 10/01/2008: R$80,00


-----------------------------------------
Total per terminal 1 (300+80):R$380.00

-----------------------------------------

------------------------------------------
Terminal 2 - Date 01/01/2008

Cod 1 Values: R$10
Cod 2 Values: R$10

total per day 01/01/2008: R$20,00


Terminal 2 - Date 10/01/2008

Cod 3 Values: R$20
Cod 4 Values: R$20

total per day 10/01/2008: R$40,00


-----------------------------------------
Total per terminal 2 (300+80):R$380.00
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
English is my (and JavaRanch's) only language I'm afraid. Can you translate that?
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul is correct, I am afraid. It is JavaRanch policy that we post in English; very few of us can speak Spanish.
Please find a friend who can translate into English; we shall do our best to help.


And welcome to JavaRanch.
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Everson Junior:
Preciso de salvar os dados em um List para posteriormente exibi eles assim:


------------------------------------------
Terminal 1 - Date 01/01/2008

Cod 1 Values: R$100
Cod 2 Values: R$200

total per day 01/01/2008: R$300,00


Terminal 1 - Date 10/01/2008

Cod 3 Values: R$50
Cod 4 Values: R$30

total per day 10/01/2008: R$80,00


-----------------------------------------
Total per terminal 1 (300+80):R$380.00

-----------------------------------------

------------------------------------------
Terminal 2 - Date 01/01/2008

Cod 1 Values: R$10
Cod 2 Values: R$10

total per day 01/01/2008: R$20,00


Terminal 2 - Date 10/01/2008

Cod 3 Values: R$20
Cod 4 Values: R$20

total per day 10/01/2008: R$40,00


-----------------------------------------
Total per terminal 2 (300+80):R$380.00


he wants to know how to create a list in such a way that when he prints (System.out, web page, ??) the data, the output resembles like this:

------------------------------------------
Terminal 1 - Date 01/01/2008

Cod 1 Values: R$100
Cod 2 Values: R$200

total per day 01/01/2008: R$300,00


Terminal 1 - Date 10/01/2008

Cod 3 Values: R$50
Cod 4 Values: R$30

total per day 10/01/2008: R$80,00


-----------------------------------------
Total per terminal 1 (300+80):R$380.00

-----------------------------------------

------------------------------------------
Terminal 2 - Date 01/01/2008

Cod 1 Values: R$10
Cod 2 Values: R$10

total per day 01/01/2008: R$20,00


Terminal 2 - Date 10/01/2008

Cod 3 Values: R$20
Cod 4 Values: R$20

total per day 10/01/2008: R$40,00


-----------------------------------------
Total per terminal 2 (300+80):R$380.00
[ May 21, 2008: Message edited by: Manuel Leiria ]
 
Manuel Leiria
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll reply in English and translate to Portuguese (I think the OP is Brazilian).Is this procedure ok with the Ranch Policy's?


A tua classe Dado deve implementar o interface Comparable de forma a que possas ordenar a lista por Terminal e depois por Data. D� uma vista de olhos em Interface Comparable e
Sun Docs

Your class Dado must implement the Comparable interface in order to sort the list contents by Terminal and then by Date. Check Interface Comparable and
Sun Docs
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Manuel Leiria:
I'll reply in English and translate to Portuguese (I think the OP is Brazilian).Is this procedure ok with the Ranch Policy's?
. . . and I thought it was Spanish.



Excellent idea to post in two languages.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!