Question: Problem 1: Count Characters Write a program named CountChar.java, implement a method specified below: public static int countChar(char c, String str) This method counts the

Problem 1: Count Characters

Write a program named CountChar.java, implement a method specified below:

public static int countChar(char c, String str)

This method counts the number of occurrence of the character in the String.

Then test your method as follows:

1. Pass a character and a string as arguments to the main method

2. Call countChar method

3. Print how many times the character appears in the String

For example, if you pass the argument o "Introduction to Java Program", your program should display:

The character "o" appears in the String 4 times.

===========================================================================================

Problem 2: Grade Distribution

Design a program named GradeDistribution.java that reads grades from a data file(grades.txt is given for testing), then counts and displays grade distribution as follows:

Grade Range No.

[90 - 100] 2

[80 - 89] 5

[70 - 79] 1

[0 - 69] 1

Others 1

======================================================================================================================

Problem 3: Secret Channels

A company uses public Internet to carry its phone service. The voice data will be encrypted before sending to the Internet. The encryption algorithm is as follows:

For each four-digit decimal integer, (1) Add 5 to each digit, divide the sum by 10 and use the remainder to replace the digit, (2) Swap 1st-digit with 4th-digit, (3) Swap 2nd-digit with 3rd-digit. (The program must be named as Encrypted.java)

Input: A series of lines. Each line is a positive four-digit decimal integer.

Output: In each line, print the encrypted four-digit decimal integer.

Sample Input (sample data file is provided for your testing purpose):

0123

5890

9999

Sample Output

8765

5430

4444

==============================================================================

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!