Solved

What is the correct output for the attached program/ Java programming

Posted on 2008-10-21
10
154 Views
Last Modified: 2013-11-23
Hi experts,
I have attached a zip file containing code that I have renamed as .txt (so please change to .java if you have to work with them). Now what I want to know is what output is expected when the main program lab4d.java is run. Should it be Output_Paragraph_Only.txt as has been attached or Output_Full.txt.

When I ran it I got only Output_Paragraph_only. However I was told that the actual output is as in Out_Full.txt. However this is something I am not getting. So where lies the truth? Can anbody please take a look at the files and answer.
lab4d2.zip
0
Comment
Question by:ohjava
  • 5
  • 5
10 Comments
 
LVL 3

Accepted Solution

by:
glenjr earned 250 total points
ID: 22772265
ohjava,

It appears that your program when it is run waits for the user to type something and when the "enter" key is pressed it returns whatever had been typed as number 1. The user types again and when "enter" is pressed that is returned as number 2.

This is what the program returned for me when i ran it:

Programming Proverbs
1. Programming Proverbs
Dont get suckered in by the comments -- they can be terribly misleading.
2. Dont get suckered in by the comments -- they can be terribly misleading.
what is this doing
3. what is this doing
yes
4. yes
no
5. no
matsdfsdf


(the first line is what i typed and the second is what was returned when i pressed enter). I went on till number 50 was returned.

When you ran the program is that what you did?? The results that i looked at that were in the zip file are much different and dont give me a good idea of the process that you went through when you ran the program.

Let me know if any of this is unclear and what questions you have.

glenjr
0
 

Author Comment

by:ohjava
ID: 22772600
glenjr,
Thank you for your reply. I asked my teacher about this and he confirmed that Output_full.txt (that has been attached to the original question) is the correct output.

I used the following command at the command line and received the following output
===============================================================================
C:\Program Files\Java\jdk1.6.0_04\bin>java lab4d < lab4d3.txt
1. PROGRAMMING PROVERBS
2.
3. Don't get suckered in by the comments -- they can be terribly misleading.
4. Debug only code.
5.
6. It is easier to change the specification to fit the program than vice versa
7.
8. Technological progress has merely provided us with more efficient means
9. for going backwards.
10.
11. The First Rule of Program Optimization: Don't do it. The Second Rule of
12. Program Optimization (for experts only!): Don't do it yet.
13.
14. If the code and the comments disagree then probably both are wrong.

C:\Program Files\Java\jdk1.6.0_04\bin>java lab4d < lab4d3.txt
1. PROGRAMMING PROVERBS
2.
3. Don't get suckered in by the comments -- they can be terribly misleading.
4. Debug only code.
5.
6. It is easier to change the specification to fit the program than vice versa.
7.
8. Technological progress has merely provided us with more efficient means
9. for going backwards.
10.
11. The First Rule of Program Optimization: Don't do it. The Second Rule of
12. Program Optimization (for experts only!): Don't do it yet.
13.
14. If the code and the comments disagree then probably both are wrong.
15.

