Results 1 to 4 of 4
  1. #1
    Bill SS is offline Member
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default Interesting task with regular expressinos

    I learn java for one year but several times ago my friend ask me a next task

    There is a text consisting of words of different lengths.
    Needed in a console application to add a menu with a choice of word length to be replaced by the word entered by the same panel.

    Terms: code convention and two classes(OOP inheritance has to be supported)
    console example:

    "Please enter text"
    jfkdjf klsdkdls dslklsk dkslk
    "Please enter word's length to change "
    6
    "Please enter the words"
    milk
    "result is:"
    milk klsdkdls dslklsk milk

    Java Code:
    import java.util.*;
    public class Test {
    
    	
    	public static void main(String[] args)
    	{
    	
            Scanner in = new Scanner (System.in);
    		
            System.out.println("Please, input text");
    		String text = in.nextLine();	
    
    		System.out.println("Please enter word's length to change");
    		int length  = in.nextInt();
    		Scanner in1 = new Scanner (System.in);
    		
    		System.out.println("Please enter the word");
    		String change = in1.nextLine();
    	}
    	class sentence extends Test
    	public class Sentence {
       private Word head;
       private Word tail;
       private int size;
    
       public Sentence( String sentence ) {
          String[] words =  sentence.split( "\\s+" );
          for ( String  word : words ) {
             add( word );
          }
       }
    
       public void add( String word ){
          //...
       }
    
       public Word first(){
          return head;
       }
    
    
       public Word last(){
          return tail;
       }
       
       //...
    
    }
    
    public class Word [I][SIZE=4]extends[/SIZE][/I] sentense {
       private Word prev;
       private Word next;
       private String item;
       
       public void setNext( Word nextOne ) {
          next = nextOne;
       }
       
       public void setPrev( Word prevOne ) {
          prev = prevOne;
       }
    
       public Word prev(){
          return prev;
       }
       
       public Word next(){
          return next;
       }
       
       public int length(){
          return item.length();
       }
       
       public void replace ( Sentence sentence ) {
          //...
       }
       //...
    
    }
    
    System.out.println ("result is"+" "+: const):
    }
    My question is how really abolish the code and add really useful methods in it? Can you hepl me with realization of it?
    Thank you for your time guys.
    Last edited by Bill SS; 02-15-2012 at 11:14 PM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default Re: Interesting task with regular expressinos

    Also at javaprogrammingforums.com

    @OP: If you have started a discussion in various places, please post links to let everyone know that. Everyone participating in a discussion ought, at least, to know where that discussion is taking place.

    Also bear in mind that many people are a little reluctant to participate in discussion like this for fear of wasting their time answering a question that might have been answered elsewhere.

  3. #3
    Bill SS is offline Member
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default Re: Interesting task with regular expressinos

    I really wonder to know how to resolve this task... I dont discussed anything in javaprogrammingforums.com
    I started to resolve it only there.
    Sorry for double-post task-information especiallu fpr post it in javaprogrammingforums.com

  4. #4
    Bill SS is offline Member
    Join Date
    Feb 2012
    Posts
    4
    Rep Power
    0

    Default Re: Interesting task with regular expressinos

    So guys give give some code-hints for my developments with friend's task/// I really have ability to resolve that task.

Similar Threads

  1. Replies: 3
    Last Post: 10-08-2011, 09:47 AM
  2. interesting programming puzzle
    By karq in forum New To Java
    Replies: 4
    Last Post: 08-09-2010, 04:53 AM
  3. Interesting CS problem. Need help.
    By xtrmi in forum New To Java
    Replies: 1
    Last Post: 05-02-2009, 04:51 AM
  4. Interesting Experiment
    By uncommon in forum Advanced Java
    Replies: 13
    Last Post: 12-21-2008, 12:30 AM
  5. Tricky but very interesting problem
    By ravjot28 in forum New To Java
    Replies: 4
    Last Post: 06-26-2008, 02:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •