Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA program. I\'ve highlighted the instructions public class Histogram { /* Enu

ID: 3911925 • Letter: J

Question

JAVA program. I've highlighted the instructions

public class Histogram {
/* Enum representing the available histrogram bars. */
enum Bar { A, B, C, D, F }
  
char barASymbol = 'a';
char barBSymbol = 'b';
char barCSymbol = 'c';
char barDSymbol = 'd';
char barFSymbol = 'f';
  
int barAHeight;
int barBHeight;
int barCHeight;
int barDHeight;
int barFHeight;
  
public Histogram() {
/* TODO (1):
* Assign the values 2,3,5,2,1 directly, to the bar heights a-f respectively.
*/

int barAHeight = 2;
int barBHeight = 3;
int barCHeight = 5;
int barDHeight = 2;
int barFHeight = 1;
  
  
  
}// end Histogram()
  
public Histogram(int barAHeight,
int barBHeight,
int barCHeight,
int barDHeight,
int barFHeight) {
/* TODO (2):
* Initialize bar heights directly, with parameter values.
*/

this.barAHeight = barAheight;
this.barBHeight = barBheight;
this.barCHeight = barCheight;
this.barDHeight = barDheight;
this.barFHeight = barFheight;
  
  
  
}// end Histogram()

public String barHistogram(boolean withLabel) {
/* TODO (3):
* Return a string representing the entire histogram.
* If withLabel is true, then add the bar height to the end
* of each bar, e.g. aaa: 3
*/

  
  
  
  
  
}// end barHistogram()
  
public String barFor(Bar bar) {
/* TODO (4):
* Return a string representing the bar height for the specified bar.
* Call the method createBar() to create the string bar.
*/

  
  
  
  
}// end barFor()
  
public String createBar(char barSymbol, int barHeight) {
/* TODO (5):
* Return a string representing the bar height for the specified bar.
*/

  
  
  
  
}// end createBar()

}// end Histogram

Explanation / Answer


Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you

public class Histogram {
/* Enum representing the available histrogram bars. */
enum Bar { A, B, C, D, F }

char barASymbol = 'a';
char barBSymbol = 'b';
char barCSymbol = 'c';
char barDSymbol = 'd';
char barFSymbol = 'f';

int barAHeight;
int barBHeight;
int barCHeight;
int barDHeight;
int barFHeight;

public Histogram() {
/* TODO (1):
* Assign the values 2,3,5,2,1 directly, to the bar heights a-f respectively.
*/
barAHeight = 2;
barBHeight = 3;
barCHeight = 5;
barDHeight = 2;
barFHeight = 1;

}// end Histogram()

public Histogram(int barAHeight,
int barBHeight,
int barCHeight,
int barDHeight,
int barFHeight) {
/* TODO (2):
* Initialize bar heights directly, with parameter values.
*/
this.barAHeight = barAHeight;
this.barBHeight = barBHeight;
this.barCHeight = barCHeight;
this.barDHeight = barDHeight;
this.barFHeight = barFHeight;

}// end Histogram()

public String barHistogram(boolean withLabel) {
/* TODO (3):
* Return a string representing the entire histogram.
* If withLabel is true, then add the bar height to the end
* of each bar, e.g. aaa: 3
*/

String s = "";
s += barFor(Bar.A);
if(withLabel)
s += ": " + barAHeight;
s += " ";

s += barFor(Bar.B);
if(withLabel)
s += ": " + barBHeight;
s += " ";


s += barFor(Bar.C);
if(withLabel)
s += ": " + barCHeight;
s += " ";

s += barFor(Bar.D);
if(withLabel)
s += ": " + barDHeight;
s += " ";

s += barFor(Bar.F);
if(withLabel)
s += ": " + barFHeight;
s += " ";

return s;


}// end barHistogram()

public String barFor(Bar bar) {
/* TODO (4):
* Return a string representing the bar height for the specified bar.
* Call the method createBar() to create the string bar.
*/
switch(bar){
case A:
return createBar(barASymbol, barAHeight);
case B:
return createBar(barBSymbol, barBHeight);
case C:
return createBar(barCSymbol, barCHeight);
case D:
return createBar(barDSymbol, barDHeight);
case F:
return createBar(barFSymbol, barFHeight);
default:
return "";
}

}// end barFor()

public String createBar(char barSymbol, int barHeight) {
/* TODO (5):
* Return a string representing the bar height for the specified bar.
*/
String s = "";
for(int i = 1; i <= barHeight; i++)
s += barSymbol;

return s;

}// end createBar()

}// end Histogram