Atem85

jj

Sep 28th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.36 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(new String("Просто"));
  6.         t.add(new String("три"));
  7.         t.add(new String("слова"));
  8.         String ourWord = t.find("три");
  9.         t.print();
  10.         System.out.println();
  11.         System.out.println(ourWord);
  12.        t.setConditional(new Condition() {
  13.             @Override
  14.             public boolean check(String word) {
  15.                 return word.equals("слова");
  16.             }
  17.         });
  18.         System.out.println();
  19.         System.out.println(t.getSize());
  20.         t.remove("три");
  21.         System.out.println();
  22.         t.print();
  23.         System.out.println();
  24.         System.out.println(t.getSize());
  25.     }
  26. }
  27. public class MyText {
  28.  
  29.     private String[] myTexts;
  30.     private String word;
  31.     private int size = 0;
  32.  
  33.     public MyText(String word) {
  34.         this.word = word;
  35.     }
  36.  
  37.     public MyText(int size) {
  38.         this.size = size;
  39.         this.size = 0;
  40.         this.myTexts = new String[size];
  41.     }
  42.  
  43.     public void add(String text) {
  44.         myTexts[size] = text;
  45.         size++;
  46.     }
  47.  
  48.     public String find(String word) {
  49.         for (int i = 0; i < myTexts.length; i++) {
  50.             if (myTexts[i].equals(word)) {
  51.                 return myTexts[i];
  52.             }
  53.         }
  54.         return null;
  55.     }
  56.  
  57.     public void print() {
  58.         for (int i = 0; i < myTexts.length; i++) {
  59.             System.out.print(myTexts[i] + " ");
  60.         }
  61.     }
  62.  
  63.     public void remove(String word) {
  64.         for (int i = 0; i < myTexts.length; i++) {
  65.             if (myTexts[i].equals(word)) {
  66.                 String[] newTexts = new String[size - 1];
  67.                 System.arraycopy(myTexts, 0, newTexts, 0, i);
  68.                 System.arraycopy(myTexts, i + 1, newTexts, i, size - (i + 1));
  69.                 myTexts = newTexts;
  70.             }
  71.         }
  72.     }
  73.  
  74.     public void setConditional(Condition c) {
  75.  
  76.  
  77.     }
  78.  
  79.     public void check(String word) {
  80.         if (word.equals("слова")) {
  81.  
  82.         }
  83.  
  84.     }
  85.  
  86.     public String getWord() {
  87.         return word;
  88.     }
  89.  
  90.     public void setWord(String word) {
  91.         this.word = word;
  92.     }
  93.  
  94.     public int getSize() {
  95.         return size;
  96.     }
  97.  
  98.     public void setSize(int size) {
  99.         this.size = size;
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment