2a) Write a method to input a list of words and returns a string in which all bu
ID: 665615 • Letter: 2
Question
2a) Write a method to input a list of words and returns a string in which all but the last word are replaced with the initial letter. The input represents one or more given names, and ends with the family name. For example, given the input string Hilda Mary Primrose Smith the method should return the string H. M. P. Smith. 2b) Suppose you have a table of internet movies and the number of downloads for each movie, defined by a variable HashNap downloads. Write the signature and body for a method mostDownloaded that returns the Movie object that has the most downloads.Explanation / Answer
public Movie mostDownloaded(HashMap<Movie,Integer> downloads)
{
Integer maxi = new Integer(-1);
Movie mov;
Iterator it = downloads.entrySet().iterator();
for (Map.Entry<Movie, Integer> entry : downloads.entrySet()) {
Movie key = entry.getKey();
int value = entry.getValue();
if((value)>maxi)
{
maxi=value;
mov=key;
}
}
return mov;
}
public String shortName(String name[])
{
String shorterName="";
int n=name.length;
for(int i=0;i<n-1;i++)
shorterName=shorterName+name[i].charAt(0)+". ";
shorterName=shorterName+name[n-1];
return shorterName;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.