473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Java help needed, brain ready to explode!

6
Im about ready to throw myself out of a window for this piece of work that i need to do. I need an array of English sentences. Which will list all those words from all the sentences that contain one or more character 'm'. Use an input dialog box to read the sentences into the array and an output dialog box to display the required words (7 words per line). The number of sentences will not exceed 5.

Now i *think* ive figured out that i need to use some of the following :

String [] array = new String[5];

Then im guessing i need to store the string in an array

array[0] = theInputSentence;

Then i need to somehow create a loop that checks the sentence for thats that have the letter 'm' in them.


But other then that my mind has come to an absolute standstill and its pretty damn annoying. Especially with the loop bit that will check for the 'm'.
Really startign to get worked up about it too
Nov 6 '06 #1
11 2294
r035198x
13,262 8TB
Im about ready to throw myself out of a window for this piece of work that i need to do. I need an array of English sentences. Which will list all those words from all the sentences that contain one or more character 'm'. Use an input dialog box to read the sentences into the array and an output dialog box to display the required words (7 words per line). The number of sentences will not exceed 5.

Now i *think* ive figured out that i need to use some of the following :

String [] array = new String[5];

Then im guessing i need to store the string in an array

array[0] = theInputSentence;

Then i need to somehow create a loop that checks the sentence for thats that have the letter 'm' in them.


But other then that my mind has come to an absolute standstill and its pretty damn annoying. Especially with the loop bit that will check for the 'm'.
Really startign to get worked up about it too
Write the shell for the program. The class, the main method and import javax.swing. Then try to get the sentences into the array. Your guesses are correct. After writing the shell, post and we can see where the loops go.
Nov 7 '06 #2
derbys
6
Write the shell for the program. The class, the main method and import javax.swing. Then try to get the sentences into the array. Your guesses are correct. After writing the shell, post and we can see where the loops go.
Hey, ive managed to complete this one, but thanks for your time anyway. I was wondering if you could help me with a piece of code that i wrote a while ago.

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.JOptionPane;
  2. import java.util.Arrays;
  3.  
  4. class NameHolder {
  5.   String[] names = new String[10];
  6.  
  7.   public NameHolder() {
  8.     int i;
  9.     String op = "";
  10.  
  11.     // Get names
  12.     for(i = 0; i < names.length; ++i)
  13.       names[i] = (String)JOptionPane.showInputDialog(null, "Please enter a name:");
  14.  
  15.     // Sort names
  16.     Arrays.sort(names);
  17.  
  18.     // Join names
  19.     for(i = 0; i < names.length; ++i)
  20.       op += names[i] + "\n";
  21.  
  22.     // Output names
  23.     JOptionPane.showMessageDialog(null, op);
  24.   }
  25.  
  26.   public static void main(String[] args) {
  27.     // Instantiate.
  28.     new NameHolder();
  29.   }
  30. }
What that does (you can probably tell) is that it allows a user to enter 10 names, which then get put in to alphabetical order and then displayed. What im wondering is it possible to only display names alphabetically after a certain name i.e "Jack". For example if i enter the names "Ben, Ted, James, Zack" it would only display the names "Ted, James and Zack" as there after Jack in the alphabet - if that makes any sense at all? :D
Nov 7 '06 #3
r035198x
13,262 8TB
Hey, ive managed to complete this one, but thanks for your time anyway. I was wondering if you could help me with a piece of code that i wrote a while ago.

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.JOptionPane;
  2. import java.util.Arrays;
  3.  
  4. class NameHolder {
  5. String[] names = new String[10];
  6.  
  7. public NameHolder() {
  8. int i;
  9. String op = "";
  10.  
  11. // Get names
  12. for(i = 0; i < names.length; ++i)
  13. names[i] = (String)JOptionPane.showInputDialog(null, "Please enter a name:");
  14.  
  15. // Sort names
  16. Arrays.sort(names);
  17.  
  18. // Join names
  19. for(i = 0; i < names.length; ++i)
  20. op += names[i] + "\n";
  21.  
  22. // Output names
  23. JOptionPane.showMessageDialog(null, op);
  24. }
  25.  
  26. public static void main(String[] args) {
  27. // Instantiate.
  28. new NameHolder();
  29. }
  30. }
What that does (you can probably tell) is that it allows a user to enter 10 names, which then get put in to alphabetical order and then displayed. What im wondering is it possible to only display names alphabetically after a certain name i.e "Jack". For example if i enter the names "Ben, Ted, James, Zack" it would only display the names "Ted, James and Zack" as there after Jack in the alphabet - if that makes any sense at all? :D

Expand|Select|Wrap|Line Numbers
  1.  import javax.swing.JOptionPane; 
  2. import java.util.Arrays;
  3.  
  4. class NameHolder {
  5.  String[] names = new String[10];
  6.  public NameHolder() {
  7.   String op = "";
  8.   // Get names
  9.   for(int i = 0; i < names.length; ++i) {
  10.    names[i] = (String)JOptionPane.showInputDialog(null, "Please enter a name:");
  11.   }
  12.   // Sort names
  13.   Arrays.sort(names);
  14.   int pos = -1;
  15.   String start = (String)JOptionPane.showInputDialog(null, "Please enter a name to start from:");
  16.   for(int i = 0; i < names.length; ++i) {
  17.    if(names[i].equals(start)) {
  18.     pos = i;
  19.     break;
  20.    }
  21.   }
  22.   // Join names
  23.   if(pos == -1) {
  24.    JOptionPane.showMessageDialog(null, "Name not found");
  25.   }
  26.   else {
  27.    for(int i = pos; i < names.length; ++i) {
  28.     op += names[i] + "\n";
  29.    }
  30.    JOptionPane.showMessageDialog(null, op);
  31.   }
  32.  }
  33.  public static void main(String[] args) {
  34.  // Instantiate.
  35.   new NameHolder();
  36.  }
  37. }
  38.  
  39.  
