Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Strategic Database Technology Management For The Year 2000

Authors: Alan Simon

1st Edition

155860264X, 978-1558602649

More Books

Students also viewed these Databases questions

Question

Have you defined the situation fairly and accurately?

Answered: 1 week ago

Question

What is the meaning and definition of E-Business?

Answered: 1 week ago