Results 1 to 6 of 6

Thread: Err in programm

  1. #1
    nassir is offline Member
    Join Date
    Dec 2009
    Posts
    33
    Rep Power
    0

    Exclamation Err in programm

    hi everybody
    i have the project but can not run correct

    Java Code:
    import java.util.*;
    import java.io.*;
    public class datamain{
    	 //private static  Scanner scan;
    	public static void main (String[] args) throws IOException{
    		datafile ff=new datafile();
    		datafile2 ff2=new datafile2();
    		System.out.println ("======== Welcomr ============\n");
    		System.out.println ("        1-information");
    		System.out.println ("        2-information");
    		System.out.println ("        3-information");
    		System.out.println ("        4-Exit");
    		Scanner scan=new Scanner(System.in);
    		int tni=scan.nextInt();
    		switch(tni){
    			case 1:info();break;
    			//case 2:info();break;
    			//case 3:info();break;
    			case 4:System.exit(0);
    			
    		}
    		ff2.vectt();
    	
    	}
    		  public  static  void  info () throws  IOException{
    		  	for(int i=1;i<10;i++){
    		  	System.out.println ("");
    		  	}
    		  	Scanner scan=new Scanner(System.in);
    		  	datafile ff=new datafile();
    		  	System.out.println ("Enter your name: ");
    			String name1=scan.next();
    			ff.setname(name1);
    			System.out.println ("Enter your Age: ");
    			int age1=scan.nextInt();
    			ff.setAge(age1);
    			System.out.println ("Enter your country: ");
    			String country1=scan.next();
    			ff.setcountry(country1);
    			
    		
    		
    		
    }
    }
    
    ==================
    import java.util.*;
    import java.io.*;
    public  class datafile{
    	
    	private static String name;
    	private static int Age;
    	private static String country;
    	
    	public void setname(String name){
    		this.name=name;
    	}
    	public String getname(){
    		return name;
    	}
    	public void setAge(int Age){
    		this.Age=Age;
    	}
    	public int getAge(){
    		return Age;
    	}
    	public void setcountry(String country){
    		this.country=country;
    	}
    	public String getcountry(){
    		return country;
    	}
    	
    }
    
    
    ==================
    
    import java.util.*;
    import java.io.*;
    public class datafile2{
    	int div=3;
    	File outFileName=new File("C:\\ali.txt");
    	Vector vect=new Vector();
    	datafile ff=new datafile();
    	public  void vectt() {
    	vect.add(ff.getname());
    	vect.add(ff.getAge());
    	vect.add(ff.getcountry());
    	/*for(int i=0;i<vect.size();i++){
    	System.out.println (vect.get(i));
    	}*/
    	
    	try {
            BufferedWriter out = new BufferedWriter(new FileWriter(outFileName));
            int count = 0 ;
            for(int index = 0 ; index < vect.size() ; index++ ){
            out.write( vect.get(index).toString() +"," );
            count++;
            if(count%div == 0)
            out.newLine();
            }
            out.close();
        } catch (IOException e) {
        	System.out.print(e.getMessage());
      
        }
    	}
    }



    i wrote this programm but no doing

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

    Default

    What is the problem with your program?

    * Does it compile?
    * Does it run?
    * Are you seeing any error messages?

    If any errors, post them here as well as indicating which line is causing the error.

  3. #3
    Jevy is offline Member
    Join Date
    Oct 2008
    Posts
    3
    Rep Power
    0

    Default

    Hey nassir, your local variable above in "datafile class" needs to be in lowercase as well as the parameters passed into these two methods above that you have posted.However,here is the problem below:

    1)private static int Age;

    2)public void setAge(int Age){
    this.Age=Age;
    }

    3)public int getAge(){
    return Age;
    }

    The corrected version should look similar like this inorder to compile and run your code:

    1)private static int age;
    2)private void setAge(int age){
    this.age = age;
    }
    3)private int getAge(){
    return age;
    }


    Thanks,
    Jevy......

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by nassir View Post
    i wrote this programm but no doing
    Have you ever compile this code before write this complete code, I can see three classes there. Didn't you compile at least one of them before finalize the whole? If you comes with an error please let us know, without knowing that how can we comment on this pal. Good luck!

  5. #5
    nassir is offline Member
    Join Date
    Dec 2009
    Posts
    33
    Rep Power
    0

    Default

    Thank you for the good efforts

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Marks programm
    By blackmoon in forum AWT / Swing
    Replies: 5
    Last Post: 12-08-2009, 11:06 PM
  2. [SOLVED] my programm doesn´t run like it shoud be.
    By AlejandroPe in forum New To Java
    Replies: 3
    Last Post: 04-07-2009, 01:42 PM
  3. web programm (.jsp)
    By renars1985 in forum New To Java
    Replies: 1
    Last Post: 12-18-2007, 04:23 PM
  4. web programm (.jsp)
    By renars1985 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-18-2007, 09:34 AM
  5. Programm Error: cannot find symbol Help?
    By junix in forum New To Java
    Replies: 2
    Last Post: 12-10-2007, 06:30 AM

Posting Permissions

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