Guest User

Untitled

a guest
Dec 9th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. public class Cachorro {
  2.  
  3. private String Raca;
  4. private String cor;
  5. private String nome;
  6. private String nome_dono;
  7. private int idade;
  8.  
  9.  
  10. public Cachorro(String Raca,String cor,String nome,String nome_dono, int idade){
  11.  
  12. this.Raca = Raca;
  13. this.cor = cor;
  14. this.nome =nome;
  15. this.nome_dono = nome_dono;
  16. this.idade = idade;
  17. }
  18. public String getRaca() {
  19. return Raca;
  20. }
  21. public void setRaca(String raca) {
  22. Raca = raca;
  23. }
  24. public String getCor() {
  25. return cor;
  26. }
  27. public void setCor(String cor) {
  28. this.cor = cor;
  29. }
  30. public String getNome() {
  31. return nome;
  32. }
  33. public void setNome(String nome) {
  34. this.nome = nome;
  35. }
  36. public String getNome_dono() {
  37. return nome_dono;
  38. }
  39. public void setNome_dono(String nome_dono) {
  40. this.nome_dono = nome_dono;
  41. }
  42. public int getIdade() {
  43. return idade;
  44. }
  45. public void setIdade(int idade) {
  46. this.idade = idade;
  47. }
  48.  
  49.  
  50. public String toString(){
  51. return "Nome Cao:" +getNome()+"nCor:" +getCor()+
  52. "nRaca:"+getRaca()+"nNome dono:"+ getNome_dono()+"nIdade:"+getIdade();
  53. }
  54.  
  55.  
  56. }
  57.  
  58. import java.util.List;
  59. import java.util.ArrayList;
  60.  
  61. public class Main {
  62.  
  63. public static void main(String[] args) {
  64.  
  65. List<String> dog = new ArrayList<>();
  66.  
  67. Cachorro cc = new Cachorro("rotweiller","preto","Flora","Cesar",8);
  68.  
  69. dog.add(cc);
  70. System.out.println(dog);
  71.  
  72. }
  73.  
  74. }
  75.  
  76. import java.util.List;
  77. import java.util.ArrayList;
  78.  
  79. class Cachorro {
  80. private String Raca;
  81. private String cor;
  82. private String nome;
  83. private String nome_dono;
  84. private int idade;
  85.  
  86. public Cachorro(String Raca,String cor,String nome,String nome_dono, int idade){
  87. this.Raca = Raca;
  88. this.cor = cor;
  89. this.nome =nome;
  90. this.nome_dono = nome_dono;
  91. this.idade = idade;
  92. }
  93. public String getRaca() {
  94. return Raca;
  95. }
  96. public void setRaca(String raca) {
  97. Raca = raca;
  98. }
  99. public String getCor() {
  100. return cor;
  101. }
  102. public void setCor(String cor) {
  103. this.cor = cor;
  104. }
  105. public String getNome() {
  106. return nome;
  107. }
  108. public void setNome(String nome) {
  109. this.nome = nome;
  110. }
  111. public String getNome_dono() {
  112. return nome_dono;
  113. }
  114. public void setNome_dono(String nome_dono) {
  115. this.nome_dono = nome_dono;
  116. }
  117. public int getIdade() {
  118. return idade;
  119. }
  120. public void setIdade(int idade) {
  121. this.idade = idade;
  122. }
  123. public String toString(){
  124. return "Nome Cao:" + getNome() + "nCor: " + getCor() +
  125. "nRaca: " + getRaca() +"nNome dono: " + getNome_dono() + "nIdade: " + getIdade();
  126. }
  127. }
  128.  
  129. class Main {
  130. public static void main(String[] args) {
  131. List<Cachorro> dogs = new ArrayList<>();
  132. dogs.add(new Cachorro("rotweiller", "preto", "Flora", "Cesar", 8));
  133. for (Cachorro dog : dogs) {
  134. System.out.println(dog);
  135. }
  136. }
  137.  
  138. }
  139.  
  140. List<Cachorro> listaCachorros = new ArrayList<>();
  141. Cachorro cachorro = new Cachorro("rotweiller","preto","Flora","Cesar",8);
  142.  
  143. listaCachorros.add(cachorro);
  144.  
  145. // imprimir os dados do objeto 'cachorro' (adicionado na lista)
  146. System.out.println(cachorro.ToString());
  147.  
  148. // imprimir os dados de todos os objetos da lista
  149. for(Cachorro c : listaCachorros)
  150. {
  151. System.out.println(c.ToString());
  152. }
  153.  
  154. public static void main(String[] args) {
  155. List<Cachorro> dog = new ArrayList<>();
  156.  
  157. Cachorro cc = new Cachorro("rotweiller", "preto", "Flora", "Cesar", 8);
  158.  
  159. dog.add(cc);
  160. System.out.println(dog);
  161. }
  162.  
  163. List<Cachorro> dog = new ArrayList<>();
  164.  
  165. dog.add(cc.toString());
Add Comment
Please, Sign In to add comment