Write a TEXT ONLY client (no extending window controller or including any graphi
ID: 3685326 • Letter: W
Question
- Write a TEXT ONLY client (no extending window controller or including any graphics) which reads in a file with the format given below and stores all characters in a 2D array of characters. Your client should also be capable of printing out the contents of its 2D array. Implement the reading in a separate method from the printing and make both methods separate from the main. Main should call each of the other two in turn (in the usual way for the toString method).
- Write a TEXT ONLY client (no extending window controller or including any graphics) which reads in a file with the format given below and stores all characters in a 2D array of characters. Your client should also be capable of printing out the contents of its 2D array. Implement the reading in a separate method from the printing and make both methods separate from the main. Main should call each of the other two in turn (in the usual way for the toString method).
Explanation / Answer
import java.io.*;
class Client
{
char c[][];
int count = 0;
void readMaze()
{
try
{
FileInputStream fin=new FileInputStream("Client.java");
FileReader f = new FileReader("Client.java");
BufferedReader br = new BufferedReader(f);
while(br.readLine()!=null)
{
count++;
}
System.out.println("COUNT " + count);
c = new char[count][100];
for(int i=0;i<count;i++)
{
for(int j=0;j<100;j++)
{
c[i][j] = (char)fin.read();
}
}
fin.close();
f.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
void print()
{
for (int i =0; i <count; i++)
{
for (int j = 0; j < 100; j++)
{
System.out.print(" " + c[i][j]);
}
}
}
public static void main(String args[])
{
Client cc = new Client();
cc.readMaze();
cc.print();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.