Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2013
    Posts
    14
    Rep Power
    0

    Default Why isn't anything coming up anymore?

    Java Code:
    package apcsChapter6;
    
    import java.io.IOException;
    
    public class HeatIndexV1_5 {
    
    	/**
    	 * @param args
    	 * @throws IOException
    	 */
    	public static void main(String[] args) throws IOException {
    		// TODO Auto-generated method stub
    
    		FileCounter fileCountObject = new FileCounter();
    		fileCountObject.humidCounter();
    		fileCountObject.humidNumber();
    		fileCountObject.humidVerifier();
    
    		fileCountObject.tempCounter();
    		fileCountObject.tempNumber();
    		fileCountObject.tempVerfier();
    
    	}
    
    }
    Java Code:
    package apcsChapter6;
    
    import java.io.File;
    //import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.util.Scanner;
    
    public class FileCounter {
    	public int humidCount, tempCount;
    	public String humidToken = "";
    
    	public void humidCounter() throws IOException {
    		// this is to count how many digits should be in our array
    		File humidFile = new File("KeyWestHumid.txt");
    		Scanner inHumidFile = new Scanner(humidFile);
    		while (inHumidFile.hasNextLine()) {
    			// humidToken = inHumidFile.nextLine();
    			humidCount++;
    		}
    		inHumidFile.close();
    		// return humidCount;
    
    	}
    
    	public int humidNumber() {
    		return humidCount;
    	}
    
    	public void humidVerifier() {
    		System.out.println("The amount of numbers in KeyWestHumid.txt is...:"
    				+ humidCount);
    	}
    
    	public void tempCounter() throws IOException {
    		File tempFile = new File("KeyWestTemp.txt");
    		Scanner inTempFile = new Scanner(tempFile);
    		while (inTempFile.hasNextLine()) {
    			tempCount++;
    		}
    		inTempFile.close();
    	}
    
    	public int tempNumber() {
    		return tempCount;
    	}
    
    	public void tempVerfier() {
    		System.out.println("The amount of numbers in KeyWestTemp.txt is...:"
    				+ tempCount);
    	}
    
    }
    The program was working fine until I added another file for it to scan and now I can't even change it back :( someone please tlel me what is wrong....

  2. #2
    NotTooOld is offline Hostage
    Join Date
    Apr 2013
    Location
    China
    Posts
    128
    Rep Power
    0

    Default Re: Why isn't anything coming up anymore?

    Quote Originally Posted by ilovemysillybanana View Post
    Java Code:
    package apcsChapter6;
    
    import java.io.IOException;
    
    public class HeatIndexV1_5 {
    
    	/**
    	 * @param args
    	 * @throws IOException
    	 */
    	public static void main(String[] args) throws IOException {
    		// TODO Auto-generated method stub
    
    		FileCounter fileCountObject = new FileCounter();
    		fileCountObject.humidCounter();
    		fileCountObject.humidNumber();
    		fileCountObject.humidVerifier();
    
    		fileCountObject.tempCounter();
    		fileCountObject.tempNumber();
    		fileCountObject.tempVerfier();
    
    	}
    
    }
    Java Code:
    package apcsChapter6;
    
    import java.io.File;
    //import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.util.Scanner;
    
    public class FileCounter {
    	public int humidCount, tempCount;
    	public String humidToken = "";
    
    	public void humidCounter() throws IOException {
    		// this is to count how many digits should be in our array
    		File humidFile = new File("KeyWestHumid.txt");
    		Scanner inHumidFile = new Scanner(humidFile);
    		while (inHumidFile.hasNextLine()) {
    			// humidToken = inHumidFile.nextLine();
    			humidCount++;
    		}
    		inHumidFile.close();
    		// return humidCount;
    
    	}
    
    	public int humidNumber() {
    		return humidCount;
    	}
    
    	public void humidVerifier() {
    		System.out.println("The amount of numbers in KeyWestHumid.txt is...:"
    				+ humidCount);
    	}
    
    	public void tempCounter() throws IOException {
    		File tempFile = new File("KeyWestTemp.txt");
    		Scanner inTempFile = new Scanner(tempFile);
    		while (inTempFile.hasNextLine()) {
    			tempCount++;
    		}
    		inTempFile.close();
    	}
    
    	public int tempNumber() {
    		return tempCount;
    	}
    
    	public void tempVerfier() {
    		System.out.println("The amount of numbers in KeyWestTemp.txt is...:"
    				+ tempCount);
    	}
    
    }
    The program was working fine until I added another file for it to scan and now I can't even change it back :( someone please tlel me what is wrong....
    I'm new to Java, but it looks to me like your method "humidCounter()" needs to move to the next line in the file. It looks like (as it is written) it will simply look to see if the file "hasNextLine" and then increment the humidCount variable. Looks like the line in the file never gets changed. But like I said, I'm new. You might add "inHumidFile.nextLine()" But I think your humidCount variable will only be counting the number of lines in the file.
    Last edited by NotTooOld; 04-12-2013 at 07:16 AM.

  3. #3
    Join Date
    Apr 2013
    Posts
    14
    Rep Power
    0

    Default Re: Why isn't anything coming up anymore?

    :/ but I mean nothing is coming up, I get no output at all, can you see if my program runs on your machine?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default Re: Why isn't anything coming up anymore?

    Stick some debugging in there so you can see which methods are being run and where the code is getting to.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    NotTooOld is offline Hostage
    Join Date
    Apr 2013
    Location
    China
    Posts
    128
    Rep Power
    0

    Default Re: Why isn't anything coming up anymore?

    Quote Originally Posted by ilovemysillybanana View Post
    :/ but I mean nothing is coming up, I get no output at all, can you see if my program runs on your machine?
    It's not the computer. It's the code.

  6. #6
    NotTooOld is offline Hostage
    Join Date
    Apr 2013
    Location
    China
    Posts
    128
    Rep Power
    0

    Default Re: Why isn't anything coming up anymore?

    Quote Originally Posted by Tolls View Post
    Stick some debugging in there so you can see which methods are being run and where the code is getting to.
    The first method call is to humidCounter. Am I missing something or would that method not simply increment humidCount until it reached the max value of integer?
    Java Code:
       public void humidCounter() throws IOException {         
    // this is to count how many digits should be in our array         
    File humidFile = new File("KeyWestHumid.txt");         
    Scanner inHumidFile = new Scanner(humidFile);         
    while (inHumidFile.hasNextLine()) {             
    // humidToken = inHumidFile.nextLine();      //This line is commented out in the code       
    humidCount++;         
    }         
    inHumidFile.close();         
    // return humidCount;       
    }

  7. #7
    Join Date
    Apr 2013
    Posts
    14
    Rep Power
    0

    Default Re: Why isn't anything coming up anymore?

    What I want it to do is count the amount of numbers in the text file :/ are you saying I wrote code that would crash my program? How do I change that? Because I can't get this to work anymore the first time it worked fine o.o I don't iknow what I'm doing different

  8. #8
    NotTooOld is offline Hostage
    Join Date
    Apr 2013
    Location
    China
    Posts
    128
    Rep Power
    0

    Default Re: Why isn't anything coming up anymore?

    Quote Originally Posted by ilovemysillybanana View Post
    What I want it to do is count the amount of numbers in the text file :/ are you saying I wrote code that would crash my program? How do I change that? Because I can't get this to work anymore the first time it worked fine o.o I don't iknow what I'm doing different
    Let me try this again... This is a "number" ---> 5 . This is also a number ---> 98.6 . OR is that second one 3 numbers? For a computer to find the kind of number you want to find, it has to know very clearly what the number should look like. For a clue you might look at the KeyWestHumid.txt file. It may (or not) have dates in a format like this: 01/28/2012. How many numbers is that?? It is only ONE specific date... but it might be in this format too. 28-01-12. You have to know the format of the "numbers" you want, or cover all the possibilities.
    But back to your code. You should listen to Tolls. He's a Moderator, very good, and much more experienced than I. If I were you, I'd do both what I suggested (put in some code to move to the next integer within the KeyWestHumid file) and what Tolls suggested. (put in some debugging code) That debugging code helps a great deal, and can be as simple as ---> System.out.println("The next line is..."); <-- That can help you find where the code stops. Let us see your Stack Trace as well.

Similar Threads

  1. Replies: 1
    Last Post: 07-10-2012, 10:33 PM
  2. Java doesn't want to install anymore
    By Andross in forum Forum Lobby
    Replies: 0
    Last Post: 09-29-2011, 04:50 PM
  3. Jax is coming to the us!!!
    By blease87 in forum Reviews / Advertising
    Replies: 0
    Last Post: 03-04-2011, 12:21 PM
  4. Cant run my programs anymore
    By Glenn1990 in forum New To Java
    Replies: 2
    Last Post: 02-25-2011, 08:49 PM
  5. repaint class doesnt work anymore... dunno why..
    By Addez in forum New To Java
    Replies: 9
    Last Post: 11-07-2009, 09:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •