Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Author: Marty Stepp (on 07/08) Write a function named input_stats that accepts a

ID: 3594679 • Letter: A

Question


Author: Marty Stepp (on 07/08) Write a function named input_stats that accepts a string parameter representing a file name, then opens/reads that file's contents and prints information to the console about the file's lines. Report the length of each line, the number of lines in the file, the length of the longest line, and the average characters per line, in exactly the format shown below. You may assume that the input file contains at least one line of input. For example, if the input file carrol.txt contains the following data Beware the Jabberwock, my son, the jaws that bite, the claws that catch, Beware the JubJub bird and shun the frumious bandersnatch Then the call of input.stats ("carroll.txt") should produce the following console output: Line 1 has 38 chars Line 2 has 41 chars Line 3 has 8 chars Line 4 has 31 chars Line 5 has 26 chars 5 lines longest = 41, average 25.6 If the input file does not exist or is not readable, your function should prno output. If the file does exist, you may assume that the file contains at least 1 line of input. Constraints: Your solution should read the file only once, not make multiple passes over the file data. Type your Python solution code here:

Explanation / Answer

import java.util.*;

public class HashTableDemo {

public static void main(String args[]) {
// Create a hash map
Hashtable balance = new Hashtable();
Enumeration names;
String str;
double bal;

balance.put("aaa", new Double(3434.34));
balance.put("bbb", new Double(123.22));
balance.put("ccc", new Double(1378.00));
balance.put("ddd", new Double(99.22));
balance.put("eee", new Double(-19.08));

// Show all balances in hash table.
names = balance.keys();
while(names.hasMoreElements()) {
str = (String) names.nextElement();
System.out.println(str + ": " +
balance.get(str));
}
System.out.println();
// Deposit 1,000 into aaa's account
bal = ((Double)balance.get("aaa")).doubleValue();
balance.put("aaa", new Double(bal+1000));
System.out.println("aaa's new balance: " +
balance.get("aaa"));
}
}