Question

In: Computer Science

The question is as follows with all of the requirements commented in. /** * A class...

The question is as follows with all of the requirements commented in.

/**

* A class that represents a Hounsfield unit. Hounsfield units are the units of

* measurement used in computed tomography (CT or CAT) scanning.

*

* <p>

* The Hounsfield scale is defined by specifying the radiodensity of air as

* {@code -1000} Hounsfield units and the radiodensity of distilled water as

* {@code 0} Hounsfield units. Adjacent tissues in the human body can be

* distinguished from one another if their radiodensities differ; see

* <a href="https://en.wikipedia.org/wiki/Hounsfield_scale">the Wikipedia

* page</a> for a table of typical Hounsfield values for tissues of the

* human body.

*

* <p>

* CT scanners for medical purposes typically restrict the value of reported

* Hounsfield units to integers in the range {@code -1024} to {@code 3071} so

* that a Hounsfield unit can be encoded as a 12-bit value. This class uses

* the values {@code -1024} and {@code 3071} to represent the minimum and

* maximum, respectively, allowable Hounsfield unit values.

*

*/

public class Hounsfield {

/**

* The integer value of this Hounsfield unit

*/

private int value;

/**

* The minimum Hounsfield unit reported by medical CT scanners

* Look up the correct value in the documentation

*/

public static final int MIN_VALUE = 0;

/**

* The maximum Hounsfield unit reported by medical CT scanners

* Look up the correct value in the documentation

*/

public static final int MAX_VALUE = 0;

/**

* Initializes this Hounsfield unit to have a value of zero.

*/

public Hounsfield() {

// A constructor should assign every non-static field a value.

// Change the next line to assign the correct value to this.value

// or use constructor chaining.

//

// Implement the get method before trying to run the JUnit test.

// If you used constructor chaining you will also have to implement

// the next constructor before running the JUnit test.

this.value = -1000;

}

/**

* Initializes this Hounsfield unit to have the specified value.

*

* @param value

* the value of this Hounsfield unit

* @throws IllegalArgumentException

* if {@code value} is less than the minimum Hounsfield unit

* reported by medical CT scanners or greater than the maximum

* Hounsfield unit reported by medical CT scanners

*/

public Hounsfield(int value) {

// If you implement the set method first, you can simply call set

// from within this constructor to implement the constructor.

//

// Alternatively, implement the checkValue method first and call

// it from within this constructor to perform the necessary

// input validation, and then assign the appropriate value to this.value

}

/**

* Initializes this Hounsfield unit by copying the value from the specified

* other Hounsfield unit.

*

* @param other

* the Hounsfield unit to copy the value from

*/

public Hounsfield(Hounsfield other) {

// Assign a value to this.value by copying other.value

}

/**

* Throws an {@code IllegalArgumentException} if the specified value is less

* than the minimum Hounsfield unit reported by medical CT scanners or

* greater than the maximum Hounsfield unit reported by medical CT scanners.

*

* @param value

* a value to check

* @throws IllegalArgumentException

* if the specified value is less than the minimum Hounsfield

* unit reported by medical CT scanners or greater than the

* maximum Hounsfield unit reported by medical CT scanners.

*/

private static void checkValue(int value) {

// This method is useful for implementing the input validation

// needed in the constructor and in the method set

}

/**

* Returns the value of this Hounsfield unit.

*

* @return the value of this Hounsfield unit

*/

public int get() {

// Change the next line to return the value of this.value

return -1;

}

/**

* Sets the value of this Hounsfield unit to the specified value returning

* the value that was overwritten.

*

* @param value

* the value to set this Hounsfield unit to

* @return the overwritten value of this Hounsfield unit

* @throws IllegalArgumentException

* if the specified value is less than the minimum Hounsfield

* unit reported by medical CT scanners or greater than the

* maximum Hounsfield unit reported by medical CT scanners.

*/

public int set(int value) {

// Call checkValue on the first line to perform input validation

return 0;

}

/**

* Returns a string representation of this Hounsfield unit. The returned

* string is the numeric value of this Hounsfield unit (formatted as an

* integer) followed by a space followed by the string {@code "HU"}.

*/

@Override

public String toString() {

// Change the next line to return the approriate string

return "";

}

}

Solutions

Expert Solution

Hounsfield.java

public class Hounsfield {
private int value;
private static final int MIN_VALUE = -1024;
private static final int MAX_VALUE = 3071;
  
public Hounsfield()
{
this.value = 0;
}
  
public Hounsfield(int value)
{
checkValue(value);
this.value = value;
}
  
public Hounsfield(Hounsfield other)
{
checkValue(other.get());
this.value = other.get();
}
  
private void checkValue(int value)
{
if(value < MIN_VALUE || value > MAX_VALUE)
throw new IllegalArgumentException(this.getClass().getSimpleName() + "Value should be between " + MIN_VALUE + " and " + MAX_VALUE);
}
  
public int get()
{
return this.value;
}
  
public int set(int value)
{
int previous = this.value;
checkValue(value);
this.value = value;
return previous;
}
  
@Override
public String toString()
{
return (this.value + " HU");
}
}

HounsfieldTester.java (Driver class)

public class HounsfieldTester {
  
public static void main(String[] args)
{
try
{
// using 1st constructor
Hounsfield hf1 = new Hounsfield();
hf1.set(590);

// using 2nd constructor
Hounsfield hf2 = new Hounsfield(3000);

//using 3rd constructor
Hounsfield hf3 = new Hounsfield(hf1);
  
// displaying all the 3 objects using their respective toString() methods
System.out.println("Object 1: " + hf1.toString());
System.out.println("Object 2: " + hf2.toString());
System.out.println("Object 3: " + hf3.toString());
  
}catch(IllegalArgumentException iae){
System.out.println(iae.getMessage());
}
}
}

*************************************************************** SCREENSHOT ************************************************************


Related Solutions

All Tasks are commented in the code: public class MandelbrotUtil { private MandelbrotUtil() { } /**...
All Tasks are commented in the code: public class MandelbrotUtil { private MandelbrotUtil() { } /** * Return the number of iterations needed to determine if z(n + 1) = z(n) * z(n) + c * remains bounded where z(0) = 0 + 0i. z(n + 1) is bounded if its magnitude * is less than or equal to 2. Returns 1 if the magnitude of c * is greater than 2. Returns max if the magnitude * of z(n...
Question #1 The commented codes in the Driver class are either causing a syntax error or...
Question #1 The commented codes in the Driver class are either causing a syntax error or run time error. Make sure to identify the error yourself without running it. predict the output once you fix all the errors. un-comment one line at a time identify the error fix just that line, You are not allowed to change any declarations of the objects. if it is a runtime error explain the error compile the code. move to the next error Make...
Question 1: What are the requirements when choosing an identifier for a C# class? Question 2:...
Question 1: What are the requirements when choosing an identifier for a C# class? Question 2: What are the types of comments supported by C#?
this is my matlab code for class, my professor commented "why is the eps an input...
this is my matlab code for class, my professor commented "why is the eps an input when it is set inside the function and not specified as a variable? how do i fix? function[] = () %Declare Global Variables global KS; global KC; KC = 0; KS = 0; End = 0; while (End == 0) choice = questdlg('Choose a function', ... 'Fuction Menu', ... 'A','B','B'); switch choice; case 'A' Program = 'Start'; while strcmp(Program,'Start'); Choice = menu('Enter the Trigonometric...
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): 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. Once you have added the fields to your class, implement the methods getLevel and getWidth....
Explain the 7 requirements for a Asset Class
Explain the 7 requirements for a Asset Class
The Common Requirements Of All Questions Are The Same. Read Each Question Carefully And Submit ......
The Common Requirements Of All Questions Are The Same. Read Each Question Carefully And Submit ... Question: The common requirements of all questions are the same. Read each question carefully and submit a ... The common requirements of all questions are the same. Read each question carefully and submit a query to fulfill for each question. Also, students need to submit the result of the corresponding query under the query. The query result should be copied and pasted as it...
this is a question for marketing class, i need to know out of all of the...
this is a question for marketing class, i need to know out of all of the 2020 year Toyota vehicles, which trims have navigation for which models? for ex the Toyota Tundra Platinum and higher has navigation, and etc.
Create a class that generates permutations of a set of symbols. Requirements The class must be...
Create a class that generates permutations of a set of symbols. Requirements The class must be named PermutationGenerator. The PermutationGenerator class has two methods as follows. hasNext This method has no parameters.  It returns true if at least one permutation remains to be generated. next This method has no parameters.  It returns an array of the symbols (char[]) in a permutation (if any remain) or null otherwise. The following main method MUST be used, with NO CHANGES to test your class. public static void main(String[] args) { int count = 0; PermutationGenerator pg...
Question 3 Someone once commented that advertising is America’s greatest export. Discuss. Question 8 How can...
Question 3 Someone once commented that advertising is America’s greatest export. Discuss. Question 8 How can advertisers overcome the problems of low literacy in their markets? Question 18 Take each of the steps in the communications process and give an example of how culture differences can affect the final message received.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT