Java Problem – Text File I/O and Processing, Random Access Files Problem descrip
ID: 3812867 • Letter: J
Question
Java Problem – Text File I/O and Processing, Random Access Files
Problem description
Write a class that provides the following three methods:
1.countChars(String filename, char c) – counts the number of times that a character c occurs in a text file <filename>.
2.readString(String <inputfilename>, String <outputfilename>) – reads strings from a text file <inputfilename>, one string per line, sorts the strings, and writes the sorted strings one per line to a file <outputfilename>.
3.displayInteger(String filename>) – the first entry of a random access file <filename> is long value specifying the offset of an integer value somewhere in the middle of the file. Uses the RandomAccessFile class to display the value of the integer.
Write a test class to test above three methods. You may need to prepare text files for the test.
Analyze the problem and design classes
Design and implement the method countChars
Design and implement the method readString
Design and Implement the method DisplayInteger
Implement the test class
Prepare the test cases
Run the test and record the results
Explanation / Answer
public class countchars {
public static void main()
{
int count = 0;
string t;
while(t=br.readline! = null)
{
for(int i =0 ; i <t.lenght(); i++)
{
char ch = t.charAt(i);
if(ch=='c')
{
count++;
}
}
}
system.out.println("number of c are" : +count);
2)
public class readstring {
public static void main()
{
}
f.close();
out.println(l);
}
w.close();
}
}
string file = "chegg.txt";
string outputfile = "sorted.txt";
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.