Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 1 (100 pts) Objectives: writing a complex program that includes: reading and printing data, computing new data, updating existing data, error checking. Practice modularization

Task 1 (100 pts) 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 read 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 | * Banana| * * Grape | * * * Pear | * ct | 1 2 3 .... 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 | * Banana| * * * * Grape | * * * * Pear | * 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 printHorizChart(int[] counts, String[] items) - prints a vertical chart ---------------Sample run (this is a single run of the program) Enter the number of items and their names (N item1 item2 ... itemN): 5 Apple Banana Strawberry Grape Pear Reading the items finished. Enter the data for the counts array in format (N count1 count2 ... countN): 5 1 2 1 5 1 Reading the counts finished. Apple | * Banana | * * Strawberry| * Grape | * * * * * Pear | * 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 Item with largest count: Grape Compute and print percentages chart Apple | * * * * * * * * * * Banana | * * * * * * * * * * * * * * * * * * * * Strawberry| * * * * * * * * * * Grape | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Pear | * * * * * * * * * * 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 Enter item and value to update the counts: Banana 10 Apple | * Banana | * * * * * * * * * * * * Strawberry| * Grape | * * * * * Pear | * 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 Item with largest count: Banana Do you want to repeat these steps? (0-No/1-Yes): 1 Enter the number of items and their names (N item1 item2 ... itemN): 5 Apple Banana Strawberry Grape Pear Reading the items finished. Enter the data for the counts array in format (N count1 count2 ... countN): 5 100 200 100 500 100 Reading the counts finished. Apple | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Banana | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Strawberry| * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Grape | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Pear | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 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 Item with largest count: Grape Compute and print percentages chart Apple | * * * * * * * * * * Banana | * * * * * * * * * * * * * * * * * * * * Strawberry| * * * * * * * * * * Grape | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Pear | * * * * * * * * * * 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 Enter item and value to update the counts: Sage 1 Error. No update will be made. Not found in items: Sage. Apple | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Banana | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Strawberry| * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Grape | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Pear | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 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 Item with largest count: Grape Do you want to repeat these steps? (0-No/1-Yes): 1 Enter the number of items and their names (N item1 item2 ... itemN): 5 Apple Banana Strawberry Grape Pear Reading the items finished. Enter the data for the counts array in format (N count1 count2 ... countN): 5 1 2 1 5 1 Reading the counts finished. Apple | * Banana | * * Strawberry| * Grape | * * * * * Pear | * 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 Item with largest count: Grape Compute and print percentages chart Apple | * * * * * * * * * * Banana | * * * * * * * * * * * * * * * * * * * * Strawberry| * * * * * * * * * * Grape | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Pear | * * * * * * * * * * 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 Enter item and value to update the counts: banana 10 Error. No update will be made. Not found in items: banana. Apple | * Banana | * * Strawberry| * Grape | * * * * * Pear | * 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 Item with largest count: Grape Do you want to repeat these steps? (0-No/1-Yes): 1 Enter the number of items and their names (N item1 item2 ... itemN): 1 Grape Reading the items finished. Enter the data for the counts array in format (N count1 count2 ... countN): 5 1 2 1 5 1 Reading the counts finished. Error in printHorizChart: arrays do not have the same number of items Error in itemMaxCount: arrays do not have the same number of items Compute and print percentages chart Error in printHorizChart: arrays do not have the same number of items Enter item and value to update the counts: Grape 4 Error in UpdateCounts: arrays do not have the same number of items Error in printHorizChart: arrays do not have the same number of items Do you want to repeat these steps? (0-No/1-Yes): 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Describe how to prevent and treat choking.

Answered: 1 week ago