Using Java: Program should receive as input (command line) the name of a file th
ID: 3540435 • Letter: U
Question
Using Java:
Program should receive as input (command line) the name of a file that
contains the alphabet of the text (characters) and their frequencies percents:
example file should contain the following
A .35 B .1 C .2 D .2 _ .15
The output to the screen should be a table of each character and its bit code.
example output
character: bit code
A: 11
B: 100
C: 00
D: 01
_: 101
Please don't post unrelated code, code from google that won't compile, spam, or outside of chegg offers as this will result in a 2 rating for not being helpful. I just need help with this code and willing to spend Chegg points for a right answer.
Explanation / Answer
package chegg;
import java.io.*;
import java.util.Scanner;
import java.lang.*;
public class Chegg
{
public static void main(String[] args) {
//String filePath = args[0];
BufferedReader br = null;
String filePath = "C:\Users\Dhanraj Purbiya\Documents\NetBeansProjects\train\src\chegg\babynames.txt";
Scanner in=new Scanner(System.in);
try {
String sCurrentLine;
String line="";
br = new BufferedReader(new FileReader(filePath));
while ((sCurrentLine = br.readLine()) != null) {
line=sCurrentLine;
}
char[] charArray=line.toCharArray();
char[] alphabateArray=new char[charArray.length];
byte bitCode[]=new byte[charArray.length];int j=0;
for(int i=0;i<charArray.length;i++)
{
if(Character.codePointAt(charArray,i)>64 && Character.codePointAt(charArray,i)<123)
{
alphabateArray[j]=charArray[i];
String ctr=Character.toString(charArray[i]);
j++;
}
}
System.out.println("Alphabates "+"Bit Code");
for(int i=0;i<alphabateArray.length;i++)
{
if(Character.codePointAt(alphabateArray,i)>64 && Character.codePointAt(alphabateArray,i)<123)
System.out.println(alphabateArray[i]+" "+Character.toString(alphabateArray[i]).getBytes()+" ");
}
System.out.println();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.