ANU The Australian National University



____________________________________________________

[ANU] [DCS] [COMP2100/2500] [Description] [Schedule] [Lectures] [Labs] [Homework] [Assignments] [COMP2500] [Assessment] [PSP] [Java] [Reading] [Help]

____________________________________________________

COMP2100/2500
Homework 9

Continue filling in a new Time Recording Log and Weekly Time Use Summary each week.

Write the following program, following the enhanced PSP as described in Lecture 19 and filling in the Project Plan Summary and a Defect Recording Log. Use one of the Project Plan Summary forms that doesn't have greyed-out sections.

Write a Java program called Percent that helps calculate the “To Date %” columns of your PSP Project Plan Summary.

The program shall operate as follows: It shall prompt for a list of integers from the standard input, one per line, terminated by a blank line (just as for Homework 3). It shall then calculate the total of those numbers and the percentage of that total that each represents. It shall present the output as a table, with two columns separated by exactly four spaces. The left column shall contain the original number, right-justified in a field of width four characters. The right column shall contain the percentages, followed by a ‘%’ symbol, right justified in a field of width six characters (up to three digits before the decimal point, the decimal point, one figure after the decimal point, and the percent symbol). Percentages shall be rounded to one decimal place.

For example (the To Date Time in Phase and the To Date Defects Injected from my Homework 7):

comp2100@partch java Percent
> 47
> 37
> 81
> 21
> 66
> 57
>

  47     15.2%
  37     12.0%
  81     26.2%
  21      6.8%
  66     21.4%
  57     18.4%
 309
comp2100@partch java Percent
> 2
> 17
> 1
> 3
>

   2      8.7%
  17     73.9%
   1      4.3%
   3     13.0%
  23

Notice that there is a blank line between the prompt for the last line of input and the start of the output. Notice also that the last line of output holds the total of all the inputs, but no percentage.

If there are no numbers input, or if their total is zero, the program should print an error message and stop (rather than trying to divide by zero). If one of the inputs is not an integer, it should print an error message and prompt for it again (just as in Homework 3).


PSP Note

If you re-use code from Homework 3, you should not count those lines as part of the new and changed lines of code for this program.


Hints

I think it might make sense to use your solution to Homework 3 as the starting point, and modify that program. You can then use diff to work out the new and changed lines of code just as you did for the last two homeworks.

____________________________________________________

[ANU] [DCS] [COMP2100/2500] [Description] [Schedule] [Lectures] [Labs] [Homework] [Assignments] [COMP2500] [Assessment] [PSP] [Java] [Reading] [Help]

____________________________________________________

Copyright © 2005, Ian Barnes, The Australian National University
Version 2005.1, Wednesday, 4 May 2005, 07:05:54 +1000
Feedback & Queries to comp2100@cs.anu.edu.au