2 Replies - 271 Views - Last Post: 29 November 2012 - 08:03 PM Rate Topic: -----

#1 GuyWithDragonTattoo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-November 12

Array keeps coming out as false

Posted 29 November 2012 - 07:55 PM

i have a file which includes data and the program reads its in. I have created arrays for each data set in the file. One of the data sets "SolarPowerOpen" is a boolean array. It includes the values yes and no for 30 days. I have to find all the values which say yes (true) and display them. But the program only recognizes all the values as false. when i run the program it shows 0 days when the Solar power was open.



import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.*;
import javax.swing.*;
import javax.swing.JOptionPane;

public class CuriosityRover {

    public static void main (String[] args) throws IOException{
    
     
     int[] Day = new int[30];
     double[] Pressure = new double[30];
     double[] HighTemp = new double[30];  
	 double[] LowTemp = new double[30];
	 int[] WindSpeed = new int[30];
	 int[] BatteryPower = new int[30];
	 boolean[] SolarPowerOpen = new boolean[30];
	 
   
             File file = new File ("CuriosityRover.txt");
             FileReader fileReader  = new FileReader (file);
                 BufferedReader bufferedReader = new BufferedReader (fileReader);
            
             String line = "";
             int counter = 0;
            
             while (( line = bufferedReader.readLine()) != null){
                     String[] sort = line.split (",");
                    
                     Day[counter] = Integer.parseInt(sort[0]);
                     Pressure[counter] = Double.parseDouble(sort[1]);
                     HighTemp[counter] = Double.parseDouble(sort[2]);
                     LowTemp[counter] = Double.parseDouble(sort[3]);
                     WindSpeed[counter] = Integer.parseInt(sort[4]);
                     BatteryPower[counter] = Integer.parseInt(sort[5]);
                     SolarPowerOpen[counter] = Boolean.parseBoolean(sort[6]);
                     
                     counter++;
                       }

         int SolarDeployed = 0;
	 for (int i=0; i<SolarPowerOpen.length; i++){
	 if (SolarPowerOpen[i] == true)
	 SolarDeployed++;
	 }

}
}


This post has been edited by pbl: 29 November 2012 - 07:59 PM
Reason for edit:: Fixed code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Array keeps coming out as false

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

Re: Array keeps coming out as false

Posted 29 November 2012 - 07:58 PM

And the question is ???
And :code:
Welcome at DIC, I'll fix your first post
Was This Post Helpful? 0
  • +
  • -

#3 GuyWithDragonTattoo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-November 12

Re: Array keeps coming out as false

Posted 29 November 2012 - 08:03 PM

...

This post has been edited by pbl: 29 November 2012 - 08:22 PM
Reason for edit:: Empty post cleared

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1