Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: textAnalyser help

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation textAnalyser help

    Hello,

    I am totally new to Java programming and I have this problem to solve... Can anyone help me continue it or at least writing some methods for the code

    it is a text analyser programm to analyse any imported text ( such as calculating the number of chars in the text, the frequency of a char .... etc)

    the code is

    public class textAnalyser{

    String corpusID;



    public textAnalyser(String corpusID){
    this.corpusID = corpusID;

    }
    private int numChars(){

    }

    public String getCorpusID(){
    return corpusID;
    }

    public int getNumChars(){
    return numChars;
    }
    public void addTexttoCorpus(String text){

    }
    public void clear(){

    }
    public int frequencyOf(char c){

    }
    public double percentageOf(char c){

    }
    public char mostFrequent(){

    }


    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: textAnalyser help

    Can you explain where you are having problems?
    Do you have any code that will compile and execute? What you posted looks like a very bare skeleton.

  3. #3
    Member
    Join Date
    Oct 2010
    Posts
    40
    Thanks
    0
    Thanked 2 Times in 1 Post

    Default Re: textAnalyser help

    Most of the code you needed is in the String API. Just check the documentation. You wont benefit anything from asking people to do the coding for you. The code u needed is just simple, with patient i know you can do it. Gudluck. =)

  4. #4
    Junior Member
    Join Date
    Oct 2009
    Posts
    7
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: textAnalyser help

    Should get you started.

    public class TextAnalyser {
     
    	private String inputString;
     
    	public TextAnalyser(String inputString) {
    		this.inputString = inputString;
    	}
     
    	public int numChars(){
    		return inputString.length();	
    	}
     
    	public String getInputString() {
    		return inputString;
    	}
     
    	public void addTextToInputString(String text) {
    		inputString += text; //prefer string builder
    	}
     
    	public void clear() {
    		inputString = null;
    	}
     
    	public int frequencyOf(char c) {
    		int count = 0;
    		for(int x = 0; x < inputString.length(); x++) {
    			if(inputString.charAt(x) == c) {
    				count++;
    			}
    		}
    		return count;
    	}
     
    	public double percentageOf(char c) {
    		return ((double)frequencyOf(c) / (double)inputString.length()) * 100D;
    	}
     
    	//public char mostFrequent(){	
    	//}
     
     
    }

    I haven't added any null checks ect but i hope this helps.