Results 1 to 4 of 4
- 02-15-2012, 10:07 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 4
- Rep Power
- 0
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
My question is how really abolish the code and add really useful methods in it? Can you hepl me with realization of it?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): }
Thank you for your time guys.Last edited by Bill SS; 02-15-2012 at 10:14 PM.
- 02-15-2012, 10:38 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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.
- 02-15-2012, 11:13 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 4
- Rep Power
- 0
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
- 02-16-2012, 05:47 AM #4
Member
- Join Date
- Feb 2012
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
I thought this would be an interesting thing to try...
By Azryo in forum New To JavaReplies: 3Last Post: 10-08-2011, 08:47 AM -
interesting programming puzzle
By karq in forum New To JavaReplies: 4Last Post: 08-09-2010, 03:53 AM -
Interesting CS problem. Need help.
By xtrmi in forum New To JavaReplies: 1Last Post: 05-02-2009, 03:51 AM -
Interesting Experiment
By uncommon in forum Advanced JavaReplies: 13Last Post: 12-20-2008, 11:30 PM -
Tricky but very interesting problem
By ravjot28 in forum New To JavaReplies: 4Last Post: 06-26-2008, 01:43 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks