I have to do this simple project:

(a) A new project named LetterCountExample
(b) A main class for the project named the same of the project.
(c) A class called LetterCounter, with the following members:
i. A eld of type char named letter.
ii. A method of return type int, named doCount(String) that takes one argu-
ment of type String and returns the number of times the character in the
variable letter occurs in the given String.
(d) Create a Junit test that uses the test string "abracadabra" and veries that the
method returns the correct value.

So far I have gotten to this part but dont know what else to do, thanks for your help.

public class LetterCounter {
	
	public char letter = ' ';
	
	
	
	public int doCount(){
	
		
	}

}

I have this in the main part called LetterCountExample.java:

public class LetterCountExample {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("Enter a word");
		
		System.out.println("Enter letter that you wish to count");
		
	}

}

All I want to do is scan the input letter and send it to the char named letter , and scan the string send it also and with that a function that counts the letter in the string,returns the int value and then print it.

hi i want to create one project in java.. which topic is Human Resource Management.. how can't understand that how can i start home page..please help me about this...thank you........

Click on software dev then Java and start a thread.

Here is what I have so far:

LetterCountExample.java

import java.util.Scanner;

public class LetterCountExample {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		
		Scanner scanner = new Scanner(System.in);
		
		System.out.println("Enter a word: ");
		String word_input = scanner.nextLine();
		
		System.out.println("Enter letter that you wish to count: ");
		char letter_input = scanner.nextLine().charAt(0); 
	}

}

LetterCounter.java:

public class LetterCounter {
	
	
	public char letter_input;
	
	
	public void doCount(String word_input){
		
		if (word_input == null)
			return;
		
		int counter = 0;
		
		for (int i = 0; i < word_input.length(); i++ ){
			
			if (Character.isLetter (letter_input))
				counter++;
		}
	
		System.out.println("The input word has "+ counter + "letters.");
	}

	
}

I still have a problem as to how to send the scanned letter and word to LetterCounter.java so it can perform the method.

Let me check if I get the goal of your project.
You want to create a LetterCounter class with a doCount() method which takes a string and the character to count?

Let me check if I get the goal of your project.
You want to create a LetterCounter class with a doCount() method which takes a string and the character to count?

That is correct.

You defined your doCount() method with the return type void, while your assignment explicitly states that it should return an integer (int), you'll also want to add the following line to the end of the doCount() method once you've changed its return type to int: return counter;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.