Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1.  
  2. package javaapplication1;
  3. import java.util.*;
  4. import java.io.Serializable;
  5. import java.util.Arrays;
  6. import java.util.HashMap;
  7. import java.util.Map;
  8.  
  9. public class JavaApplication1 {
  10.  
  11. static int i = 0;
  12. public static void main(String[] args) {
  13.  
  14. Pony test = new Pony("Твайлайт","Фиолетовый","Звезда");
  15. MyContainer cont = new MyContainer(5);
  16. i = 1;
  17. cont.insert(0, "Mys");
  18. cont.insert(1, test);
  19. cont.ShowAllElem();
  20. }
  21.  
  22. }
  23. class MyContainer{
  24. private Map ponylist;
  25. private int maxSize;
  26. private int ElemCount;
  27.  
  28. public MyContainer(int maxSize){
  29. this.maxSize = maxSize;
  30. this.ponylist = new HashMap<Integer, Object>();
  31. ElemCount = 0;
  32. }
  33. public void ShowAllElem(){
  34. int i=0;
  35. for(i=0;i<ponylist.size();i++){
  36. System.out.println(ponylist.get(i));
  37. }
  38. }
  39. public Object ShowElem(int index){
  40. if(ponylist.containsKey(index)){
  41. return ponylist.get(index);
  42. }
  43. else{
  44. return 1;
  45. }
  46.  
  47. }
  48. public void Remove(int index){
  49. ponylist.remove(index);
  50. ElemCount--;
  51. }
  52.  
  53.  
  54. public void insert(int index, Object elem){
  55. if(ElemCount<maxSize){
  56. ponylist.put(index, elem);
  57. ElemCount++;
  58. }
  59. else{
  60.  
  61. }
  62. }
  63.  
  64.  
  65. }
  66.  
  67. class Pony{
  68. private String name;
  69. private String color;
  70. private String cutie_mark;
  71. public Pony(String name, String color,String cutie_mark){
  72. this.color=color;
  73. this.name=name;
  74. this.cutie_mark = cutie_mark;
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement