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...
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...
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...
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...
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.
As part of their class requirements, the students in Dr. Taylor’s Research Design and Analysis class...
As part of their class requirements, the students in Dr. Taylor’s Research Design and Analysis class are sent over to Trumbull Mall to observe interactions between mothers and their toddler-aged children. They are told not to interact with the moms at all, but just record certain behaviors, like the number of times they speak harshly to their children and the number of times the children whine or cry. One of the mothers notices that the students are watching people and...
Question For Managerial accounting class: All the information is below A is a retail company that...
Question For Managerial accounting class: All the information is below A is a retail company that sells shoes. Data concerning the company’s monthly revenues and costs appear below (Q  refers to the number of pairs of shoes sold): Formula Revenue $70 Q Expenses: Cost of merchandises $30 Q Wages and salaries $130,000 Utilities $12,000 + $2Q Miscellaneous $5000 + $3 Q 1. Prepare the company’s planning budget assuming that 30,000 pairs of shoes are expected to be sold. (1pt) 2. Assume...
Create a class named GameCharacter to define an object as follows: The class should contain class...
Create a class named GameCharacter to define an object as follows: The class should contain class variables for charName (a string to store the character's name), charType (a string to store the character's type), charHealth (an int to store the character's health rating), and charScore (an int to store the character's current score). Provide a constructor with parameters for the name, type, health and score and include code to assign the received values to the four class variables. Provide a...
This all counts as 1 question in class because it's supposed to be already known. So...
This all counts as 1 question in class because it's supposed to be already known. So please answer all of them. I just want to be sure I'm right. Question 1 Which of the following statements are true regarding momentum? Check all that apply. The total momentum of an isolated system is conserved, but internal forces can change the total momentum of the system pinitial = (m1v1)i + (m2v2)i + (m3v3)i + … pfinal = (m1v1)f + (m2v2)f + (m3v3)f...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT