Can somebody please take a look at this code because everytime I try to compile it and it always gives me an error can somebody please take a look at it and please fix the code to make it work properly, and answer the question below.
1. Describe your approach to testing your solution?
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* The test class ClientTest tests the Client class.
*
* @author Doyt Perry/<add your name here>.
* @version Fall 2019
*/
public class ClientTest
{
/**
* Default constructor for test class ClientTest.
*/
public ClientTest()
{
// not used in this Lab
}
/**
* Sets up the test fixture.
*
* Called before every test case method.
*/
@Before
public void setUp()
{
// not used in this Lab
}
/**
* Tears down the test fixture.
*
* Called after every test case method.
*/
@After
public void tearDown()
{
// not used in this Lab
}
/**
* Test Client constructor #1 (no parameters).
*/
@Test
public void testConstructor1()
{
// Create a client object using the constructor with no
parameters.
Client tstClient = new Client();
// Verify instance variables have been set to placeholder
values
assertEquals("last name", tstClient.GetLastName);
assertEquals("first name",tstClient.GetFirstName);
assertEquals(0, tstClient.getAge());
assertEquals(1, tstClient.getHeight());
assertEquals(1, tstClient.getWeight());
}
/**
* Test Client constructor #2 (5 parameters).
*/
@Test
public void testConstructor2()
{
// Create a client object using the constructor with 5
parameters.
Client tstClient = new Client("Smith", "Carl", 44, 70, 200);
// Verify instance variables have been set to the passed in
values
assertEquals("Smith", tstClient.GetLastName')';
assertEquals("Carl", tstClient.GetFirstName);
assertEquals(44, tstClient.getAge());
assertEquals(70, tstClient.getHeight());
// REMOVE this comment and fix the test below
assertEquals(1, tstClient.getWeight());
}
/**
* Test setLastName method.
*/
@Test
public void testSetLastName()
{
// Create a client object using the constructor with 5
parameters.
Client tstClient = new Client("Smith", "Carl", 44, 70, 200);
// set the last name to a new value
tstClient.setLastName("Smithsonian");
// Verify last name has been set to new value
assertEquals("Smithsonian", tstClient.getLastName());
}
/**
* Test set setFirstName method.
*/
@Test
public void testSetFirstName()
{
// Create a client object using the constructor with 5
parameters.
Client tstClient = new Client("Smith", "Carl", 44, 70, 200);
// set the first name to a new value
tstClient.setFirstName("Robert");
// Verify first name has been set to new value
assertEquals("Robert", tstClient.getFirstName);
}
/**
* Test setAge method.
*/
@Test
public void testSetAge()
{
// Create a client object using the constructor with 5
parameters.
Client tstClient = new Client("Smith", "Carl", 44, 70, 200);
// set age to a new value
tstClient.setAge(39);
// REMOVE this comment and fix the test below
// Verify age has been set to new value
assertEquals(44, tstClient.getAge());
}
/**
* Test setHeight method.
*/
@Test
public void testSetHeight()
{
// Create a client object using the constructor with 5
parameters.
Client tstClient = new Client("Smith", "Carl", 44, 70, 200);
// set height to a new value
tstClient.setHeight(66);
// Verify height has been set to new value
assertEquals(66, tstClient.getHeight());
}
/**
* Test setWeight method.
*/
@Test
public void testSetWeight()
{
// Create a client object using the constructor with 5
parameters.
Client tstClient = new Client("Smith", "Carl", 44, 70, 200);
// set weight to a new value
tstClient.setWeight(180);
// Verify weight has been set to new value
assertEquals(180, tstClient.getWeight());
// REPLACE these comments with code that sets the weight to
// a different value & then verifies the updating has been
done
}
/**
* Test calcBMI method.
*
* NOTE TO 111 STUDENTS: This test method IS correct!!!
* DO NOT MODIFY IT
*
*/
@Test
public void testCalcBMI()
{
// Create a client object using the constructor with 5
parameters.
Client tstClient = new Client("Smith", "Carl", 44, 70, 200);
// Verify BMI has been correctly calculated (with delta
of.01)
assertEquals(28.69, tstClient.calcBMI(), .1);
}
/**
* Test the toString method.
*
* NOTE TO 111 STUDENTS: This test method IS correct!!!
* DO NOT MODIFY IT
*
*/
@Test
public void testToString()
{
// Create a client object using the constructor with no
parameters.
Client tstClient = new Client();
// call the toString() method to retrieve the output
String tstOutput = tstClient.toString();
// verify client name is in correct output format
assertTrue(tstOutput.contains("last name, first name"));
// verify client age is included in output stream
assertTrue(tstOutput.contains("0"));
// verify BMI is correctly calculated
assertTrue(tstOutput.contains("703.0"));
// Create a client object using the constructor with 5
parameters.
tstClient = new Client("Smith", "Carl", 44, 70, 200);
// call the toString() method to retrieve the output
tstOutput = tstClient.toString();
// verify client name is in correct output format
assertTrue(tstOutput.contains("Smith, Carl"));
// verify client age is included in output stream
assertTrue(tstOutput.contains("44"));
// verify client BM is correctly calculated
assertTrue(tstOutput.contains("28."));
}
}
We have Written
Client as well, to make it run without Errors and all the
correction has been made.
No modification was done where it was mentioned "DO NOT
MODIFY"
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* The test class ClientTest tests the Client class.
*
* @author Doyt Perry/<add your name here>.
* @version Fall 2019
*/
public class ClientTest
{
/**
* Default constructor for test class ClientTest.
*/
public ClientTest()
{
// not used in this Lab
}
/**
* Sets up the test fixture.
*
* Called before every test case method.
*/
@Before
public void setUp()
{
// not used in this Lab
}
/**
* Tears down the test fixture.
*
* Called after every test case method.
*/
@After
public void tearDown()
{
// not used in this Lab
}
/**
* Test Client constructor #1 (no parameters).
*/
@Test
public void testConstructor1()
{
// Create a client object using the constructor with no
parameters.
Client tstClient = new Client();
// Verify instance variables have been set to placeholder
values
assertEquals("last name", tstClient.getLastName());
assertEquals("first name",tstClient.getFirstName());
assertEquals(0, tstClient.getAge());
assertEquals(1, tstClient.getHeight());
assertEquals(1, tstClient.getWeight());
}
/**
* Test Client constructor #2 (5 parameters).
*/
@Test
public void testConstructor2()
{
// Create a client object using the constructor with 5
parameters.
Client tstClient = new Client("Smith", "Carl", 44, 70, 200);
// Verify instance variables have been set to the passed in
values
assertEquals("Smith", tstClient.getLastName());
assertEquals("Carl", tstClient.getFirstName());
assertEquals(44, tstClient.getAge());
assertEquals(70, tstClient.getHeight());
assertEquals(200, tstClient.getWeight());
}
/**
* Test setLastName method.
*/
@Test
public void testSetLastName()
{
// Create a client object using the constructor with 5
parameters.
Client tstClient = new Client("Smith", "Carl", 44, 70, 200);
// set the last name to a new value
tstClient.setLastName("Smithsonian");
// Verify last name has been set to new value
assertEquals("Smithsonian", tstClient.getLastName());
}
/**
* Test set setFirstName method.
*/
@Test
public void testSetFirstName()
{
// Create a client object using the constructor with 5
parameters.
Client tstClient = new Client("Smith", "Carl", 44, 70, 200);
// set the first name to a new value
tstClient.setFirstName("Robert");
// Verify first name has been set to new value
assertEquals("Robert", tstClient.getFirstName());
}
/**
* Test setAge method.
*/
@Test
public void testSetAge()
{
// Create a client object using the constructor with 5
parameters.
Client tstClient = new Client("Smith", "Carl", 44, 70, 200);
// set age to a new value
tstClient.setAge(39);
assertEquals(39, tstClient.getAge());
}
/**
* Test setHeight method.
*/
@Test
public void testSetHeight()
{
// Create a client object using the constructor with 5
parameters.
Client tstClient = new Client("Smith", "Carl", 44, 70, 200);
// set height to a new value
tstClient.setHeight(66);
// Verify height has been set to new value
assertEquals(66, tstClient.getHeight());
}
/**
* Test setWeight method.
*/
@Test
public void testSetWeight()
{
// Create a client object using the constructor with 5
parameters.
Client tstClient = new Client("Smith", "Carl", 44, 70, 200);
// set weight to a new value
tstClient.setWeight(180);
// Verify weight has been set to new value
assertEquals(180, tstClient.getWeight());
// REPLACE these comments with code that sets the weight to
// a different value & then verifies the updating has been
done
}
/**
* Test calcBMI method.
*
* NOTE TO 111 STUDENTS: This test method IS correct!!!
* DO NOT MODIFY IT
*
*/
@Test
public void testCalcBMI()
{
// Create a client object using the constructor with 5
parameters.
Client tstClient = new Client("Smith", "Carl", 44, 70, 200);
// Verify BMI has been correctly calculated (with delta
of.01)
assertEquals(28.69, tstClient.calcBMI(), .1);
}
/**
* Test the toString method.
*
* NOTE TO 111 STUDENTS: This test method IS correct!!!
* DO NOT MODIFY IT
*
*/
@Test
public void testToString()
{
// Create a client object using the constructor with no
parameters.
Client tstClient = new Client();
// call the toString() method to retrieve the output
String tstOutput = tstClient.toString();
// verify client name is in correct output format
assertTrue(tstOutput.contains("last name, first name"));
// verify client age is included in output stream
assertTrue(tstOutput.contains("0"));
// verify BMI is correctly calculated
assertTrue(tstOutput.contains("703.0"));
// Create a client object using the constructor with 5
parameters.
tstClient = new Client("Smith", "Carl", 44, 70, 200);
// call the toString() method to retrieve the output
tstOutput = tstClient.toString();
// verify client name is in correct output format
assertTrue(tstOutput.contains("Smith, Carl"));
// verify client age is included in output stream
assertTrue(tstOutput.contains("44"));
// verify client BM is correctly calculated
assertTrue(tstOutput.contains("28."));
}
}
--------------------------------------------------------------------------------------------------------------------------------
public class Client{
String fname, lname;
int age, height, weight;
public String getFirstName() {
return fname;
}
public double calcBMI() {
// TODO Auto-generated method
stub
return 703.0 *
weight/(height*height);
}
public void setFirstName(String fname) {
this.fname = fname;
}
public String getLastName() {
return lname;
}
public void setLastName(String lname) {
this.lname = lname;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
Client(){
fname = "first name";
lname = "last name";
age = 0;
height = 1;
weight = 1;
}
@Override
public String toString() {
return lname +", "+fname + age + +
height + + weight+ calcBMI();
}
public Client(String lname, String fname, int age, int
height, int weight) {
super();
this.fname = fname;
this.lname = lname;
this.age = age;
this.height = height;
this.weight = weight;
}
}
----------------------------------------------------------------------------------------------------------------------------------
SEE OUTPUT
Thanks, PLEASE COMMENT if
there is any concern.
Get Answers For Free
Most questions answered within 1 hours.