May 29th, 2012, 12:56 PM
Help with console program with 3 classes...
I've been stuck on this homework assignment for a Java class I am taking and I don't even know where to begin. I want to learn it, not to have someone figure it out for me. I guess really, I just need the assignment dumbed down to where I can understand. I am newer to java and "supposedly" this is a intro level java class.
The assignment is :
Programming Assignment 3
Write a program that consists of three classes. The first class will be the actual program.
The second class will simply convert a string to lower case.
The third class will have three methods:
public static String trimmed(String str)
public static String trimmed(String str, int len)
public static String squeeze(String str)
The 1st trimmed method will return str without leading or trailing whitespace and will return an empty string if str is null.
The 2nd trimmed method will return the first len characters after trimming the string. The 2nd method must make use of the 1st method.
The squeeze method will replace all sequences of 2 spaces with 1 space.
The program will read a file containing the data below (cut and paste it into notepad and save it), and will display each line:
as entered but trimmed and squeezed.
as entered but trimmed, squeezed, and shortened to 10 characters
as entered but trimmed, squeezed, converted to lower case, and shortened to 20 characters.
Data (copy after this line down to (not including) the line that says end data, you will have 5 lines):
This is a test, this is only a test!
This test is a test of your Java programming skills!
You can do this program however you like (console, GUI, AWT, Swing, Applet, etc.).
If you use an inner classes for the second and third classes, you will receive up to 5 extra points, and if the third class is anonymous, you will receive up to five additional points.
If you make the program graphical, you will receive up to 10 extra points (total won't exceed 100).
You will lose points for poor formatting, poor commenting, not following instructions, program that don't work, etc.
In any case, your total cannot exceed 100 points.
Since this is the 3rd assignment, you are expected to get this right before you turn it in. It will be graded much more rigorously than the earlier assignments and in most cases, you won't get a second chance! If something is confusing in the instructions, ask before submitting!
Now, I don't care for it to be fancy, so I'm working console.
I drew out what I need on paper. I asked the professor for help, and I was even more confused.
Basically the three methods i use to manip. a string should be passed a string and return the modified string.
The printing should be don in the main loop.
The loop should :
Read a line of data, process the input string as described, and then output the modified string (either after each required modification) or, if I save the 3 modified strings, output them at the end. So basically, i get what that is saying, I'd prefer to write them all at the end which would save them in memory correct?
The loop should continue to read & process lines of data until there is no more data to read (end of file).
Now, i understand how to do the inner classes, and im not really sure how an anonymous inner class would work here for the 3rd class because other than having no name, its used only once in a program and is defined right at the spot where it is used? I dont see how this would fit in ?
Any assistance is greatly appreciated...
I am also willing to have someone help me via GTalk, if they want to PM me. I would love to have a "tutor" of sorts on this Java class. My class is online and it's just a huge pain for me to understand at times.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!