aspose file tools*
The moose likes Java in General and the fly likes 2 Java programming problems for homework that needs combining Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "2 Java programming problems for homework that needs combining" Watch "2 Java programming problems for homework that needs combining" New topic
Author

2 Java programming problems for homework that needs combining

Joey McGee
Greenhorn

Joined: Nov 22, 2012
Posts: 27
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

Joined: Nov 22, 2012
Posts: 27
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!!!
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

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.


The quieter you are, the more you are able to hear.
Joey McGee
Greenhorn

Joined: Nov 22, 2012
Posts: 27
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

Joined: Jun 19, 2010
Posts: 825
    
    5

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

Joined: Nov 22, 2012
Posts: 27
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

Joined: Jun 19, 2010
Posts: 825
    
    5

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

Joined: Nov 22, 2012
Posts: 27
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

Joined: Nov 22, 2012
Posts: 27
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

Joined: Jun 19, 2010
Posts: 825
    
    5

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.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11497
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joey McGee
Greenhorn

Joined: Nov 22, 2012
Posts: 27
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

Joined: Jun 19, 2010
Posts: 825
    
    5

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
Bartender

Joined: Oct 02, 2003
Posts: 11497
    
  16

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.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: 2 Java programming problems for homework that needs combining