a)You can begin by reading the html file. R makes this easy to do Your first tas
ID: 3700191 • Letter: A
Question
a)You can begin by reading the html file. R makes this easy to do
Your first task is to write code to count the total number of faculty in the department. Everyone listed on the website is a member of the faculty. Report your answer.
b) Now count the number of “full professors”. A “full professor” is someone who is listed as a professor but does not have the term “assistant” or “associate” in their title. For example, a Distinguished Professor is a “full professor” but an “Assistant Teaching Professor” is not a full professor.
c) List the various categories of faculty in the department. That is, find all the titles and only list the ones that are unique, e.g. Professor, Assistant Teaching Professor, Instructor, and so on. Read through your list carefully – make sure that you are not repeating categories (pay attention to spaces, typos and abbreviations). Report both the number of categories as well as the number of people in each category.
d) Create a data frame that contains all the names of faculty who are listed as Assistant Teaching Professor. The first column should be the last name and the second column should be the first name.
e) What proportion of faculty in the department have “teaching” in their title? What proportion have “research” in their title?
Explanation / Answer
package com.practice.java;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
public class ShowDetail {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
URL website = new URL("http://stat.psu.edu/people/faculty");
URLConnection connection = website.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
connection.getInputStream()));
String inputLine;
String nextLine;
String jobTitle;
int count =0;
int totalCount = 0;
Map<String,Integer> propessorsCountMap = new HashMap<String,Integer>();
while ((inputLine = in.readLine()) != null){
if(inputLine.contains("jobTitle")){
totalCount = totalCount +1;
nextLine = in.readLine();
if(nextLine != null){
jobTitle = nextLine.replace("<li>", "").replace("</li>", "").trim();
if (propessorsCountMap.get(jobTitle) != null){
count = propessorsCountMap.get(jobTitle);
count = count+1;
propessorsCountMap.put(jobTitle,count);
} else {
propessorsCountMap.put(jobTitle, 1);
}
}
}
}
System.out.println("total number of faculty :: "+totalCount);
int fullProfessorsCount = 0;
for (Map.Entry<String,Integer> entry : propessorsCountMap.entrySet()) {
if(!(entry.getKey().contains("Assistant")) && !(entry.getKey().contains("Associate"))){
fullProfessorsCount = fullProfessorsCount +entry.getValue();
}
}
System.out.println("full professor count :: "+fullProfessorsCount);
for (Map.Entry<String,Integer> entry : propessorsCountMap.entrySet()) {
System.out.println("category::"+entry.getKey() + " count::"+entry.getValue());
}
in.close();
}
}
output :
total number of faculty :: 57
full professor count :: 24
category::Professor count::9
category::Verne M. Willaman Professor count::1
category::Associate Professor count::2
category::Instructor count::4
category::Teaching Lecturer count::2
category::Lecturer count::1
category::Assistant Teaching Professor count::10
category::Professor and Department Head count::1
category::Professor, Director of SCC and Online Programs count::1
category::Professor, Associate Head for Graduate Studies count::1
category::Research Professor count::2
category::Bruce Lindsay Visiting Assist.Professor count::1
category::Associate Research Professor count::2
category::Distinguished Professor count::2
category::Assistant Professor count::12
category::Assistant Research Professor count::6
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.