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;...
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; }...
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...
(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...
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...
in java code Modify your program as follows: Ask the user for the number of hours...
in java code Modify your program as follows: Ask the user for the number of hours worked in a week and the number of dependents as input, and then print out the same information as in the initial payroll assignment. Perform input validation to make sure the numbers entered by the user are reasonable (non-negative, not unusually large, etc). Let the calculations repeat for several employees until the user wishes to quit the program. Remember: Use variables or named constants...
How Heapify is done (theory, pseudocode, and examples) the examples used Java code please (in your...
How Heapify is done (theory, pseudocode, and examples) the examples used Java code please (in your own words)
TreeSetDemo IN JAVA PLEASE The following program can be done all in the main method. It...
TreeSetDemo IN JAVA PLEASE The following program can be done all in the main method. It demonstrates that a TreeSet eliminates duplicates and is ordered. Create a Random object with a seed of 5. Create an ArrayList numAL of type Integer Populate numAL with 10 numbers randomly selected from 0 to 6 Print out numAL Create a TreeSet numTS of type Integer Create an Iterator alIter from numAl and use it to add all the elements of numAL in numTS....
Java Problem: Please answer both parts of the question fully: (a). Write Java code for a...
Java Problem: Please answer both parts of the question fully: (a). Write Java code for a method to test if a LinkedList<Long> has Long values that form a Fibonacci sequence from the beginning to the end and return true if it is and false otherwise. A sequence of values is Fibonnaci if every third value is equal to sum of the previous two. Eg., 3,4,7,11,18,29 is a Fibonacci sequence whereas 1,2,3,4 is not, because 2+3 is not equal to 4....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT