Apart from the information you have been given written code already.Lexi Turgeon wrote:My assignment has given me some information..
So what specifically you do not understand? A bit strange, because at least what you could do, is to search on google "How to read file in Java", and by comparing search results with the given instructions to you - you should be able to assemble the app. Almost just assemble.Lexi Turgeon wrote:..but I do not understand it at all.
As I said, you have been given almost all code, so, without giving away exact output, it is hard to give some hints.Lexi Turgeon wrote:I understand what I have to do, but with these guidelines I do not understand how to do it.
Lexi Turgeon wrote:I do not understand where I am supposed to start my code.
Earlier I wrote:Do you know how to create a class? Create one and show us. Only the class.
Lexi Turgeon wrote:Do I have all the code I need here or do I have to come up with other code on my own?
Lexi Turgeon wrote:
Liutauras Vilda wrote:
Lexi Turgeon wrote:
So, you have created a class, great. Not sure why you have added that import statement there yet, don't go too far, one step at a time, and don't forget to compile after each step. I hope you tried it and it compiles?
1. Now in order to run the program, class needs to have a 'main' method, right? Please add main method declaration. Look for the hint in the given instructions.
2. After you add 'main' method, can you try to add all other methods suggested in your instructions?
After that repost your code to see if you can handle it.
Lexi Turgeon wrote:
I believe I have added all other methods that were in my instructions.
Lexi Turgeon wrote:and if you have a separate method that actually does the file processing, it should also have the throws clause:
public static void processFile (String filename) throws IOException, FileNotFoundException {
Henry Wong wrote:
Your next paragraph in the your instructions are ...
Lexi Turgeon wrote:and if you have a separate method that actually does the file processing, it should also have the throws clause:
public static void processFile (String filename) throws IOException, FileNotFoundException {
Can you take a shot at that?
Henry
Lexi Turgeon wrote:I have been given the task of reading some numbers from a files I created. The file I created only has numbers in it and is saved in the folder of the NetBeans project. My assignment has given me some information, but I do not understand it at all.
...
I understand what I have to do, but with these guidelines I do not understand how to do it.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Liutauras Vilda wrote:@Lexi
Yeah, it seems fine so far. So, read through the next part of instructions and think what needs to be done.
Hint: the rest specified code (in instructions) needs to be used in one particular method you have created already.
So, try to assemble the last specified code. How that will be looking like?
Note: in order not to have compilation errors, you'll need to add some little bits from your side - declare variables.
Lexi Turgeon wrote:The file i am trying to read from is a file called "grades.txt", would I have to put that in quotes in the code?
and if you have a separate method that actually does the file processing, it should also have the throws clause:
public static void processFile (String filename) throws IOException, FileNotFoundException {
Greate Lexi, you're doing some progress already. However, Carey already pointed out one thing. A bit more in details that would mean, that you're going to call method 'processFile' and you're going to supply a full path to file as an argument. Without giving away all details, that will look similar to:Lexi Turgeon wrote:This was as far as I got. Does this seem correct so far?
Carey Brown wrote:
Always refer back to your requirements.
Liutauras Vilda wrote:Can you try to incorporate the idea to your current code?
However, you didn't compile your code often enough, because you have line 12 which shouldn't compile. The sooner you could notice all compile errors, the easier are to fix them. Some people say you should compile your code after every newly written 5 - 10 lines. Try to follow this approach, that needs to be as a habit probably.
instructions wrote:set up ... as follows...
instructions wrote:
Liutauras Vilda wrote:
instructions wrote:set up ... as follows...
instructions wrote:
That could be important if your teacher is going to check if you can follow the instructions as they appear. I'm having in mind parameter name, which in this case is 'filename' rather than 'pathToFile' (as I suggested for a demo purpose).
Another 2 points.
First. You still don't have a habit to compile code, this has been mentioned multiple times already. Line 12 wouldn't compile. Why you ignoring it?
Second. Very important. Winston basically raised very good point. Do you actually understand what this program is meant to do? Could you please describe in English?
All your work looks very mechanical. Because you don't have any other questions, it seems these don't pop up at all to you. That worries me a bit.
Do you have anything else to do according to your instructions?
[edit] fixed 2 typos
Lexi Turgeon wrote:
I am so lost with this assignment.
Lexi Turgeon wrote:Create a method called processFile as declared above and call it from main passing the name of the file that you created ("scores.txt"). In processFile, set up the BufferedReader and loop through the file, reading each score. Convert the score to an integer, add them up, and calculate and display the mean.
A bit unfortunate and sad.I am so lost with this assignment.
Today's instructions wrote:Convert the score to an integer, add them up, and calculate and display the mean.
Previously provided instructions wrote:This example demonstrates how to parse a double
It should only take a minute to convert the double you are using at present to an integer.Carey Brown wrote:. . . Are you converting each score too an integer? (This is simply a matter of following your instructions. . . .) . . .
Liutauras Vilda wrote:
1. By the way, is it secondary school assignment? College? University?
2. How long programming classes lasted until you got this assignment?
3. Did you attend all of them?
Lexi Turgeon wrote:
Liutauras Vilda wrote:Can you try to incorporate the idea to your current code?
However, you didn't compile your code often enough, because you have line 12 which shouldn't compile. The sooner you could notice all compile errors, the easier are to fix them. Some people say you should compile your code after every newly written 5 - 10 lines. Try to follow this approach, that needs to be as a habit probably.
Lexi Turgeon wrote:Everything compiles except for line 6, 11, 16, and 17.
All things are lawful, but not all things are profitable.
We were speaking about it already. Same as about other places where errors occur, I have in mind declaring variable before you use it, you have that issue present on line 16. Problem is that probably you don't understand (yet) what variable declaration is and don't know how to recognize it, because you had the same problem with variable 'Value', after we showed you, you declared, but then again made exactly same mistake on the next line.Lexi Turgeon wrote:The name of the file is Scores.txt so I am not sure why it is not working. Any idea why?
Carey Brown wrote:You can't use grades.txt. If you want a String literal it would have to be "grades.txt" (in quotes). If you want a variable you might choose something like fileName.
Practice it seems doesn't help you much at the moment, probably you need some theory before.Lexi Turgeon wrote:I do not attend them as they are online, the teacher and students offer little to no help at all.
Lexi Turgeon wrote:
My problem I think comes from my code not recognizing my file I am trying to read from.
Because Java® is a strongly‑typed language. Every variable must be declared with a type before use. If you write Scores.txt without quote marks, that is a class called Scores with a static field called txt. Nowhere do you have a Scores class, so the compiler thinks you should have a variable called Scores with a member called txt.Lexi Turgeon wrote:. . . I do not get why I have to declare it as a variable . . .