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

Ranking Programming Languages Suppose you are given an input file with the names

ID: 3705641 • Letter: R

Question

Ranking Programming Languages Suppose you are given an input file with the names of few top ranked programming languages and names are separated by comma. Your task is to read the names from the input file and print the names in an output file and give them the rank in the order they appear. So, the first language gets the rank of 1, the next one gets the rank 2 and so on. Lab Scenario: I. The program reads from an already provided input file: ILA8.in. The name of the languages is in one line separated by comma. The format of the file is as follows: PYTHON, SQL, JAVA, JAVASCRIPT, C#, C++, PHP, PERL, RUBY/RAILS You will perform the file open operation. And then perform the read operation with your favorite read functions and read the content of the file Once you are done reading, process the file content and then using your favorite write operations and write the content to another file. Please don't forget to close the file. So that "Python" gets the rank of 1, "SQL" will be rank 2 and so on. The sample output should look like this: 2. 3. Language Rank PYTHON 1 SQL2 JAVA 3 JAVASCRIPT 4 C# 5 PHP 7 PERL 8 RUBY/RAILS 9 For this lab, you are expected to use functions and file VO operations. There should be at least 3 user defined functions. One main0, one file_read0 to read the content of the file ILA8.in and one for file_ write() to write the table to another file. The output file should be named as: firstname_ lastname_ ILA8.out 4.

Explanation / Answer

package chegg1;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.util.StringTokenizer;

public class ReadFile {

public static void main(String[] args) {

BufferedReader br = null;

try {

String line;

br = new BufferedReader(new FileReader("C:\Users\cr\Desktop\data22.txt"));

int count=1;

while ((line = br.readLine()) != null ) {

System.out.println(line);

if(line!= null){

String[] listLine = line.split(";");

for(String l : listLine){

sqrt(l,count);

count++;

}

}

  

}

  

} catch (IOException e) {

e.printStackTrace();

} finally {

try {

if (br != null)

br.close();

} catch (IOException ex) {

ex.printStackTrace();

}

}

}

private static void sqrt(String line,int count) {

// TODO Auto-generated method stub

//

System.out.println("line "+line);

BufferedWriter bw = null;

FileWriter fw = null;

try {

String data = " This is new content";

File file = new File("C:\Users\cr\Desktop\data2222.txt");

// if file doesnt exists, then create it

if (!file.exists()) {

file.createNewFile();

}

// true = append file

fw = new FileWriter(file.getAbsoluteFile(), true);

bw = new BufferedWriter(fw);

Integer countVal = Integer.valueOf(count);

if(countVal == 1 ){

bw.write("Langunage");

bw.write(" ");

bw.write("Rank");

bw.write(" ");

}

bw.write(line);

bw.write(" ");

bw.write(String.valueOf(countVal));

bw.write(" ");

} catch (IOException e) {

e.printStackTrace();

} finally {

try {

if (bw != null)

bw.close();

if (fw != null)

fw.close();

} catch (IOException ex) {

ex.printStackTrace();

}

}

}

}