|
|
This is similar to programming challenge 5, page 267 of our book (page 291 on the international version)
For this assignment you are going to write the code for the following class:
Here are the specifications of class LetterCounter:
Methods of class LetterCounter:
count
returns: nothing
arguments: nothing
what it does: it asks the user to enter a string, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. Make sure you count the characters using a loop. If you don't use a loop (there are other ways to count the characters) it will not count as correct even if you fool the testing program (yes, I will look at your code). The display should look as follows:
string: whatever the user entered
character: h
number of times character was found: 2
Read the instructions carefully:
- create a folder called Assignment08
- create a file called LetterCount.java and save it in folder Assignment08
- download file Test08.class.zip (Test08_java6.class.zip) and put it in your folder Assignment08
- compile all java files in folder Assignment08
- type the following command in the DOS prompt window:
java Test08
- tests will be run on your code and appropriate messages will be printed out showing which tests passed and which failed. At the end the program will tell you which option to choose in the moodle quizz corresponding to programming exercise 08
- You must use Test08.print or Test08.println instead of System.out.print and System.out.println. Use Test08_java6.print and Test08_java6.println if you are using java6.
You could use the following main method in order to test your program. You don't need to use it, you don't need to show it to me or submit it. Use it if you want to test your code:
public static void main(String[] args){
LetterCounter cc = new LetterCounter();
cc.count();
}
This main method could be a method of your LetterCount class. In that case you could test your class by typing:
java LetterCount
|
|
|