Page 2 of 2 FirstFirst 12
Results 21 to 26 of 26
  1. #21
    Wishes is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    hey
    I also made mistake when I run the program

    java codename.java

    that was the one reason of take run error

    thank yo

  2. #22
    Wishes is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    Hey

    no compile error
    or run error

    also I USED PRINTOUT STATEMENT TO CHEck read part and its read data correctly

    and its is write correctly but its always give me the length zero
    and I did some test I think my program didnt do the calculation
    which is private method in (claSS Bodor Vector)
    how I can call private method or at least make it work


    Java Code:
    import java.io.*;
    import java.util.*;
    
    class VectorAssignment {
    
             public static void main (String[] args)  {
    		  
                    ArrayList <BodorVector> vectors=new ArrayList<BodorVector>();
                    int  vectorsNumber=0,vectordimension=0;
    				Integer[] vectorcordinate=new Integer[10];
                    Point startpoint=new Point(vectordimension,vectorcordinate);
    				Point endpoint =new Point(vectordimension,vectorcordinate);
    				double vectorlength=0;
    				BodorVector TempVector=new BodorVector(startpoint,endpoint);
    			
    
        try{
        
                               /*********************************************************/
                             	 /**  Part One:      Read Data From Input File     **/
    					      /*********************************************************/
    						  
        // Get the object of DataInputStream
        // Open the file that is the first
    	FileReader fin = new FileReader("input.txt");
        Scanner mydata= new Scanner(fin);
    
    
    int i=1; // to dteremine line number
    
        //loop to Read the File number By number
     while (mydata.hasNextInt())  {	
     
                                     /** first line has the number of dimension **/
                                     if (i==1 ){//if one
                                                vectordimension=mydata.nextInt(); 
    			                                 i++;
    						                     vectorsNumber++; 
    		                                                          	
    		                                   	}//if 1
    																							
    									else if (i==2){
                                          /** second line is start points */                   
    											 for(int s=0; s< vectordimension;s++)
    										     vectorcordinate[s]=mydata.nextInt();
    											 startpoint= new Point(vectordimension,vectorcordinate);
    											 i++;
    											 }//if2
    			                                      else if(i==3){ 
    												  /** Third line is end points */ 
                                                        for(int f=0; f< vectordimension;f++)
    		                                           	vectorcordinate[f]=mydata.nextInt();	
    		                                          	endpoint= new Point(vectordimension,vectorcordinate);
    												     i=1;}//if3}
                                         						  							
                                    //** constructor vector with start and end point*/
                                    
    								TempVector=new BodorVector(startpoint,endpoint);
                                                        
    					            vectors.add(TempVector);
    
    }//while
    
                                     //Close the input stream
                                      mydata.close();
    								  
    								  
    								  
    								    /*********************************************************/
    								    /**  Part Two:      Write The Length to Output File     **/
                                        /*********************************************************/
    	
    								  
    								  FileWriter outputp = new FileWriter("C:\\output.txt");
                                      BufferedWriter outputdata = new BufferedWriter(outputp);
    								  
    		                          outputdata.write("Hello your file has  "+ vectorsNumber+ "   Vectors  ");
    		                          
    								  /**write a new line to the file so the next time you write   
                                                to the file it does it on the next line */ 
    								 outputdata.newLine();  
      
                                                    /** Loop to get the vectors Length **/
    		                                        for(int c=0;c<vectorsNumber;c++)
    		
    		                                          {
    												  TempVector=vectors.get(c);
    		                                          vectorlength=TempVector.getLength();
                                                      outputdata.write("The length of vector number **" +( c+1) + " ** equal   "   + vectorlength +"\n");
    	                                               outputdata.newLine();
    	                                              } // for
    	
    
    	                                        System.out.println("Thank you , The data has been written"+"  vector number" +vectorsNumber);
        	                                    
    											/** flush and close output file **/
    											
    											outputdata.flush();
                                                outputdata.close();
    											
    											
    											}//try2
    
    	  catch (Exception e){
    	  //Catch exception if any error occure 
          System.err.println("Error: " + e.getMessage());
        }
     
     }//MAIN
    }//CLASS
    Java Code:
    import java.math.*;
    
    class BodorVector {
    private Point start;
    private Point finish;
    private double length ;
    
    
         public BodorVector (Point x, Point y ){
    	 start = x;
    	 finish = y ;
    	 }
    	 private void calculatelength (){
    	 int dimes = start.getDim();
    	 Integer[] st= start.getCords();
    	 Integer[] fini=finish.getCords();
    	 int result =0;
    	 for (int i=0 ; i< dimes ;i++)
    	 {int dif=0;
    	    dif=Math.abs(st[i]-fini[i]);
    		dif = Math.abs(dif * dif ); 
    		result= result + dif;
    	 }
    	 
    	 //length = Math.sqrt(result);
    	 length= 6;
    	 }
    	 public double getLength (){
    	
    	 return  length ;
    	 }
    	 }
    Java Code:
    import java.util.*;
    
     class Point{
    int dimension;
     Integer[] coordinate;// ask about integer []
    
             public Point (int dim, Integer [] cords){
                     dimension = dim;
                     coordinate = cords;
             }
          
    
            	  public int getDim(){
                     return dimension ;
                    }
    				
    				public Integer[] getCords(){
    				 return coordinate ;
    				 }
    				 
    
     }
    Last edited by Wishes; 11-26-2010 at 11:11 AM.

  3. #23
    Wishes is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    Hey
    I chane the method calculatelength to public, and I called it in main class but it is still not working

    I dont know where the problem , I tried to put constant value for length in calculatelength
    but still give me zero that is mean my programm dosn't call calculatelength

    any suggestion

  4. #24
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Perhaps you need to show the data file and tell us just what this program is trying to do with the file. What is its purpose?

  5. #25
    Wishes is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    HEY

    Thank you
    I solved it by create two temprory varaible rather than one
    and its Work fine now.

  6. #26
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Java compile error
    By socboy6579 in forum New To Java
    Replies: 7
    Last Post: 10-14-2010, 06:48 PM
  2. Compile Error
    By gcorreageek in forum Advanced Java
    Replies: 2
    Last Post: 09-08-2010, 05:23 AM
  3. compile error
    By angryredantz in forum New To Java
    Replies: 1
    Last Post: 01-23-2009, 10:44 PM
  4. Compile Error - Please Help!!
    By AJ2009 in forum New To Java
    Replies: 10
    Last Post: 01-04-2009, 03:59 PM
  5. compile error
    By dirtycash in forum New To Java
    Replies: 6
    Last Post: 12-12-2007, 06:00 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
  •