Write a MapReduce JAVA program. You will need to write a MapReduce job that read
ID: 3814847 • Letter: W
Question
Write a MapReduce JAVA program.
You will need to write a MapReduce job that reads in text input and computes the average length of all words that start with each character. For any text input, the job should report the average length of words that begin with ‘a’, ‘b’, and so forth. For example, for input:
No now is defenitely not the time
The output would be:
N 2.0
n 3.0
d 10.0
i 2.0
t 3.5
For initial solution, your program should be case sensitive as shown in the example.
The frameworks of the java programs are given in your workspace directory: /home/training/training_materials/developer/exercises/averagewordlength/src/stub
Please fill in the TODO parts and compile the program.
To test your program, please use the test file in folder: /home/training/training_materials/developer/data/shakespeare
AND based on the output, write a JAVA program to load the output into a HBase table.
Explanation / Answer
import java.util.Scanner;
public class HelloWorld
{
public static void main(String []args)
{
int len[]=new int[50];
char chr[]=new char[50];
String s,s1;
s1="";
char ch,c,k;
int i,l,a,b,j,su,h,count;
a=0;
b=0;
su=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter a text ");
s=sc.nextLine();
s=s+" ";
for(i=0;i<s.length();i++)
{
ch=s.charAt(i);
if(ch!=' ')
s1=s1+ch;
else
{
c=s1.charAt(0);
l=s1.length();
System.out.println(c);
System.out.println(l);
s1="";
len[a++]=l;
chr[b++]=c;
}
l=0;
}
for(i=0;i<a;i++)
{
k=chr[i];
for(j=0;j<b;j++)
{
if(k==chr[j])
{
su=su+len[j];
count=count+1;
}
}
for(h=0;h<a;h++)
{
if(chr[i]==k)
chr[i]='.'
}
System.out.print(k+" "+su/count);
System.out.println();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.