Atem85

jj

Sep 28th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.91 KB | None | 0 0
  1. public class Demo {
  2.     public static void main(String[] args) {
  3.  
  4.         MyText t = new MyText(5);
  5.         t.add("Просто");
  6.         t.add("три");
  7.         t.add("слова");
  8.  
  9.  
  10.         for (int i = 0; i < t.size(); i++) {
  11.             System.out.print(t.get(i) + " ");
  12.         }
  13.         System.out.println();
  14.         String ourWord = t.find("три,");
  15.         System.out.println(ourWord);
  16.         t.setConditional(new Condition() {
  17.             @Override
  18.             public boolean check(String word) {
  19.                 return word.equals("слова");
  20.             }
  21.         });
  22.         System.out.println();
  23.         System.out.println(t.getSize());
  24.         t.remove("три");
  25.         //t.print();
  26.         t.add("Еще одна строка");
  27.         System.out.println();
  28.         System.out.println(t.getSize());
  29.     }
  30. }
  31. public class MyText {
  32.  
  33.     private String[] myTexts;
  34.     private String word;
  35.     private int size = 0;
  36.     private int capacity = 0;
  37.  
  38.     public MyText(String word) {
  39.         this.word = word;
  40.     }
  41.  
  42.     public MyText(int capacity) {
  43.         this.capacity = capacity;
  44.         this.myTexts = new String[this.capacity];
  45.     }
  46.  
  47.     public int size() {
  48.         return size;
  49.     }
  50.  
  51.     public MyText add(String text) {
  52.         myTexts[size] = text;
  53.         size++;
  54.         return this;
  55.     }
  56.  
  57.     public String get(int index) {
  58.         return myTexts[index];
  59.     }
  60.     public void print() {
  61.         for (int i = 0; i < myTexts.length; i++) {
  62.             System.out.print(myTexts[i] + " ");
  63.         }
  64.     }
  65.  
  66.     public String find(String word) {
  67.         for (int i = 0; i < size; i++) {
  68.             if (myTexts[i].equals(word)) {
  69.                 return myTexts[i];
  70.             }
  71.         }
  72.         return null;
  73.     }
  74.  
  75.  
  76.     public void remove(String word) {
  77.         for (int i = 0; i < myTexts.length; i++) {
  78.             if (myTexts[i].equals(word)) {
  79.                 String[] newTexts = new String[size-1];
  80.                 System.arraycopy(myTexts, 0, newTexts, 0, i);
  81.                 System.arraycopy(myTexts, i + 1, newTexts, i, size - (i + 1));
  82.                 myTexts = newTexts;
  83.             }
  84.         }
  85.     }
  86.  
  87.     public void setConditional(Condition c) {
  88.  
  89.  
  90.     }
  91.  
  92.     public void check(String word) {
  93.         if (word.equals("слова")) {
  94.  
  95.         }
  96.  
  97.     }
  98.  
  99.     public String getWord() {
  100.         return word;
  101.     }
  102.  
  103.     public void setWord(String word) {
  104.         this.word = word;
  105.     }
  106.  
  107.     public int getSize() {
  108.         return size;
  109.     }
  110.  
  111.     public void setSize(int size) {
  112.         this.size = size;
  113.     }
  114.  
  115.     public String[] getMyTexts() {
  116.         return myTexts;
  117.     }
  118.  
  119.     public void setMyTexts(String[] myTexts) {
  120.         this.myTexts = myTexts;
  121.     }
  122.  
  123.     public int getCapacity() {
  124.         return capacity;
  125.     }
  126.  
  127.     public void setCapacity(int capacity) {
  128.         this.capacity = capacity;
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment