In: Computer Science
All code is done using Java. The steps to the question are as follows (There is more information in the code comments posted below as well):
Remember to run the JUnit tester each time you complete a constructor or method, and to carefully study the result of the tests to help you through the development process.
Code and comments given:
/**
* A class that represents a windowed view of Hounsfield units. A Hounsfield
* window is defined by two values: (1) the window level, and (2) the window
* width. The window level is the Hounsfield unit value that the window is
* centered on. The window width is the range of Hounsfield unit values that the
* window is focused on.
*
* <p>
* A window has a lower and upper bound. The lower bound is defined as the
* window level minus half the window width:
*
* <p>
* lo = level - (width / 2)
*
* <p>
* The upper bound is defined as the window level plus half the window width:
*
* <p>
* hi = level + (width / 2)
*
* <p>
* Hounsfield units are mapped by the window to a real number in the range of
* {@code 0} to {@code 1}. A Hounsfield unit with a value less than lo is mapped
* to the value {@code 0}. A Hounsfield unit with a value greater than hi is
* mapped to the value {@code 1}. A Hounsfield unit with a value v between lo
* and hi is mapped to the value:
*
* <p>
* (v - lo) / width
*
*
*/
public class HounsfieldWindow {
}
public class HounsfieldWindow { private int level, width; public HounsfieldWindow(int level, int width) { this.level = level; this.width = width; } public HounsfieldWindow() { this(0, 400); // Not sure what should be default values. } public int getLevel() { return level; } public int setLevel(int level) { if(level < Hounsfield.MIN_VALUE || level > Hounsfield.MAX_VALUE) { throw new IllegalArgumentException(); } int data = this.level; this.level = level; return data; } public int getWidth() { return width; } public int setWidth(int width) { if(width <= 0) { throw new IllegalArgumentException(); } int data = this.width; this.width = width; return data; } public double getLowerBound() { return level - (width / 2); } public double getUpperBound() { return level + (width / 2); } public double map(Hounsfield f) { int hounsfieldUnitVal = f.get(); System.out.println("got " + hounsfieldUnitVal); if(hounsfieldUnitVal < getLowerBound()) { return 0; } if(hounsfieldUnitVal > getUpperBound()) { return 1; } return (hounsfieldUnitVal - getLowerBound()) / (double)width; } }
************************************************** You have not provided what the method names should be.. please change them if required as per your junit cases. Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.