Coronavirus made it tough but we keep working remotely with no delays. Get 15% OFF your First Order
Get 15% OFF your First Order

Programming

writing a complex program that includes: reading and printing data, computing new data, updating existing data, error checking. Practice modularization by having to structure the program using methods with specific signatures.

I don’t understand this Java question and need help to study.

Task 1

Objectives: writing a complex program that includes: reading and printing data, computing new data, updating existing data, error checking. Practice modularization by having to structure the program using methods with specific signatures.

Project: HW7_Chart

This program will deal with printing a chart and reading and updating the data for the chart.

Implement the following methods:

  • void printHorizChart(int[] counts, String[] items) – prints the items and as many stars as the value associated with each item. The bottom row will show the corresponding number (like and x-axis): 4 spaces are allocated for printing a number. The stars should be aligned with the numbers. See sample run.

    The left column displaying the item names must be adjusted based on the current names. For example if “Strawberry” was not there it would be:

    Apple |   *_x000D_
    Banana|   *   *_x000D_
    Grape |   *   *   *   _x000D_
    Pear  |   *_x000D_
    ct    |   1   2   3  ...._x000D_
    	
  • String itemMaxCount(int[] counts, String[] items) Finds and returns the item that has the largest count. If two items have that same largest count, print the first one. E.g. for
    Apple |   *_x000D_
    Banana|   *   *   *   *_x000D_
    Grape |   *   *   *   *_x000D_
    Pear  |   *_x000D_
    ct    |   1   2   3   4 ....

    it will return Banana.

  • int[] getPercentages(int[] counts) – create and return an int array with corresponding percentages for counts. Use the formula:
    item_percentage = (item_count * 100)/sum_of_counts
    for example if the 5 count values are: 1,2,1,5,1, the sum of counts is: 1+2+1+5+1 = 10 and the percentage corresponding to value 2 is: 2*100/10 = 20. See the printed charts for Banana for counts (see 2 stars) and percentages (see 20 stars).
    See in the sample run below that both 1,2,1,5,1 and 100,200,100,500,100 resulted in the same percentage values:10,20,10,50,10.
  • int[] readCounts() – reads count data from the user. The user will give all the data on one line.
  • String[] readItems() – reads items data from the user. The user will give all the data on one line. NOTE that you MUST read the Strings with kb.next() not with kb.nextLine(). Why?
  • void updateCounts(int[] counts, String[] items, String givenItem, int value) – if givenItem is one of the strings in items, update the count corresponding to it.
    If counts and items do not have the same length or if givenItem is not in the list, it will print an error message and NOT update anything.
    When comparing the givenItem with the Strings in items, do a case-sensitive comparison.
  • in main the program will repeat the following sequence of actions
    • readItems
    • readCounts
    • print the horizontal chart with counts
    • print the item that has the largest count
    • compute percentages
    • print the horizontal chart with percentages
    • prompt the user for an item name and a value
    • call the updateCounts with the above item and value
    • print the horizontal chart of counts
    • print the item that has the largest count
    • prompt the user if they want to continue. Must use 0 (zero) for No and 1 for Yes.
  • Other issues: it is ok to move the empty line from before the printed charts if it makes the output easier to read.
  • FOR FUN, NOT required: void printVertChart(int[] counts, String[] items) – prints a vertical chart – We should discuss this in class.
---------------Sample run (this is a single run of the program)_x000D_
Enter the number of items and their names (N item1 item2 ... itemN): 5 Apple Banana Strawberry Grape Pear _x000D_
Reading the items finished. _x000D_
Enter the data for the counts array in format (N count1 count2 ... countN): 5 1 2 1 5 1_x000D_
Reading the counts finished. _x000D_
_x000D_
Apple     |   *_x000D_
Banana    |   *   *_x000D_
Strawberry|   *_x000D_
Grape     |   *   *   *   *   *_x000D_
Pear      |   *_x000D_
ct        |   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100_x000D_
Item with largest count: Grape_x000D_
_x000D_
Compute and print percentages chart_x000D_
_x000D_
Apple     |   *   *   *   *   *   *   *   *   *   *_x000D_
Banana    |   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *_x000D_
Strawberry|   *   *   *   *   *   *   *   *   *   *_x000D_
Grape     |   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *_x000D_
Pear      |   *   *   *   *   *   *   *   *   *   *_x000D_
ct        |   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100_x000D_
Enter item and value to update the counts: Banana 10_x000D_
Apple     |   *_x000D_
Banana    |   *   *   *   *   *   *   *   *   *   *   *   *_x000D_
Strawberry|   *_x000D_
Grape     |   *   *   *   *   *_x000D_
Pear      |   *_x000D_
ct        |   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100_x000D_
Item with largest count: Banana_x000D_
_x000D_
Do you want to repeat these steps? (0-No/1-Yes): 1_x000D_
Enter the number of items and their names (N item1 item2 ... itemN): 5 Apple Banana Strawberry Grape Pear _x000D_
Reading the items finished. _x000D_
Enter the data for the counts array in format (N count1 count2 ... countN): 5 100 200 100 500 100_x000D_
Reading the counts finished. _x000D_
_x000D_
Apple     |   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *_x000D_
Banana    |   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *_x000D_
Strawberry|   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *_x000D_
Grape     |   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *_x000D_
Pear      |   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *_x000D_
ct        |   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100_x000D_
Item with largest count: Grape_x000D_
_x000D_
Compute and print percentages chart_x000D_
_x000D_
Apple     |   *   *   *   *   *   *   *   *   *   *_x000D_
Banana    |   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *_x000D_
Strawberry|   *   *   *   *   *   *   *   *   *   *_x000D_
Grape     |   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *_x000D_
Pear      |   *   *   *   *   *   *   *   *   *   *_x000D_
ct        |   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100_x000D_
Enter item and value to update the counts: Sage 1_x000D_
_x000D_
   Error. No update will be made. Not found in items: Sage. _x000D_
_x000D_
Apple     |   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *_x000D_
Banana    |   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *_x000D_
Strawberry|   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *_x000D_
Grape     |   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *_x000D_
Pear      |   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *_x000D_
ct        |   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100_x000D_
Item with largest count: Grape_x000D_
_x000D_
Do you want to repeat these steps? (0-No/1-Yes): 1_x000D_
Enter the number of items and their names (N item1 item2 ... itemN): 5 Apple Banana Strawberry Grape Pear _x000D_
Reading the items finished. _x000D_
Enter the data for the counts array in format (N count1 count2 ... countN): 5 1 2 1 5 1_x000D_
Reading the counts finished. _x000D_
_x000D_
Apple     |   *_x000D_
Banana    |   *   *_x000D_
Strawberry|   *_x000D_
Grape     |   *   *   *   *   *_x000D_
Pear      |   *_x000D_
ct        |   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100_x000D_
Item with largest count: Grape_x000D_
_x000D_
Compute and print percentages chart_x000D_
_x000D_
Apple     |   *   *   *   *   *   *   *   *   *   *_x000D_
Banana    |   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *_x000D_
Strawberry|   *   *   *   *   *   *   *   *   *   *_x000D_
Grape     |   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *_x000D_
Pear      |   *   *   *   *   *   *   *   *   *   *_x000D_
ct        |   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100_x000D_
Enter item and value to update the counts: banana 10_x000D_
_x000D_
   Error. No update will be made. Not found in items: banana. _x000D_
_x000D_
Apple     |   *_x000D_
Banana    |   *   *_x000D_
Strawberry|   *_x000D_
Grape     |   *   *   *   *   *_x000D_
Pear      |   *_x000D_
ct        |   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100_x000D_
Item with largest count: Grape_x000D_
_x000D_
Do you want to repeat these steps? (0-No/1-Yes): 1_x000D_
Enter the number of items and their names (N item1 item2 ... itemN): 1 Grape_x000D_
Reading the items finished. _x000D_
Enter the data for the counts array in format (N count1 count2 ... countN): 5 1 2 1 5 1_x000D_
Reading the counts finished. _x000D_
_x000D_
   Error in printHorizChart: arrays do not have the same number of items_x000D_
_x000D_
   Error in itemMaxCount: arrays do not have the same number of items_x000D_
_x000D_
Compute and print percentages chart_x000D_
_x000D_
   Error in printHorizChart: arrays do not have the same number of items_x000D_
_x000D_
Enter item and value to update the counts: Grape 4_x000D_
_x000D_
   Error in UpdateCounts: arrays do not have the same number of items_x000D_
_x000D_
   Error in printHorizChart: arrays do not have the same number of items_x000D_
_x000D_
Do you want to repeat these steps? (0-No/1-Yes): 0_x000D_

Sample run of Extra part (chart printed vertically)

 30|           *                       _x000D_
 29|           *                       _x000D_
 28|           *                       _x000D_
 27|           *                       _x000D_
 26|           *                       _x000D_
 25|           *                       _x000D_
 24|           *                       _x000D_
 23|           *                       _x000D_
 22|           *                       _x000D_
 21|           *                       _x000D_
 20|           *                *      _x000D_
 19|           *                *      _x000D_
 18|           *                *      _x000D_
 17|           *                *      _x000D_
 16|           *                *      _x000D_
 15|           *                *      _x000D_
 14|           *                *      _x000D_
 13|           *                *      _x000D_
 12|           *                *      _x000D_
 11|           *                *      _x000D_
 10|           *                *      _x000D_
  9|           *                *      _x000D_
  8|           *                *      _x000D_
  7|           *                *      _x000D_
  6|           *                *      _x000D_
  5|    *      *                *      _x000D_
  4|    *      *                *    * _x000D_
  3|    *      *          *     *    * _x000D_
  2|    *      *          *     *    * _x000D_
  1|    *      *          *     *    * _x000D_
   |Apple Banana Strawberry Grape Pear

Looking for this or a Similar Assignment? Click below to Place your Order

× How can I help you?