• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

2 Java programming problems for homework that needs combining

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.




 
Joey McGee
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Joey McGee
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)?
 
Joey McGee
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"?
 
Joey McGee
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Joey McGee
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Joey McGee
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic