Forums Register Login

2 Java programming problems for homework that needs combining

+Pie Number of slices to send: Send
For homework in my Java class we were asked to complete 2 different programming problems and then combine them together. I got both completed individually and they compile and run but now I'm lost on how to combined them. Below is the first programming problem and it's code

1. Develop a simple tool for calculating basic statistics for a segment of text. The application should have a single window with scrolling text box (a JTextArea)) and a stats box. The stats box should be a panel with a titled border, containing labeled fields that display the number of words in the text box and the average word length, as well as any other statistics that you would like to add. The stats box should also contain a button that, when pressed, recomputes the statistics for the current contents of the text field.




+Pie Number of slices to send: Send
Here is the 2nd programming problem.

Design and implement an application that reads a string from the user, then determines and prints how many of each lowercase vowel (a,e,i,o,u) appear in the entire string. Have a seperate counter for each vowel. Also count and print the number of nonvowel characters.



The assignment is due to tonight and so any help combining them is greatly appreciated!!!
+Pie Number of slices to send: Send
I'm not sure what you mean by "combining" here.

The only thing that comes to my mind is that you can define a separate class, say TextStatistics that would contain methods used in both applications (one method to calculate the number of words for the given String, another to calculate the average length and another for vowels). These would all be separate methods but would reside in the same class. The class constructor would have a String argument that would be text you are analyzing. Hence you can use this class to get all the information you need in both applications.

But still you would have two classes, each with main method - one for the GUI client and another for when your client enters text from the command line.
+Pie Number of slices to send: Send
 

Kemal Sokolovic wrote:I'm not sure what you mean by "combining" here.

The only thing that comes to my mind is that you can define a separate class, say TextStatistics that would contain methods used in both applications (one method to calculate the number of words for the given String, another to calculate the average length and another for vowels). These would all be separate methods but would reside in the same class. The class constructor would have a String argument that would be text you are analyzing. Hence you can use this class to get all the information you need in both applications.

But still you would have two classes, each with main method - one for the GUI client and another for when your client enters text from the command line.



I don't understand... The teacher told us to combine both programming problems into 1, though I know we would need 2 classes, 1 for GUI and another for when your client enters text from the command line. I'm very confused and your answer just confused me more as I need to know what code to combine together and where to put them so the program compiles and runs correctly.
+Pie Number of slices to send: Send
Ok, let's try step by step now.

Is the assignment requirement to capture text from the user from both JTextArea (the first application) and command line (the second one)?
+Pie Number of slices to send: Send
 

Kemal Sokolovic wrote:Ok, let's try step by step now.

Is the assignment requirement to capture text from the user from both JTextArea (the first application) and command line (the second one)?



The teacher didn't say, though I think what she wants is both the CountVowels and the Statistics to use the JTextArea.
+Pie Number of slices to send: Send
That would be very bad design as it's not recommended to mix these two. Is there any way you can provide some more details about the assignment requirements besides that "combine these two applications"?
+Pie Number of slices to send: Send
 

Kemal Sokolovic wrote:That would be very bad design as it's not recommended to mix these two. Is there any way you can provide some more details about the assignment requirements besides that "combine these two applications"?



She just said to combine the 2 into 1 program (she not good at explaining things). So I guess whatever we get to work is fine as long as both are in 1 program.
+Pie Number of slices to send: Send
 

Jackson Lawton wrote:

Kemal Sokolovic wrote:That would be very bad design as it's not recommended to mix these two. Is there any way you can provide some more details about the assignment requirements besides that "combine these two applications"?



She just said to combine the 2 into 1 program (she not good at explaining things). So I guess whatever we get to work is fine as long as both are in 1 program.



If you can figure a way to combine these 2 programs into 1 let me know... I have to step out for a bit but will be back around 3:00pm (EST), if not before and will look for your responce.
+Pie Number of slices to send: Send
Well, you would need to tell me what's your choice (GUI or command line) so I can explain it to you in more details and avoid confusion that I made in the first post.
+Pie Number of slices to send: Send
 

Jackson Lawton wrote:If you can figure a way to combine these 2 programs into 1 let me know


so, you are asking us to figure out your homework for you? We don't really do that here. We are happy to help you, but you have to do the heavy lifting.

Can you go back to your teacher and ask her to clarify what exactly she means? Part of becoming a good programmer is knowing when you don't have enough info to do what someone is asking you to do. You have to keep going back, and ask them to clarify things until you both feel like you agree on what needs to be done.
+Pie Number of slices to send: Send
 

fred rosenberger wrote:

Jackson Lawton wrote:If you can figure a way to combine these 2 programs into 1 let me know


so, you are asking us to figure out your homework for you? We don't really do that here. We are happy to help you, but you have to do the heavy lifting.

Can you go back to your teacher and ask her to clarify what exactly she means? Part of becoming a good programmer is knowing when you don't have enough info to do what someone is asking you to do. You have to keep going back, and ask them to clarify things until you both feel like you agree on what needs to be done.



I'm not asking you to do the problem for us and I just spoke to my teacher and she said we need to combine both problems into 1 program. I tried to get more out of her but that's all she would say.
+Pie Number of slices to send: Send
Then you would have to be more specific and TellTheDetails. If you are not sure about that, then there is no way someone else can help you.
+Pie Number of slices to send: Send
My point is that if YOU don't know what needs to be done, there is no way WE can know what needs to be done, since we only know what you tell us.
+Pie Number of slices to send: Send
My suspicion is that your teacher expected you to write the CountVowels class in such a way that it would have methods which could be called from other classes to do such things as counting the vowels in a given string.

If you had done that, then it wouldn't be too hard to modify the GUI program to call those methods and put the returned values into a JTextArea, or whatever it does now. But you didn't do that, and so it would be quite difficult to use the CountVowels class as it stands now from a GUI program.

Now remember I don't know what's gone on in your course so far, so I'm just speculating. If my suspicion is right, then I would say it was quite unkind of your teacher to accept your version of CountVowels as it is, with no comments. I would say that the original requirements for CountVowels should at least have mentioned the use of reusable methods rather than a single main() method. But again I might be completely wrong in my guess.
This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3302 times.
Similar Threads
JTextArea & Cursor
Label in a field or scrollpanel
JTextArea
nothing shows. what did i forget?
need help with JPanel, liseners, and referencing vectors
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 22:34:40.