Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-06-2010, 06:53 PM   PM User | #1
kitty
New Coder

 
Join Date: Dec 2010
Posts: 13
Thanks: 3
Thanked 0 Times in 0 Posts
kitty is an unknown quantity at this point
file-handling javascript, printing sections of a file

I can get this code to take two separate sections of a file which are not beside each other and write them into another file. It always comes up as a single full line of the code instead of the sections I want. The code includes the student number first name last name and three results of assignments. I want the code to write the student number and three results of all the students into a file and then work out the average of the student results. Can you help?

Code:
 try{                    
               while (in.hasNextLine())
               {
                  String line = in.nextLine();
                  out.println( line);
                  int i=0;
                  if(!Character.isDigit(line.charAt(i)))  { i++; }
                  studentStringNumber = line.substring(0, i);
                  String stringResult = line.substring(i);
                              	
                  studentStringNumber = studentStringNumber.trim();
                  stringResults = stringResults.trim();
                  double stringResultsValue = Double.parseDouble(stringResults.trim());
                  stringResults = in.nextLine();
                              	
                                 
                  studentStringNumber = in.nextLine();
                  studentNumber = Integer.parseInt(studentStringNumber);
                  if(in.hasNextInt())
                  {
                     int value = in.nextInt();
                  }
               						 					   
                  results = Double.parseDouble(stringResults); 
                  if(in.hasNextDouble())
                  {
                     double value = in.nextDouble();
                  } 
               						               	
                            	
                  Scanner lineScanner = new Scanner(line);
                  studentStringNumber = lineScanner.next();
                  while(!lineScanner.hasNextDouble())
                  {
                     studentStringNumber = studentStringNumber+ " " +lineScanner.next();
                  }
                  stringResultsValue = lineScanner.nextDouble();     
               }
            }
kitty is offline   Reply With Quote
Old 12-06-2010, 07:11 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
You seem to be confusing Javascript with some other language (Java???).

String stringResult = line.substring(i);
double stringResultsValue = Double.parseDouble(stringResults.trim());
studentNumber = Integer.parseInt(studentStringNumber);
double value = in.nextDouble();


- none of those (for example) are valid Javascript syntax.

JavaScript is purely a client-side language, and unless used with an Ajax call has no capability to read from or write to a file (except a cookie), communicate with the server or access a database.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
Philip M is offline   Reply With Quote
Old 12-06-2010, 07:14 PM   PM User | #3
kitty
New Coder

 
Join Date: Dec 2010
Posts: 13
Thanks: 3
Thanked 0 Times in 0 Posts
kitty is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
You seem to be confusing Javascript with some other language.

String stringResult = line.substring(i);
double stringResultsValue = Double.parseDouble(stringResults.trim());
studentNumber = Integer.parseInt(studentStringNumber);
double value = in.nextDouble();


- none of those (for example) are valid Javascript syntax.

JavaScript is purely a client-side language, and unless used with an Ajax call has no capability to read from or write to a file (except a cookie), communicate with the server or access a database.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

I'm very sorry but i have got mixed up. This is acctually just Java codes not javascript. I'm all very new to this and i didn't know that there was a difference.

I would be delighted if you could still help me or redirect me to another part of the forum that deals with java...
kitty is offline   Reply With Quote
Old 12-06-2010, 08:46 PM   PM User | #4
kitty
New Coder

 
Join Date: Dec 2010
Posts: 13
Thanks: 3
Thanked 0 Times in 0 Posts
kitty is an unknown quantity at this point
Please delete this as i have moved my question to the appropriate thread.

Thank you.
kitty is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:20 AM.


Advertisement
Log in to turn off these ads.