Problem Statement
Installation programs often run several tasks, one after another. Each task is assigned an integer, the expected execution time of this task. During the installation, a progress bar shows the user what percentage of the installation time has elapsed. In this problem, the bar will be represented by a string containing exactly 20 characters. If X% of the installation has been completed, then the leftmost X% of these characters should be a '#', while the remaining characters should be '.'. If necessary, round down the number of '#' characters to the nearest integer less than or equal to the actual value (see example 0). The bar starts at 0% and is only updated each time a task finishes execution.
Create a class ProgressBar containing the method showProgress which takes a
Definition
- Class:
- ProgressBar
- Method:
- showProgress
- Parameters:
- int[], int
- Returns:
- String
- Method signature:
- String showProgress(int[] taskTimes, int tasksCompleted)
- (be sure your method is public)
Constraints
- taskTimes will contain between 1 and 50 elements, inclusive.
- Each element in taskTimes will be between 1 and 1000, inclusive.
- tasksCompleted will be between 0 and the number of elements in taskTimes, inclusive.
Examples
{19,6,23,17}
3
Returns: "##############......"
This installation consist of 4 tasks, and the expected execution times for these are 19, 6, 23 and 17, respectively. Since the first 3 tasks have been completed, the total execution time for the installation so far has been 19+6+23 = 48 and the total expected time is 19+6+23+17 = 65. Thus 48/65 = 73.84615% of the installation has been completed, so the first 20*0.7384615 = 14.76923 = 14 (round down) characters in the string should be '#', and the remaining 6 should be '.'. Thus the method returns "##############......"
{2,3,7,1,4,3}
4
Returns: "#############......."
The installation has run for 2+3+7+1 = 13 units and the total execution is 2+3+7+1+4+3 = 20.
{553,846,816,203,101,120,161,818,315,772}
4
Returns: "##########.........."
{7,60,468,489,707,499,350,998,1000,716,457,104,597,583,396,862}
2
Returns: "...................."
{419,337,853,513,632,861,336,594,94,367,336,297,966,627,399,433,846,859,80,2}
19
Returns: "###################."
Even though about 99.98% of the installation has been completed, the last character should still be a '.' since we always round down.
{500}
0
Returns: "...................."
{500}
1
Returns: "####################"
{878,766,805,362}
2
Returns: "###########........."
{199,921,25,245,696,596,289,503,139,560,163,929,435,607,882,808,774,968,576,112,509,387,456,85,285,487,453,953,856,221,314,90,536}
9
Returns: "####................"
{408,396}
1
Returns: "##########.........."
{886,457,649,949,630,882,17,209,307,108,867,473,902,841,424,160,621,123,985,36}
16
Returns: "################...."
{87,515,621,634,896,567,265,79,558,577,846,927,471}
0
Returns: "...................."
{377,817,295,239,890,60,424,88,427,68,424,309,8,966,729}
14
Returns: "#################..."
{332,865,914,885,473,63,853,1000,133,497,789,540,22,841,211,336,507,759,614,997,990,568,107,432,937,469,90,813,114,106,987,615,135,336,823,123,708}
4
Returns: "##.................."
{341,810,131,1000,659,974,383,272,734,874,198,392,917,625,767,996,221,644,172,665,382,676,195,86,706,295,489,712,996,968,583,939,40,956,997,521,167,465}
19
Returns: "##########.........."
{130,721,994,883,576,629,615,546,735,726,32,71,970,949,690,128,808,231,262,598,511,786,348,854,981,995,437,86,176,922,117,201,614,426,944,43,927,89,508,988,638,189,423,703,6,782,884,152}
25
Returns: "###########........."
{948,38,627,755,233,264,898,8,787,667,615,553,98,406,72,44,290,763,88,441,162,538,958,950,803,733,975,608,415,921,62,724,408}
17
Returns: "########............"
{553,846,816,503,101,120,161,818,315,772}
9
Returns: "################...."
{602,901,638,93,590,473,669,461,952,778,779,730,946,530,292,983,928,826,887}
19
Returns: "####################"
{649,532,748,318,299,170,577,468,956,439,23,65,500,877,739,729,379,439,745,729,990,915,50,647,980}
24
Returns: "##################.."
{964,550,841,395,685,983,815,276,668,146,261,494,37,776,321,101,815,98}
5
Returns: "#######............."
{812,632,21,744,977,941,494,603,423,4,657,116,429,800,634,812,134,972,301,489}
20
Returns: "####################"
{214,115,50,283,61,430,312,914,108,97,209,732,875,70,653,138,435,959,376,476,311,928,705,476,447,455,533,894,348,496,970,602,627,850,891}
17
Returns: "######.............."
{132,61,119,126,616,860,997,99,549,395,190,332,997,985,226,290,825,166,489,101,252,269,759,747,784,994,228,368,805,888,864,502,973,578,593}
6
Returns: "##.................."
{975,763,761,118,36,253,351,714,308,580,383,554,224,485,737,315,908,271,550,824,833}
19
Returns: "################...."
{127,603,44,620,566,827,103,171,896,873,165,85,594,113,855,504,550,110,299}
3
Returns: "#..................."
{706,165,679,36,704,506,567,727,781,385,683,968,986,792,171,785,512,931,335,875,82,667,21,487,299,207,549,274,515,384}
19
Returns: "##############......"
{1,4,852,451,855,608,519,221,822,44,926,169,485,488,556,950,781,598,821,358,783,218,186,860,269,701,461,626,192,45,924,192,312,798,655,184,395,933,232,790,421,254,684,800,233,161}
33
Returns: "##############......"
{23,309,823,38,812,689,190,761,917,525,753,591,298,551,842,982,400,160,756,976,73,795,419,587,350,367,122,698,725,44,364,676,983,933,219,991,648,282,324}
13
Returns: "######.............."
{571,149,361,508,319,906,935,429,737}
9
Returns: "####################"
{492,824,897,946,836,560,412,925,728,806,900,746,708,152,117,660,314,955,740,495,490,483,766,441,292,493,443,735,144,329,636,139,513,323,522,318,249,347,227,247,609}
21
Returns: "############........"
{695,734,398,544,881,813,140,955,574,480,587,357,359,816,158,517,609,981,898,493,572,435,493,736,53,382,739}
19
Returns: "##############......"
{45,81,216,400,968,40,700,435,604,977,971,368,151,416,875,385,576,319,533,107,744,775,254,515,162,452,458,815,294,202,994,933,37,2,100,923,26}
26
Returns: "##############......"
{924,882,441,255,34,552,105,867,960,328,987,489,873,620,260,338,945,727,244,832,20,322,258,288,123,707,452,73,480,483,311,822,618,680,443,265,261}
29
Returns: "###############....."
{803,428,476,492,319,152,537}
2
Returns: "#######............."
{781,70,642,686,432,294,221,820,185,74,927,871,319,928,149,225,453,903,384,465,412,614,258,37,959,24,231,617,458,406,761,413,901,348,541,447,267,168}
2
Returns: "...................."
{256,193,202,914,899,315,44,876,595,310,576,508,126,193,185,957}
16
Returns: "####################"
{720,92,470,600,78,851,135,352,169,432,638,415,257,356,756,387,621,416,188,801,984,624,82,400,260,558,568,177,534,262,645,642,35,918}
15
Returns: "########............"
{472,729,515,360,297,86,652,695,887,531,574,320,790,592,720,706,929,725,890,349,676,148,450,752,781,736,548,951,314,165,102,741,28,304,994,786,929,429,57,577,871,813,707,242,625,654}
17
Returns: "#######............."
{582,975,822,994,413,602,105,812,361,191,52,803,322,828,769,509,674,673,987,348,420,54,169,655,999,875,3,230,63,546,284,298,743}
32
Returns: "###################."
{453,871,908,420,108,720,430,822,471,279,296,832,638,142,524,192,287,94,844,997,811,253,676,380,874,702,726,126,85,318,587,643,617,695,444,941,574,468}
24
Returns: "############........"
{141,303,80,406,183,128,592,885,254,998,594,465,270,859,533,925,30,863}
10
Returns: "#########..........."
{894,250,342,664,682,670,656,425,459,462,58,404,629,562,123,674,418,858,327,369,790,935,612,781,4,359,942,800,314,995,843,116,365,714,956,330,44,747,317,461,835,718,150,638,538,325,323,370}
7
Returns: "###................."
{401,301,312,12,904,869,499,407,862,64,381,55,288,619,184,748,48,333,718,954,940,668,482,896,595,71,994,862,910,24,463,915,829,359,132,822,120,860,763,299,839,179,479,46,926,501,720,802,585,596}
19
Returns: "######.............."
{647,374,463,411}
3
Returns: "###############....."
{172,250,21,944,235,869,115,665,327,402,222,208,893,295,629,505,580,396,259,338,890,507,553,644,797,58,848,693,348,251,916,628,195,89,92,558,778,735,43,787}
15
Returns: "######.............."
{484,442,388,168,405,475,543,102,93,377,38,300,319,191,731,184,367,517,423,528,634,325,463,570,345,300,208,402,446,795,93,909,166,544,473,63,900,833,776,911,116}
32
Returns: "##############......"
{522,387,680,102,913,702,653,109,2,129,672}
8
Returns: "################...."
{360,686,553,485,689,78,49,764,845,488,832,317,216,747,405,76,29,928,882,399,903,696,878,395,538,189,654,748,875,687,867,948,171,583,464,952,347,343,974,946,465,840,54,981,493,329,858}
22
Returns: "########............"
{405,275,385,592,437,845,398,415,827,986}
4
Returns: "#####..............."
{103,691,764,624,74,410,11,37,441,835,223,937,315,666,89,907,782,263,655,134,657,379,524,18,891,948,989}
19
Returns: "#############......."
{249,678,137,266,787,87,499,713,626,127,870,99,322,88,555,993,857,137,973,224,831,461,502,614,717,692,855,170,883,272,465,123,846,464,38,315,999,34,347,986,913,368,356,416}
21
Returns: "#########..........."
{588,665,826,511,135,268,769,506,355,314,101,515,909,43,640}
7
Returns: "##########.........."
{ 19, 6, 23, 17 }
3
Returns: "##############......"
{ 47, 43 }
1
Returns: "##########.........."
{ 419, 337, 853, 513, 632, 861, 336, 594, 94, 367, 336, 297, 966, 627, 399, 433, 846, 859, 80, 2 }
19
Returns: "###################."