===================================================================================
It is possible I may have altered the manner in which I ended the file, so that you do not get similar output when you run it.
=================================================================================
MY BIG QUESTION AT THIS TIME IS:
WHY IS IT NOT PRINTING OUT THE UNSORTED INDEX OF WORDS AFTER "15" ABOVE AS IT IS SUPPOSED TO. Here is the output that is supposed to appear:- (the numbers are the line numbers on which the words appear). MY MOST LIEKLY PROBLEM IS AN END OF FILE ISSUE. I WILL CHECK THE CODE ONCE AGAIN HOWEVER TO MAKE SURE I TYPED IT EXACTLY AS THE PROF GAVE IT. IF I HAVE THEN ACCORDING TO HIM, THE PROBLEM LIES WITH THE INPUT FILE "lab4d3.txt"
=============================================================================
C:\Program Files\Java\jdk1.6.0_04\bin>java lab4d < lab4d3.txt
1. PROGRAMMING PROVERBS
2.
3. Don't get suckered in by the comments -- they can be terribly misleading.
4. Debug only code.
5.
6. It is easier to change the specification to fit the program than vice versa.
7.
8. Technological progress has merely provided us with more efficient means
9. for going backwards.
10.
11. The First Rule of Program Optimization: Don't do it. The Second Rule of
12. Program Optimization (for experts only!): Don't do it yet.
13.
14. If the code and the comments disagree then probably both are wrong.
15.
wrong. 14
probably 14
are 14
both 14
then 14
disagree, 14
and 14
code 14
If 14
yet. 12
it 12
only!): 12
experts 12
(for 12
Optimization 12
Second 11
it. 11
do 11 12
of 11 11
Rule 11 11
First 11
The 11 11
backwards. 9
going 9
for 9
means 8
efficient 8
more 8
with 8
us 8
provided 8
merely 8
has 8
progress 8
Technological 8
versa. 6
vice 6
than 6
program 6
fit 6
specification 6
change 6
to 6 6
easier 6
is 6
It 6
code. 4
only 4
Debug 4
misleading. 3
terribly 3
be 3
can 3
they 3
-- 3
comments 3 14
the 3 6 6 14 14
by 3
in 3
suckered 3
get 3
Don't 3 11 12
PROVERBS 1
PROGRAMMING 1
==============================================================================

Thanks in advance for you valuable input.
0
 

Author Comment

by:ohjava
ID: 22772606
glenjr,
Thank you for your reply. I asked my teacher about this and he confirmed that Output_full.txt (that has been attached to the original question) is the correct output.

I used the following command at the command line and received the following output
===============================================================================

C:\Program Files\Java\jdk1.6.0_04\bin>java lab4d < lab4d3.txt
1. PROGRAMMING PROVERBS
2.
3. Don't get suckered in by the comments -- they can be terribly misleading.
4. Debug only code.
5.
6. It is easier to change the specification to fit the program than vice versa.
7.
8. Technological progress has merely provided us with more efficient means
9. for going backwards.
10.
11. The First Rule of Program Optimization: Don't do it. The Second Rule of
12. Program Optimization (for experts only!): Don't do it yet.
13.
14. If the code and the comments disagree then probably both are wrong.
15.

===================================================================================
It is possible I may have altered the manner in which I ended the file, so that you do not get similar output when you run it.
=================================================================================
MY BIG QUESTION AT THIS TIME IS:
WHY IS IT NOT PRINTING OUT THE UNSORTED INDEX OF WORDS AFTER "15" ABOVE AS IT IS SUPPOSED TO. Here is the output that is supposed to appear:- (the numbers are the line numbers on which the words appear). MY MOST LIEKLY PROBLEM IS AN END OF FILE ISSUE. I WILL CHECK THE CODE ONCE AGAIN HOWEVER TO MAKE SURE I TYPED IT EXACTLY AS THE PROF GAVE IT. IF I HAVE THEN ACCORDING TO HIM, THE PROBLEM LIES WITH THE INPUT FILE "lab4d3.txt"
=============================================================================
C:\Program Files\Java\jdk1.6.0_04\bin>java lab4d < lab4d3.txt
1. PROGRAMMING PROVERBS
2.
3. Don't get suckered in by the comments -- they can be terribly misleading.
4. Debug only code.
5.
6. It is easier to change the specification to fit the program than vice versa.
7.
8. Technological progress has merely provided us with more efficient means
9. for going backwards.
10.
11. The First Rule of Program Optimization: Don't do it. The Second Rule of
12. Program Optimization (for experts only!): Don't do it yet.
13.
14. If the code and the comments disagree then probably both are wrong.
15.
wrong. 14
probably 14
are 14
both 14
then 14
disagree, 14
and 14
code 14
If 14
yet. 12
it 12
only!): 12
experts 12
(for 12
Optimization 12
Second 11
it. 11
do 11 12
of 11 11
Rule 11 11
First 11
The 11 11
backwards. 9
going 9
for 9
means 8
efficient 8
more 8
with 8
us 8
provided 8
merely 8
has 8
progress 8
Technological 8
versa. 6
vice 6
than 6
program 6
fit 6
specification 6
change 6
to 6 6
easier 6
is 6
It 6
code. 4
only 4
Debug 4
misleading. 3
terribly 3
be 3
can 3
they 3
-- 3
comments 3 14
the 3 6 6 14 14
by 3
in 3
suckered 3
get 3
Don't 3 11 12
PROVERBS 1
PROGRAMMING 1
==============================================================================

Thanks in advance for you valuable input.
0
 
LVL 3

Expert Comment

by:glenjr
ID: 22772641
ok, thanks for that information. I understand now why i was getting different results. I am going to take another look at it, and get back to you.
0
 
LVL 3

Expert Comment

by:glenjr
ID: 22772739
in your last comment you mentioned that your professor provided the file, which files did he provide to you and which are ones that you have created/edited??
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:ohjava
ID: 22778823
He provided all the code file and the input and output files.MY OBJECTIVE AT THIS TIME IS TO JUST GET THE OUTPUT HE SAID THIS CODE SHOULD THROW ON RUNNING THE MAIN (LAB4D) PROGRAM.

ACTUALLY I LOOKED AT THE CODE AGAIN AND SAW THAT I HAD MADE A TYPO. SO I GET THE EXPECTED OUTPUT NOW.

THE ERROR AT THE MOMENT IS IN THE INDEX4.JAVA FILE.

IF I NEED FURTHER HELP WITH THIS I WILL PUT OUT ANOTHER POST. THE OBJECTIVE OF THIS LAB IS TO GET A SORTED LIST OF WORDS.

THANKS ONCE AGAIN FOR GIVING ATTENTION TO THIS PROBLEM THAT HAS NW BEEN SOLVED (AT LEAST THE PRELIMINARY PART). ANY IDEAS AS TO HOW TO MAKE THE LIST SORTED ALPHABETICALLY ?

0
 
LVL 3

Expert Comment

by:glenjr
ID: 22789206
ohjava,

thanks for the pts and the fun question. i hope you enjoy learning java, its a powerful language. i look forward to anymore questions you may have.

glenjr
0
 

Author Comment

by:ohjava
ID: 22789452
glenjr,
It sure is a very challenging enterprise to learn this language. IT and programming are not as easy as they seem from the outside and I am discovering this as I attempt to transition my career into IT.

It so happens that I do have a new question related to this very problem. Since this question is now closed I will do the following:-
1.POST A NEW QUESTION WITH THE RELEVANT PROBLEM ASKED IN THERE.
2.REATTACH THE RELEVANT FILES INLCLUDING NEW INPUT AND NEW OUTPUT THAT I AM GETTING AND EXPLAINING WHAT IS DESIRED.

If you and other experts can please take a look it may help me in reaching my objective which is to get the desired output.

So please keep a lookout for the new question.

Thanks once again
0
 
LVL 3

Expert Comment

by:glenjr
ID: 22790128
that is true that programming is not as easy as professionals make it seem, but with practice and trial and error it becomes easier. The challenges are still there but they become more manageable. good luck with the transition and i will keep an eye out for the questions.

0
 

Author Comment

by:ohjava
ID: 22791822
The question is out now. I completed one course in Java but that barely scrathed the surface. I am doing a second one now and realizing how much I did not learn in the first one.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now