Like this?
Nov 7 '06 #4
derbys
6
Erm not really like that no. The names that are entered in to the input box would be then compared with the name "jack", then the names alphabetically after the name "jack" should be displayed.

So for example if these Names were entered:

Ben Toby Allen Zack Sally Richard

The following would be displayed at the end:

Richard Sally Toby Zack (in alphabetical order)

Im probably not explaining it in the most simplest of ways here.
Nov 7 '06 #5
derbys
6
Although what you did was quite similar to what i want now that ive looked at it properly. But is it possible that the name "jack" could be in the code instead of having to enter it in an input box after entering all of the other names? If so would that be using string.compareto?

Java beats me so much :D
Nov 7 '06 #6
sicarie
4,677 Expert Mod 4TB
You could just set names[0] = "Jack"; and bump up the for loop initializer (starts at i = 0, start it at i = 1 so it doesn't overwrite names[0]).
Nov 7 '06 #7
r035198x
13,262 8TB
Sorry for the break. Network problems.
Expand|Select|Wrap|Line Numbers
  1.  
  2. int pos = -1;
  3.   //String start = (String)JOptionPane.showInputDialog(null, "Please enter a name to start from:");
  4.   for(int i = 0; i < names.length; ++i) {
  5.    if(names[i].equals("Jack")) {
  6.     pos = i;
  7.     break;
  8.    }
  9.   } 
  10.  
The more times java beats you, the better your chances of beating it next time.
Nov 7 '06 #8
sicarie
4,677 Expert Mod 4TB
Expand|Select|Wrap|Line Numbers
  1.  
  2. int pos = -1;
  3.   //String start = (String)JOptionPane.showInputDialog(null, "Please enter a name to start from:");
  4.   for(int i = 0; i < names.length; ++i) {
  5.    if(names[i].equals("Jack")) {
  6.     pos = i;
  7.     break;
  8.    }
  9.   } 
  10.  
Ah r035198x is right, sorry, I didn't realize what you were asking - serves me right for only scanning it.
Nov 7 '06 #9
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1.  
  2. int pos = -1;
  3. //String start = (String)JOptionPane.showInputDialog(null, "Please enter a name to start from:");
  4. for(int i = 0; i < names.length; ++i) {
  5. if(names[i].equals("Jack")) {
  6.     pos = i;
  7.     break;
  8. }
  9.  
Ah r035198x is right, sorry, I didn't realize what you were asking - serves me right for only scanning it.
In design of course your solution also works. Only that he/she would have to increase the size of the array by one and test with
Expand|Select|Wrap|Line Numbers
  1.  if(names[i].equals(name[0])) {
Nov 7 '06 #10
gabs
3
...could you please give me some of your javax swing knowledge that input words ranges 2 to 20 and arrange it into alphabetical order...if the words is less than 2 and greater than 20...it indicate out of range...


i hope you can help me...this is a very big help...



tnx!
Im a java explorer & beginner...

God Bless...
Feb 20 '08 #11
gabs
3
using java swing with dialog box.tnx!
Feb 20 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Phil Powell | last post by:
I am forced to have to compare the value of some PHP timestamp with a Java-based java.util.Date.getTime() timestamp. Let me show you how they look: The Java time is returned to the PHP...
0
by: abcd | last post by:
kutthaense Secretary Djetvedehald H. Rumsfeld legai predicted eventual vicmadhlary in Iraq mariyu Afghmadhlaistmadhla, kaani jetvedehly after "a ljetvedehg, hard slog," mariyu vede legai pressed...
37
by: asj | last post by:
awhile back, eBay decided to switch from a Microsoft/.NET/Windows architecture on the backend to a J2EE one, which might explain why their java backend will handle up to 1 BILLION page views a day!...
8
by: Beatrice Rutger | last post by:
Hi, I am a previous Micro$oft desertee (moved from VB/VC++ to Java before this whole DOTNET thing) because I had several issues with Micro$oft. I am not completely in love with Windoze, but I...
25
by: redefined.horizons | last post by:
I've traditionally been a Java developer, although I play around with LISP. I recently migrated to Linux and I was exploring Mono as an option for development on Linux. However, I've had some...
51
by: erikcw | last post by:
DiveIntoPython.org was the first book I read on python, and I really got a lot out of it. I need to start learning Java (to maintain a project I've inherited), and was wondering if anyone knew of...
66
by: flarosa | last post by:
Hi, I'm wondering if I can get a reasonably civil (without starting any huge wars) opinion on how server-side PHP compares to server-side Java. I've been strictly a Java developer for almost...
3
by: fruityfreak | last post by:
Hi... I would like to know if the bold part is using java languages or is it some other languages??? <?php session_start(); require('db.php'); mysql_connect(MACHINE, USER, '');...
2
by: lowradiation7 | last post by:
ok my brain is about to explode i do not get this at all can someone please help me out. Write a switch statement you may combine the less than and greater than into one statement. X is less...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.