Please do this question by using Java language as the questi

Please do this question by using Java language as the question request and do not use handwriting. Just type it after you test the code.

1. Write a Java program that inputs a document and ten outputs a bar-chart plot of the frequencies of each alphabet character that appears within that document.

Solution

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Test {

   public static void main(String[] args) throws IOException {
Map<Character, Integer> chars = new TreeMap<Character, Integer>();
Scanner scan = null;

try {
   scan = new Scanner(new File(\"D:/abc.txt\"),\"utf-8\");

while (scan.hasNext()) {
char[] line = scan.nextLine().toLowerCase().toCharArray();

for (Character character : line) {
if (Character.isLetter(character)){
if (chars.containsKey(character)) {
   chars.put(character, chars.get(character) + 1);
} else {
   chars.put(character, 1);
}
}
}
}
} finally {
if (scan != null){
   scan.close();
}
}

if (!chars.isEmpty()){
for (Map.Entry<Character, Integer> entry : chars.entrySet()) {
System.out.println(entry.getKey() + \": \" + entry.getValue());
}
}
}
}

Please do this question by using Java language as the question request and do not use handwriting. Just type it after you test the code. 1. Write a Java program

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site