Lab 2
∑={0,1} L = {w : if |w| is odd w begins with 11}.
List the indistinguishability classes for L(M). Include the following information for each class c, where wc is a string in c:
• A short description or characteristic function that describes the strings in c.
• Whether wc is or is not in L(M).
• ∀z(wcz ∈ L(M) iff … ). This rule must be different for each equivalence class — that is what makes them different classes.
• The class transitions for each symbol in Σ: wca ∈ [na] and Σ: wcb ∈ [nb], where na and nb are the numbers of equivalence classes.
In: Computer Science
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while loop to take in user's name and desired destination for as long as there are user inputs. Prompt user to input yes to continue and no to quit. Prompt for user's name. Receive the name into the program and save it as the value of name variable. Prompt user for their desired vacation destination. Receive response and save it as the value of a response variable. Send the name and response to your response dictionary as key-value pair. Once all inputs are in the program, print each poll participant's name and desired vacation destination. Use for loop to run through all key-pairs in the dictionary. Pay attention to your output. Print the dictionary to show the key-value pairs. Test program with 3 - 5 key value pairs.
In: Computer Science
Use Java GUI to write a chessboard
8 Queens Problem
Write a program that can place 8 queens in such a manner on an 8 x 8 chessboard that no queens attack each other by being in the same row, column or diagonal.
In: Computer Science
Please use java language in an easy way with comments!
Expand your below program, so it can include cursed items (weapons that break, armor that causes more damage when worn). In order to do that, write an interface called "CursedItem". Then create subclasses of the armor, and weapon class that implement the CursedItem interface :
CursedWeapon: using a random number generator, there is a 4 in 10 chance that the weapon breaks during combat.
CursedArmor: this item amplifies the damage taken in battle instead of reducing it.
The interface only needs to have one method. In your driver class, create an example object for each of the new classes.
-----------------------------------------------------------------------------------------------------------
//Java code
public class GameItem {
protected String itemName; //Name of the item
//constructor
public GameItem(String itemName) {
this.itemName = itemName;
}
//use()
public void use();
}
//======================================
/**
* Weapon class that extends the GameItem class
*/
public class Weapon extends GameItem {
private int damage;
//constructor
public Weapon(String itemName, int damage) {
super(itemName);
this.damage = damage;
}
public void use() {
System.out.println("You now wield "+itemName+". This weapon does "+damage+" points of damage with each hit.");
}
}
//==========================================
/**
* Armor class that extends the GameItem class
*/
public class Armor extends GameItem{
private double protection;
public Armor(String itemName, double protection) {
super(itemName);
this.protection = protection;
}
@Override
public void use() {
System.out.println("You have equipped "+itemName+". This item reduces the damage you take in combat by "+protection+" percent.");
}
}
//=====================================
import java.util.ArrayList;
public class GameItemTest {
public static void main(String[] args)
{
ArrayList<GameItem> inventory = new ArrayList<>();
inventory.add(new Weapon("Sword",50));
inventory.add(new Armor("Shield",85.9));
for (GameItem g:inventory ) {
g.use();
}
}
}In: Computer Science
Solving Problems Using Recursion (Python):
To solve the problem, you have to use recursion and cannot use for or while loops to solve the problems as well as not using global variables.
1. Create a function that takes a positive integer and returns it with neighboring digits removed. Do not convert the integer to a list.
Ex.
Input = [5555537777721]
Output = [53721]
In: Computer Science
determine the impulse response and the step response of the following causal systems plot the pole-zero patterns and determine which are stable
y(n) = 3/4y(n - 1)- 1/8y(n - 2) + x(n)
In: Computer Science
Write a tester program to test the mobile class defined below.
Create the class named with your id (for example: Id12345678) with the main method.
Your answer should include a screenshot of the output. Otherwise, you will be marked zero for this question.
public class Mobile {
private int id;
private String brand;
public Mobile() {
id = 0;
brand = "";
}
public Mobile(int n, String name) {
id = n;
brand = name;
}
public void setBrand(String w) {
brand = w;
}
public void setId(int w) {
id = w;
}
Public int getId() {
In: Computer Science
In: Computer Science
Java program by using array only.
II. The NumberTile Game (Unchanged)
The right side of each tile (except the last) = the left side of the next tile on the board
III. Specifications
NumberTile.java
import java.util.ArrayList ;
import java.util.Random;
// A NumberTile is a square tile with a number from 1 to 9 on each side
public class NumberTile
{
private ArrayList tile ; // the 4-sided tile
private static final Random gen = new Random() ;
// Create a NumberTile object with 4 random ints in the range 1 to 9
public NumberTile()
{
// TO DO: Code the body of this method
}
// Rotate this NumberTile 90 degrees
public void rotate()
{
// TO DO: Code the body of this method
}
// Return the number on the left side of this NumberTile
public int getLeft()
{
// Do NOT modify this method
return tile.get(0) ;
}
// Return the number on the right side of this NumberTile
public int getRight()
{
// Do NOT modify this method
return tile.get(2) ;
}
// Return this NumberTile as a multiline string in the form:
// 9
// 3 7
// 6
//
public String toString()
{
// TO DO: Code the body of this method
// temporary return statement so program skeleton will compile and run
return null ;
}
} // end of NumberTile class
Hand.java
import java.util.ArrayList;
// A player's hand of NumberTiles
public class Hand
{
private ArrayList hand ;
private final static int INITIAL_SIZE = 5 ; // starting hand size
// Creates a new hand of INITIAL_SIZE NumberTiles
public Hand()
{
// TO DO: Code the body of this method
}
// Get the NumberTile at the specified index in this Hand
public NumberTile get(int index)
{
// TO DO: Code the body of this method
// temporary return statement so program skeleton will compile and run
return null ;
}
// Get the number of tiles in this Hand
public int getSize()
{
// TO DO: Code the body of this method
// temporary return statement so program skeleton will compile and run
return -999 ;
}
// Add a new NumberTile to this Hand
public void addTile()
{
// TO DO: Code the body of this method
}
// Remove the NumberTile at the specified index from this Hand
public void removeTile(int index)
{
// TO DO: Code the body of this method
}
// Is this hand empty?
public boolean isEmpty()
{
// TO DO: Code the body of this method
// temporary return statement so program skeleton will compile and run
return false ;
}
// Return this Hand as a multiline String.
// If this Hand is empty, return an appropriate message
public String toString()
{
// TO DO: Code the body of this method
// temporary return statement so program skeleton will compile and run
return "The hand" ;
}
}
Board.java
import java.util.ArrayList;
// The board for the NumberTile game
public class Board
{
private ArrayList board ; // the board for a NumberTile game
// Creates a new Board containing a single NumberTile
public Board()
{
// TO DO: Code the body of this method
}
// Return the NumberTile at the specified index on this Board
public NumberTile getTile (int index)
{
// TO DO: Code the body of this method
// temporary return statement so program skeleton will compile and run
return null ;
}
// Return the current number of tiles on this Board
public int getSize()
{
// TO DO: Code the body of this method
// temporary return statement so program skeleton will compile and run
return -999 ;
}
// Insert a new tile into this Board at the specified index
public void addTile(int index, NumberTile tile)
{
// TO DO: Code the body of this method
}
// Return a multiline string containing all the tiles on this Board
public String toString()
{
// TO DO: Code the body of this method
// temporary return statement so program skeleton will compile and run
return "The board" ;
}
}
TileGame.java
// Implements a domino-like game where two players, both of whom are
// the computer, take turns inserting NumberTiles into a Board
public class TileGame
{
// instance vars
private Board board ; // the game board
private Hand hand1 ; // Player 1 hand
private Hand hand2 ; // Player 2 hand
private String winner ; // the winner - player1, player2,
// or a tie game
// Creates a new TileGame with two initial hands and a board
public TileGame(Hand firstHand, Hand secondHand)
{
// TO DO: Code the body of this method
}
// Players take turn moving until one or both hand are empty
public void play()
{
// TO DO: Code the body of this method
}
// Utility method called by method makeMove. Returns the index at which a
// new tile will be inserted into the board, or -1 if the tile cannot
// be inserted. The new tile may be inserted either (1) between two
// existing tiles, (2) as the new first tile, or (3) as the new last tile
private int getIndexForFit(NumberTile tile)
{
// TO DO: Code the body of this method
// temporary return statement so program skeleton will compile and run
return -1 ;
}
// Utility method called by method play(). Checks consecutive tiles in the
// hand - by calling method getIndexForFit() - to see if one can be inserted
// into the board. When the first tile that fits is found, removes it from
// the hand, inserts it into the board, and the move ends. The tile may be
// rotated up to 3 times. If none of the tiles fit, adds a new, random tile
// to the hand
private void makeMove(Hand hand)
{
// TO DO: Code the body of this method
}
// Return results of the game as a humongous multi-line String containing
// the final board, both both player's final hands, and the winner
public String getResults()
{
// TO DO: Code the body of this method
// HINT: call toString for the board and for each hand and don't
// forget the winner
// temporary return statement so program skeleton will compile and run
return "Results" ;
}
} // end of TileGame2 class
TileGameTester.java
// A test class for the NumberTile Game
public class TileGameTester
{
public static void main(String[] args)
{
// TO DO: Code the body of this method
}
}
Basically, we will have 5 tiles on our hands. If tiles contain a number of the left/right number on board. We can place it on board.
Board:
5
4 6
2
so that we need to have 4/6 on our hand. if so, we can rotate the number for that tile and put it out.
4 2
2 5 ==> 6 4
6 5
TO board:
2
6 4
5
5
4 6
2
Starting a new game...
***** Player 1 Initial Hand *****
7
5 7
6
4
1 1
9
2
2 6
2
9
7 7
1
9
6 5
3
***** Player 2 Initial Hand *****
7
6 2
1
8
2 8
3
9
2 4
2
1
9 6
3
9
2 3
1
***** The Initial Board *****
5
3 4
1
***** The Final Board *****
8
8 3
2
5
3 4
1
1
4 9
1
7
9 1
7
6
1 7
2
6
7 5
7
3
5 6
9
2
6 2
2
2
2 9
4
In: Computer Science
Given an array of positive integers except one negative integer. Develop a divide-conquer algorithm to find the index of the negative integer, and compute its average complexity.
Please provide a solution in Java
In: Computer Science
Decimal value data types such as float and double represent the
decimal number as an approximation. In other words, float or double
arithmetic do not give exact answer but near approximation to the
answer. As an example, run the following program and check its
result:
#include <iostream>
using namespace std;
int main()
{
float x= 0.1 * 7;
if (x == 0.7)
cout<< "TRUE. \n";
else
cout<< "FALSE. \n";
return 0;
}
In some situations, we need our programs to give exact solutions
instead of near to exact answers. Some programming languages
provide a special data type called Decimal that represents decimal
numbers without the use of approximation. Write a program in C++
that implements the Decimal data type using a class called
BigDecimal. This class will allow users to create decimal values
and perform several operations on these values. The class should
use two member variables:
- the integer part saved as a string
- the decimal part saved as a string
For example, the following instance BigDecimal d("6.45678"); will
store "6" in the first variable and "45678" in the second
variable
The class should have the following functionalities:
Member Function Description
BigDecimal() The default constructor. Creates the number 0.0
BigDecimal(string) A constructor that accepts a string representing
the numeric value with the decimal point.
== operator Accepts two BigDecimal values and compares their
values. If the two decimal values are equal then the method should
return true otherwise it should return false.
!= operator Accepts two BigDecimal values and compares their
values. If the two decimal values are equal then the method should
return false otherwise it should return true.
++ operator (prefix) This operator should increment the integer
part of BigDecimal object by one. The overloaded ++ operator should
return the contents of the object (using this pointer) after it is
incremented.
++ operator (postfix) This operator should increment the integer
part of BigDecimal object by one. The overloaded ++ operator should
return the contents of the object before it is incremented.
<< operator Displays the numeric value of BigDecimal to the
standard output.
>> operator Reads a string value from the standard input and
stores it in the BigDecimal object.
double toDouble() Converts the BigDecimal value to a double.
You can assume that all the values of BigDecimal are nonnegative.
Here is an example of how BigDecimal can be used:
BigDecimal x("45.67");
BigDecimal y("2.5");
//Should print 2.5
cout << x++ << endl;
//Should print 4.5
cout << ++x << endl;
//Should print false
cout << x==y << endl;
In: Computer Science
How can user error be controlled? Is it unavoidable?
In: Computer Science
I am coding in MySQL and two of my tables are populating find but the other two "Employee" and "Assignment" won't. I keep getting an error code saying I can't alter a child table and I can't figure out what to fix. Here is my code:
CREATE TABLE DEPARTMENT (
DepartmentName Char(35) NOT NULL,
BudgetCode Char(30) NOT NULL,
OfficeNumber Char(15) Not Null,
DepartmentPhone Char(12) NOT NULL,
CONSTRAINT DEPARTMENT_PK primary key(DepartmentName)
);
CREATE TABLE EMPLOYEE(
EmployeeNumber Int NOT NULL AUTO_INCREMENT,
FirstName Char(25) NOT NULL,
LastName Char(25) NOT NULL,
Department Char(35) NOT NULL DEFAULT 'Human Resources',
Position Char(35) NULL,
Supervisor Int NULL,
OfficePhone Char(12) NULL,
EmailAddress VarChar(100) NOT NULL UNIQUE,
CONSTRAINT EMPLOYEE_PK PRIMARY KEY(EmployeeNumber),
CONSTRAINT EMP_DEPART_FK FOREIGN KEY(Department)
REFERENCES DEPARTMENT(DepartmentName)
ON UPDATE CASCADE,
CONSTRAINT EMP_SUPER_FK FOREIGN KEY(Supervisor)
REFERENCES EMPLOYEE(EmployeeNumber)
);
ALTER TABLE EMPLOYEE AUTO_INCREMENT=1;
CREATE TABLE PROJECT(
ProjectID Int NOT NULL AUTO_INCREMENT,
ProjectName Char(50) NOT NULL,
Department Char(35) NOT NULL,
MaxHours Numeric(8,2) NOT NULL DEFAULT 100,
StartDate Date NULL,
EndDate Date NULL,
CONSTRAINT PROJECT_PK PRIMARY KEY(ProjectID),
CONSTRAINT PROJ_DEPART_FK FOREIGN KEY(Department)
REFERENCES DEPARTMENT(DepartmentName)
ON UPDATE CASCADE
);
ALTER TABLE PROJECT AUTO_INCREMENT=1000;
CREATE TABLE ASSIGNMENT (
ProjectID Int NOT NULL,
EmployeeNumber Int NOT NULL,
HoursWorked Numeric(6,2) NULL,
CONSTRAINT ASSIGNMENT_PK PRIMARY KEY(ProjectID, EmployeeNumber),
CONSTRAINT ASSIGN_PROJ_FK FOREIGN KEY(ProjectID)
REFERENCES PROJECT(ProjectID)
ON UPDATE NO ACTION
ON DELETE CASCADE,
CONSTRAINT ASSIGN_EMP_FK FOREIGN KEY(EmployeeNumber)
REFERENCES EMPLOYEE(EmployeeNumber)
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
INSERT Department(DepartmentName, BudgetCode, OfficeNumber, DepartmentPhone)
VALUES('Administration', 'BC-100-10', 'BLDG01-201', '360-285-8100'),
('LEGAL', 'BC-200-10', 'BLDG01-220', '360-285-8200'),
('Human Resources', 'BC-300-10', 'BLDG01-230', '360-285-8300'),
('Finance', 'BC-400-10', 'BLDG01-110', '360-285-8400'),
('Accounting', 'BC-500-10', 'BLDG01-120', '360-285-8405'),
('Sales and Marketing','BC-600-10', 'BLDG01-250', '360-285-8500'),
('InfoSysems', 'BC-700-10', 'BLDG02-210', '360-285-8600'),
('Research and Development', 'BC-800-10', 'BLDG02-250', '360-285-8700'),
('Production', 'BC-900-10', 'BLDG02-110', '360-285-8800')
INSERT Employee(EmployeeNumber, FirstName, LastName, Department, Position, Supervisor, OfficePhone, EmailAddress)
VALUES('1', 'Mary', 'Jacobs', 'Administration', 'CEO', NULL, '360-285-8110', '[email protected]'),
('2', 'Rosalie', 'Jackson', 'Administration', 'AdminAsst', '1', '360-825-8120', '[email protected]'),
('3', 'Richard', 'Bandalone', 'Legal', 'Attorney', '1', '360-285-8210', '[email protected]'),
('4', 'George', 'Smith', 'Human Resources', 'HR3', '1', '360-285-8310', '[email protected]'),
('5','Alan', 'Adams', 'Human Resources', 'HR1', '4', '360-285-8320', '[email protected]'),
('6', 'Ken', 'Evans', 'Finance', 'CFO', '1', '360-285-8410', '[email protected]'),
('7', 'Mary', 'Abernathy', 'Finance', 'FA3', '6', '360-285-8420', '[email protected]'),
('8', 'Tom', 'Caruthers', 'Accounting', 'FA2', '6', '360-285-8430', '[email protected]'),
('9', 'Heather', 'Jones', 'Accounting', 'FA2', '6', '360-825-8440', '[email protected]'),
('10', 'Ken', 'Numoto', 'Sales and Marketing', 'SM3', '1', '360-285-8510', '[email protected]'),
('11', 'Linda', 'Granger', 'Sales and Marketing', 'SM3', '10', '360-285-8520', '[email protected]'),
('12', 'James', 'Nestor', 'InfoSystems', 'CIO', '1', '360-285-8610', '[email protected]'),
('13', 'Rick', 'Brown', 'InfoSystems', 'IS2', '12', NULL, '[email protected]'),
('14', 'Mike', 'Nguyen', 'Research and Development', 'CTO', '1', '360-285-8710', '[email protected]'),
('15', 'Jason', 'Sleeman', 'Research and Development', 'RD3', '14', '360-285-8720', '[email protected]'),
('16', 'Mary', 'Smith', 'Production', 'OPS3', '1', '360-825-8810', '[email protected]'),
('17', 'Tom', 'Jackson', 'Production', 'OPS2', '16', '360-825-8820', '[email protected]'),
('18', 'George', 'Jones', 'Production', 'CPS2', '17', '360-825-8830', '[email protected]'),
('19', 'Julia', 'Hayakawa', 'Production', 'CPS1', '17', NULL, '[email protected]'),
('20', 'Sam', 'Stewart', 'Production', 'OPS1', '17', NULL, '[email protected]')
INSERT Project(ProjectID, ProjectName, Department, MAxHours, StartDate, EndDate)
VALUES ('1000', '2017 Q3 Production Plan', 'Production', '100.00', '05/10/17', '2017-06-15'),
('1100', '2017 Q3 Marketing Plan', 'Sales and Marketing', '135.00', '05/10/17', '2017-06-15'),
('1200', '2017 Q3 Portfolio Analysis', 'Finance', '120.00', '07/05/17', '2017-07-25'),
('1300', '2017 Q3 Tax Preparation', 'Accounting', '145.00', '08/10/17', '2017-10-15'),
('1400', '2017 Q4 Production Plan', 'Production', '100.00', '08/10/17', '2017-09-15'),
('1500', '2017 Q4 Marketing Plan', 'Sales and Marketing', '135.00', '08/10/17', '2017-09-15'),
('1600', '2017 Q4 Portfolio Analysis', 'Finance', '140.00', '10/05/17', NULL)
INSERT Assignment(ProjectID, EmployeeNumber, HoursWorked)
VALUES('1000', '1', '30.00'),
('1000', '6', '50.00'),
('1000', '10', '50.00'),
('1000', '16', '75.00'),
('1000', '17', '75.00'),
('1100', '1', '30.00'),
('1100', '6', '75.00'),
('1100', '10', '55.00'),
('1100', '11', '55.00'),
('1200', '3', '20.00'),
('1200', '6', '40.00'),
('1200', '7', '45.00'),
('1200', '8', '45.00'),
('1300', '3', '25.00'),
('1300', '6', '40.00'),
('1300', '8', '50.00'),
('1300', '9', '50.00'),
('1400', '1', '30.00'),
('1400', '6', '50.00'),
('1400', '10', '50.00')
In: Computer Science
Write a program that implements the pseudocode ("informal
high-level description of the operating principle of a computer
program or other algorithm") below:
1. Ask the user for the size of their apartment in square meters
(size)
2. Convert the size to square feet using the formula: convertedSize
= size * 10.764
3. Print out the converted size.
Have meaningful prompts and meaningful explanation of any numbers
printed.
In: Computer Science
Hi I am getting error in implement some test case using Java. I am adding my code and relevant files here, and the failed test. Please let me know where my problem is occuring and fix my code. Thanks! I will upvote.
Implement a class to perform windowing of a Hounsfield value
Implement the class described by this API. A partial implementation is provided for you in the eclipse project; however, unlike the previous class, very little work has been done for you. You must carefully study the API of the class to determine the precise signatures of the constructors and methods that you need to implement. Furthermore, you need to thoroughly understand the concept of windowing to determine what fields are required in your class.
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.
API doc: https://drive.google.com/open?id=1GKm_m74PwFBZIC__JmnWnGi6cFzmGuul
/**
* 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.
*
*
* A window has a lower and upper bound. The lower bound is defined
as the
* window level minus half the window width:
*
*
* lo = level - (width / 2)
*
*
* The upper bound is defined as the window level plus half the
window width:
*
*
* hi = level + (width / 2)
*
*
* 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:
*
*
* (v - lo) / width
*
*
*/
public class HounsfieldWindow {
private int level;
private int width;
HounsfieldWindow(int level, int width) {
setLevel(level);
this.width = width;
}
public HounsfieldWindow() {
this(0, 400);
}
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 < 1) {
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 h) {
// TODO Auto-generated method
stub
int hounsfieldUnitVal =
h.get();
System.out.println("got " + hounsfieldUnitVal);
if(hounsfieldUnitVal < getLowerBound()) {
return 0;
}
if(hounsfieldUnitVal > getUpperBound()) {
return 1;
}
return (hounsfieldUnitVal - getLowerBound()) /
(double)width;
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tests that fails:
@Test
public void test04_ctorThrowsOnBadWidth() {
final int[] BAD_WIDTHS = {-10000,
-10, 0};
for (int width : BAD_WIDTHS)
{
try {
new HounsfieldWindow(0, width);
fail(String.format("new HounsfieldWindow(0, %s)
should throw an exception", width));
}
catch
(IllegalArgumentException x) {
// ok
}
}
}
@Test
public void test10_map() {
assumeTrue("test requires a correct
implementation of HounsfieldWindow(int, int)", IS_CTOR_OK);
// uses windows of width 1
// easy to test because map should
always return 0.5 for
// Hounsfield values inside the
window
final int width = 1;
for (int level =
Hounsfield.MIN_VALUE; level <= Hounsfield.MAX_VALUE; level++)
{
// make a window
to call map on
HounsfieldWindow
w = new HounsfieldWindow(level, width);
// the actual
value returned by map
double got =
w.map(new Hounsfield(level));
// make an
error message in case the test fails
String error =
String.format(
"map(%s) failed to return the
correct value for a window with level %s, width %s", level,
level,
width);
// assert
that 0.5 equals got
assertEquals(error, 0.5, got, 1e-9);
}
}
@Test
public void test11_map() {
assumeTrue("test requires a correct
implementation of HounsfieldWindow(int, int)", IS_CTOR_OK);
// tests Hounsfield units in
windows of various widths and levels
final int[] WIDTH = {2, 3, 4, 5,
10, 25, 50, 75, 100, 255};
final int[] LEVEL = {-800, -1, 1,
750};
for (int level : LEVEL) {
for (int width :
WIDTH) {
// make a window to call map on
HounsfieldWindow w = new HounsfieldWindow(level,
width);
// expected values map should return
double[] EXP =
HounsfieldWindowTest.mapValues(width);
for (int i = 0; i < EXP.length; i++) {
// Hounsfield unit to
map
Hounsfield h = new
Hounsfield(level - width / 2 + i);
// the expected return value
of map(h)
double exp = EXP[i];
// the actual value returned
by map(h)
double got = w.map(h);
// make an error message in
case the test fails
String error =
String.format(
"map(%s) failed to return the correct value for
a window with level %s, width %s", h.get(), level,
width);
// assert that exp equals
got
assertEquals(error, exp, got,
1e-9);
}
}
}
}
Relevant files(Hounsfield.java and Hounsfieldtest.java): https://drive.google.com/open?id=1HRUH5bika5xeLO7G_kP2LeMxNeXejRgl
In: Computer Science