Question

Can somebody please take a look at this code because everytime I try to compile it...

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."));
}
}

Homework Answers

Answer #1

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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I am a beginner when it comes to java codeing. Is there anyway this code can...
I am a beginner when it comes to java codeing. Is there anyway this code can be simplified for someone who isn't as advanced in coding? public class Stock { //fields private String name; private String symbol; private double price; //3 args constructor public Stock(String name, String symbol, double price) { this.name = name; this.symbol = symbol; setPrice(price); } //all getters and setters /** * * @return stock name */ public String getName() { return name; } /** * set...
Compile and execute the application. You will discover that is has a bug in it -...
Compile and execute the application. You will discover that is has a bug in it - the filled checkbox has no effect - filled shapes are not drawn. Your first task is to debug the starter application so that it correctly draws filled shapes. The bug can be corrected with three characters at one location in the code. Java 2D introduces many new capabilities for creating unique and impressive graphics. We’ll add a small subset of these features to the...
Please explain code 1 and code 2 for each lines code 1 public class MyQueue {...
Please explain code 1 and code 2 for each lines code 1 public class MyQueue {    public static final int DEFAULT_SIZE = 10;    private Object data[];    private int index; code 2 package test; import java.util.*; /* Class Node */ class Node { protected Object data; protected Node link; /* Constructor */ public Node() { link = null; data = 0; } /* Constructor */ public Node(Object d,Node n) { data = d; link = n; } /*...
Attached is the file GeometricObject.java. Include this in your project, but do not change. Create a...
Attached is the file GeometricObject.java. Include this in your project, but do not change. Create a class named Triangle that extends GeometricObject. The class contains: Three double fields named side1, side2, and side3 with default values = 1.0. These denote the three sides of the triangle A no-arg constructor that creates a default triangle A constructor that creates a triangle with parameters specified for side1, side2, and side3. An accessor method for each side. (No mutator methods for the sides)...
Casting class objects 1.2 Compile and execute the code listed below as it is written. Run...
Casting class objects 1.2 Compile and execute the code listed below as it is written. Run it a second time after uncommenting the line obj.speak();. public class AnimalRunner {    public static void main(String[] args)    {       Dog d1 = new Dog("Fred");       d1.speak();       Object obj = new Dog("Connie");       // obj.speak();    } } The uncommented line causes a compile error because obj is an Object reference variable and class Object doesn’t contain a speak() method. This...
loanCreator.java: /* * Use constants when necessary, define with proper scope * * Create Person class...
loanCreator.java: /* * Use constants when necessary, define with proper scope * * Create Person class with data fields of firstName and lastName these fields can not change. * * Create Loan class with data fields of Person, loan Amount, term and interest rate * If term is not past in then default value is 36 * If interest is not past in then default value is 5.0 * * In Loan class create method to construct output String *...
For this assignment, you'll create a Player class that captures information about players on a sports...
For this assignment, you'll create a Player class that captures information about players on a sports team. We'll keep it generic for this assignment, but taking what you learn with this assignment, you could create a class tailored to your favorite sport. Then, imagine using such a class to track the stats during a game. Player Class Requirements Your class should bet set up as follows: Named Player Is public to allow access from other object and assemblies Has a...
Whenever I try to run this program a window appears with Class not Found in Main...
Whenever I try to run this program a window appears with Class not Found in Main project. Thanks in Advance. * * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Assignment10; /** * * @author goodf */ public class Assignment10{ public class SimpleGeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated;    /**...
Sort by the following (name, address, dependent and gender) of these and ask the user which...
Sort by the following (name, address, dependent and gender) of these and ask the user which field to sort by !. this mean the following java must sort by address if we need, by name , by dependent , and by gender it depend on the following java it must have an option which we need to sort. please i need your help now, you just add the sorting on the following java. // Use a custom comparator. import java.io.BufferedReader;...
JAVA please Arrays are a very powerful data structure with which you must become very familiar....
JAVA please Arrays are a very powerful data structure with which you must become very familiar. Arrays hold more than one object. The objects must be of the same type. If the array is an integer array then all the objects in the array must be integers. The object in the array is associated with an integer index which can be used to locate the object. The first object of the array has index 0. There are many problems where...