Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a TEXT ONLY client (no extending window controller or including any graphi

ID: 3685326 • Letter: W

Question

  1. 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).
  1. 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();
           }
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote