Menu

Java program  to accept user-defined number of words in a string array. With a menu to implement Show, Move (cut paste), Delete, and Insert actions based on user options – as following sample output …

Question

Answered step-by-step

Java program to accept user-defined number of words in a string…

Java program  to accept user-defined number of words in a string array. With a menu to implement Show, Move (cut paste), Delete, and Insert actions based on user options – as following sample output demonstrates. (Optionally, you may also add Repeat (copy paste) action to the menu.) 

 

Sample output: 

How many words to enter: 6 

Enter the word 1 : aaa 

Enter the word 2 : bbb 

Enter the word 3 : ccc 

Enter the word 4 : ddd 

Enter the word 5 : eee 

Enter the word 6 : fff 

Enter your option: 1- Show 2- Move 3-Delete 4- Insert 5- Repeat 6- Exit: 1 

Current status: 

aaa,bbb,ccc,ddd,eee,fff, 

Enter your option: 1- Show 2- Move 3-Delete 4- Insert 5- Repeat 6- Exit: 2 

Current status: 

aaa,bbb,ccc,ddd,eee,fff, 

From which position? 2 

To which position? 6 

After modification: 

aaa,ccc,ddd,eee,fff,bbb, 

Enter your option: 1- Show 2- Move 3-Delete 4- Insert 5- Repeat 6- Exit: 2 

Current status: 

aaa,ccc,ddd,eee,fff,bbb, 

From which position? 6 

To which position? 1 

After modification: 

bbb,aaa,ccc,ddd,eee,fff, 

Enter your option: 1- Show 2- Move 3-Delete 4- Insert 5- Repeat 6- Exit: 4 

Current status: 

bbb,aaa,ccc,ddd,eee,fff, 

Eenter a word: ggg 

To which position? 4 

After modification: 

bbb,aaa,ccc,ggg,ddd,eee,fff, 

Enter your option: 1- Show 2- Move 3-Delete 4- Insert 5- Repeat 6- Exit: 5 

Current status: 

bbb,aaa,ccc,ggg,ddd,eee,fff, 

From which position? 2 

To which position? 6 

After modification: 

bbb,aaa,ccc,ggg,ddd,aaa,eee,fff, 

Enter your option: 1- Show 2- Move 3-Delete 4- Insert 5- Repeat 6- Exit: 3 

Current status: 

bbb,aaa,ccc,ggg,ddd,aaa,eee,fff, 

Which position? 2 

After deletion: 

bbb,ccc,ggg,ddd,aaa,eee,fff, 

Enter your option: 1- Show 2- Move 3-Delete 4- Insert 5- Repeat 6- Exit: 8 

Wrong option. Try again. 

Enter your option: 1- Show 2- Move 3-Delete 4- Insert 5- Repeat 6- Exit: 6 

Bye Bye! 

OR


Leave a Reply

Your email address will not be published. Required fields are marked *