For Homework Four they were to supply explanations not just answers. Below you will find the solutions for Homework Five. I include guidelines for each one of them below. In general the grade should be the percentage of inputs that the program would get correct, modulo some considerations of style. The guidelines below refer to the structure and should they solve the problem in a different manner (but correctly) give them the points by thinking in what category their solution falls in. So, roughly, please give: 2 points for proper use of loop to read from user 2 points for proper use of tokenizer to read tokens 3 points for properly updating the counter 2 points for careful initialization of the counter (these are the guidelines for problem One. All the others are preceded by guidelines when they are listed). :::::::::::::: One.java :::::::::::::: import java.util.*; class One { public static void main(String[] args) { ConsoleReader c = new ConsoleReader(System.in); System.out.print("enter> "); String line = c.readLine(); while (!line.equals("done")) { StringTokenizer st = new StringTokenizer(line); int i = 0, number = -1; while (st.hasMoreTokens()) { String one = st.nextToken(); i = i + 1; } System.out.println(i + " tokens on this line."); System.out.print("enter> "); line = c.readLine(); } System.out.println("Thank you for using this program."); } } 2 points for proper use of loop to read from user 2 points for proper use of tokenizer to read tokens 3 points for properly updating the sum variable 2 points for careful initialization of the sum variable :::::::::::::: Two.java :::::::::::::: import java.util.*; class Two { public static void main(String[] args) { ConsoleReader c = new ConsoleReader(System.in); System.out.print("enter> "); String line = c.readLine(); while (! line.equals("done")) { StringTokenizer st = new StringTokenizer(line); int sum = 0; while (st.hasMoreTokens()) { sum += Integer.parseInt(st.nextToken()); } System.out.println("The sum is: " + sum); System.out.print("enter> "); line = c.readLine(); } } } 1 point for proper use of loop to read from user 1 point for proper use of tokenizer to read tokens 2 points for properly updating the sum variable 2 points for careful initialization of the sum variable 2 points for careful initialization of the counter 1 points for properly updating the counter :::::::::::::: Three.java :::::::::::::: import java.util.*; class Three { public static void main(String[] args) { ConsoleReader c = new ConsoleReader(System.in); System.out.print("enter> "); String line = c.readLine(); while (! line.equals("done")) { StringTokenizer st = new StringTokenizer(line); int sum = 0, i = 0; while (st.hasMoreTokens()) { sum += Integer.parseInt(st.nextToken()); i = i + 1; } if (i == 0) { System.out.println("No numbers, no average."); } else { System.out.println(" Sum is: " + sum + "\n Count is: " + i + "\n Average is: " + (double)sum / i); } System.out.print("enter> "); line = c.readLine(); } } } 2 point for proper use of loop to read from user 2 point for proper use of tokenizer to read tokens 3 points for properly updating the sum variable 2 points for careful initialization of the sum variable :::::::::::::: Four.java :::::::::::::: import java.util.*; class Four { public static void main(String[] args) { ConsoleReader c = new ConsoleReader(System.in); System.out.print("enter> "); String line = c.readLine(); while (! line.equals("done")) { StringTokenizer st = new StringTokenizer(line); int sum = 0; while (st.hasMoreTokens()) { String token = st.nextToken(); sum += Integer.parseInt(token) * Integer.parseInt(token); } System.out.println("The sum is: " + sum); System.out.print("enter> "); line = c.readLine(); } } } 0.5 points for proper use of loop to read from user 0.5 points for proper use of tokenizer to read tokens 1 point for properly updating the sum variable 1 point for careful initialization of the sum variable 1 point for properly updating the counter variable 1 point for careful initialization of the counter variable 1 point for properly updating the sumSq variable 1 point for careful initialization of the sumSq variable 2 points for the final formula for standard deviation :::::::::::::: Five.java :::::::::::::: import java.util.*; class Five { public static void main(String[] args) { ConsoleReader c = new ConsoleReader(System.in); System.out.print("enter> "); String line = c.readLine(); while (! line.equals("done")) { StringTokenizer st = new StringTokenizer(line); int i = 0, sum = 0, sumSq = 0; while (st.hasMoreTokens()) { String token = st.nextToken(); int number = Integer.parseInt(token); i += 1; sum += number; sumSq += number * number; } System.out.println(" Count is: " + i); System.out.println(" Sum is: " + sum); System.out.println(" Sum of squares is: " + sumSq); System.out.println(" Standard deviation is: " + Math.sqrt((sumSq - (double)sum * sum / i) / (i - 1))); System.out.print("enter> "); line = c.readLine(); } System.out.println("Thanks for using this program."); } } 1 point for the loop that reads for the user 1 point for the correct initialization of i 1 point for the correct initialization of sum 1 point for the correct initialization of average 2 points for the loop that calculates the average 2 points for the loop that calculates the deviations 1 point for putting it together at the end :::::::::::::: Six.java :::::::::::::: import java.util.*; class Six { public static void main(String[] args) { ConsoleReader c = new ConsoleReader(System.in); System.out.print("enter> "); String line = c.readLine(); while (! line.equals("done")) { StringTokenizer st = new StringTokenizer(line); int i = 0, sum = 0; double average = 0; while (st.hasMoreTokens()) { String token = st.nextToken(); int number = Integer.parseInt(token); sum += number; i += 1; } average = (double) sum / i; double numerator = 0; st = new StringTokenizer(line); while (st.hasMoreTokens()) { String token = st.nextToken(); int number = Integer.parseInt(token); numerator += (number - average) * (number - average); } System.out.println(" The average is: " + average); System.out.println(" The sum of squared deviations is: " + numerator); System.out.println(" The standard deviation is: " + Math.sqrt(numerator / (i - 1))); System.out.print("enter> "); line = c.readLine(); } } } 2 points for the loop that reads from the user 2 points for the proper treatment of empty line 2 points for the tokenizer loop 3 points for the if statement in it :::::::::::::: Seven.java :::::::::::::: import java.util.*; class Seven { public static void main(String[] args) { ConsoleReader c = new ConsoleReader(System.in); System.out.print("enter> "); String line = c.readLine(); while (! line.equals("done")) { StringTokenizer st = new StringTokenizer(line); if (st.countTokens() == 0) { System.out.println("Empty line."); } else { int max = Integer.parseInt(st.nextToken()); while (st.hasMoreTokens()) { String token = st.nextToken(); int number = Integer.parseInt(token); if (max < number) max = number; } System.out.println("The largest number is: " + max); } System.out.print("enter> "); line = c.readLine(); } } } same as the above (I even kept the same variable name) :::::::::::::: Eight.java :::::::::::::: import java.util.*; class Eight { public static void main(String[] args) { ConsoleReader c = new ConsoleReader(System.in); System.out.print("enter> "); String line = c.readLine(); while (! line.equals("done")) { StringTokenizer st = new StringTokenizer(line); if (st.countTokens() == 0) { System.out.println("Empty line."); } else { int max = Integer.parseInt(st.nextToken()); while (st.hasMoreTokens()) { String token = st.nextToken(); int number = Integer.parseInt(token); if (max > number) max = number; } System.out.println("The smallest number is: " + max); } System.out.print("enter> "); line = c.readLine(); } } } 2 points for properly treating the string input(s) 5 for the if statement that properly categorizes the input 1 for the loop that reads from the user 1 for correct arithmetic :::::::::::::: Nine.java :::::::::::::: import java.util.*; class Nine { public static void main(String[] args) { ConsoleReader c = new ConsoleReader(System.in); System.out.print("enter> "); String line = c.readLine(); int sum = 0; while (! line.equals("done")) { if (line.equals("nickel")) sum += 5; else if (line.equals("dime")) sum += 10; else if (line.equals("cent")) sum += 1; else if (line.equals("quarter")) sum += 25; else if (line.equals("dollar")) sum += 100; else System.out.println("I don't understand " + line); System.out.println("Your balance is: " + sum / 100.00); System.out.print("enter> "); line = c.readLine(); } } } 2 points for properly treating the string input(s) 3 for the if statement that properly categorizes the input 2 for the tokenizer loop (on each line) 1 for the loop that reads from the user 1 for correct arithmetic :::::::::::::: Ten.java :::::::::::::: import java.util.*; class Ten { public static void main(String[] args) { ConsoleReader c = new ConsoleReader(System.in); System.out.print("enter> "); String line = c.readLine(); int sum = 0; while (! line.equals("done")) { StringTokenizer st = new StringTokenizer(line); while (st.hasMoreTokens()) { line = st.nextToken(); if (line.equals("nickel")) sum += 5; else if (line.equals("dime")) sum += 10; else if (line.equals("cent")) sum += 1; else if (line.equals("quarter")) sum += 25; else if (line.equals("dollar")) sum += 100; else System.out.println("I don't understand " + line); } System.out.println("Your balance is: " + sum / 100.00); System.out.print("enter> "); line = c.readLine(); } } } Many thanks for your help. ... Adrian