Question

In: Computer Science

All code is done using Java. The steps to the question are as follows (There is...

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):

  1. Begin by deciding how many fields are required and what their types should be. Add these fields to your class (making sure that they each have a private access modifier) giving them a sensible name when you do so.
  2. Once you have added the fields to your class, implement the methods getLevel and getWidth. The JUnit tester requires these methods to test the constructors and other methods.
  3. Implement the constructor HounsfieldWindow(int level, int width) first. Make sure that it has the correct access modifier and signature.
  4. Implement the no-argument constructor HounsfieldWindow() next. Use constructor chaining to implement this constructor.
  5. Implement the remaining methods making sure that they each have the correct access modifier, signature, and return type.

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 {

}

Solutions

Expert Solution

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.


Related Solutions

Question(Design Java Method). There is a java code what created a "Student" class and hold all...
Question(Design Java Method). There is a java code what created a "Student" class and hold all the books owned by the student in the inner class "Book". Please propose a new method for the Student class so that given a Student object "student", a program can find out the title of a book for which student.hasBook(isbn) returns true. Show the method code and the calls to it from a test program. The Student class is following: import java.lang.Integer; import java.util.ArrayList;...
Using Java, write code as follows: Create an interface called Items. It should define at least...
Using Java, write code as follows: Create an interface called Items. It should define at least the following methods: public void add( Object item ) - adds a single object to the collection. public Object get( int index ) - returns an item at a specific index. public int size() - returns the number of items stored in the collection. public void addAll( Object[] items ) - adds all of the elements in the array to the collection. Write a...
Perform all the steps for ALL PARTS (a - d) in R code and show and...
Perform all the steps for ALL PARTS (a - d) in R code and show and explain the results. Thank you. Problem 2.23 Consider the simple linear regression model y = 50 + 10x + E where E is NID(0,16). Suppose that the n = 20 pairs of observations are used to fit this model. Generate 500 samples of 20 observations, drawing one observation for each level of x = 0.5,1, 1.5, 2, ..., 10 [i.e. going up by an...
This is an entry to Java Question. Please answer with Pseudocode and Java code for better...
This is an entry to Java Question. Please answer with Pseudocode and Java code for better understanding. We are mainly using basic in and out declarations and are focusing on API for method invocations. Any help would be very appreciated :) Problem 7: Distance (10 points) Use API (Data Science) Data Science is an emergent field from Computer Science with applications in almost every domain including finances, medical research, entertainment, retail, advertising, and insurance. The role of a data analyst...
java code Question 4: Iterating with loops You can process the list using a For loop....
java code Question 4: Iterating with loops You can process the list using a For loop. The variable in the For loop becomes the index value for each of the items in the loop. Everything you do to an element inside the loop gets done for the entire list. Examine the following loops. Then use what you know to write the following loops. int[] numbers = new int[100]; for(int i = 0; i < numbers.length; i++){ numbers[i] = i; }...
(must be done in JAVA code) A company dedicated to parking management has decided to renew...
(must be done in JAVA code) A company dedicated to parking management has decided to renew itself by automating its control process since this process is done manually. The company has hired its development team to automate the process and gave it an October 19th deadline until 6 pm. An analyst defined the system requirements as follows: 1. The system must allow configuring the number of spaces that a vehicle parking lot will contain. 2. The system must allow the...
How Heapify is done (theory, pseudocode, and examples) the examples used Java code please
How Heapify is done (theory, pseudocode, and examples) the examples used Java code please
This is an intro to java question. Please post with pseudocode and java code. Problem should...
This is an intro to java question. Please post with pseudocode and java code. Problem should be completed using repetition statements like while and selection statements. Geometry (10 points) Make API (API design) Java is an extensible language, which means you can expand the programming language with new functionality by adding new classes. You are tasked to implement a Geometry class for Java that includes the following API (Application Programming Interface): Geometry Method API: Modifier and Type Method and Description...
This question need to be solved using java coading :- I. Input All input data are...
This question need to be solved using java coading :- I. Input All input data are from a file "in.dat". The file contains a sequence of infix form expressions, one per line. The character '$' is an end mark. For example, the following file has four infix form expressions: 1 + 2 * 3 ^ ! ( 4 == 5 ) $ 3 * ( 6 - 4 * 5 + 1) + 2 ^ 2 ^ 3 $ 77...
This question need to be solved using java coading :- I. Input All input data are...
This question need to be solved using java coading :- I. Input All input data are from a file "in.dat". The file contains a sequence of infix form expressions, one per line. The character '$' is an end mark. For example, the following file has four infix form expressions: 1 + 2 * 3 ^ ! ( 4 == 5 ) $ 3 * ( 6 - 4 * 5 + 1) + 2 ^ 2 ^ 3 $ 77...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT