View the step-by-step solution to:

Question

Tri-State Financial Services, a relatively small investment firm, has decided to expand their service line by

offering insurance. They have awarded you, an independent consultant, a contract to develop a prototype of an object-oriented quotation system that, if approved, will go into production as an application on all of their agents' smart phones. Naturally, you are anxious to do good job with your prototype so you will receive the large production contract.

Tri-State sees age and obesity as key factors for insuring individuals and will be using a person's age Body Mass Index (calculated from weight and height) in their quotes. 

Management has asked you to begin your prototype by designing a class that models a potential client. For this prototype you decide the key attributes (to be captured in instance variables) are:

Attribute

Type

Value/Range

"Placeholder" Value

Last Name

Text

Text

"last name"

First Name

Text

Text

"first name"

Age

Whole number

In years

0

Height

Whole number

In inches

1

Weight

Whole number

In pounds

1

You determine you will have two constructors, one that has no parameters (sets the instance variables to "placeholder" values) and another that has five parameters (one for each of the five instance variables).

You will code a set and a get method for each of the attributes.

You will also have a method that calculates the BMI of a client using the formula:

BMI = 703 x  

Finally, you will have method that displays basic customer information in the format:

    Last-name, First-name

    Age: Client's age, an integer

    BMI: Client's calculated BMI, a floating-point number

For this prototype, you will not validate any of the values passed into the constructors or methods. 


You think you have all the requirements and analysis in hand, and are ready to dive in.



Assignment


1.     A starter BlueJ project will be provided to you. It will contain three classes - Client, ClientTest, and ClientDemo. The version of the Client class provided has most of the methods completed to help get you started and provide the syntax and approach to use for the methods you will code. You will need to find and fix any syntax errors and compile the Client class - following any guiding comments within the code and meeting requirements described in this write up.

2.     After fixing the syntax errors, run the code in BlueJ (see item 6 below). This will reveal logic errors that need to be corrected in the Client class. Note that in ClientTest, all the tests (except one) are valid tests (i.e., if a test fails, there is likely a logic error in the Client class).

Read through ClientTest to better understand Junit tests. You will notice there are a couple of test methods in which you are to add a test case or fix the expected value in the test case. There are Java comments in the code indicate where you need to add or fix.

3.     You must use the provided project file and develop the lab within the BlueJ IDE to assignment.

4.     You must use the provided BlueJ starter project and develop your solution using the BlueJ IDE.

5.     Do NOT change the name, return type, or parameter order/type of any of the class or test class methods. These are used by Web-CAT to grade your submission, and you will end up losing points if they are changed.

6.     Each class constructor and method should be unit tested. Besides serving to verify that your code is accomplishing what you intended, writing unit test methods helps you understand how the objects should behave (how the class methods create, access and mutate the object). That is, writing the test methods first helps guide your class coding efforts.   

Follow these steps to complete the Client Class:

  1. Find and correct any syntax errors so that the classes in the project compile cleanly.
  2. Review the first JUnit test method, completing the code if necessary. Note that proper testing includes making manual calculations to verify that expected values for a method action are equivalent to actual results.
  3. Once you feel the unit test method is a valid and robust test of the method's expected behavior, review the corresponding class constructor or method and complete the coding if necessary.
  4. Run the JUnit test for the method. If it does not pass, review and correct the code for this method.
  5. When the test passes, continue in like manner for the next and subsequent methods, iteratively completing tests and developing your class or classes.  All class methods must be tested. 

7.     All classes must compile cleanly. 

8.     Check your programming style using the "Checkstyle" tool provided within BlueJ (Tools à Checkstyle).

9.     Document the overall project in the README file as directed in the Action Items for the Lab.

10. Submit your completed lab to Web-CAT using BlueJ (Tools à Submit) and review the Web-CAT results for errors. Repeat the above steps as needed to resolve any errors.

11. The class ClientDemo included in the project file demonstrates the use of the Client class, calling on its constructors and methods and displaying results. While it supports your understanding of the lab, it is not part of the actual solution. You can modify it if that is helpful to you, but the driver class will not be examined by Web-CAT nor graded by your instructor.





/**

 * Maintains information on an insurance client.

 * 

 * @author Doyt Perry/<add your name here> 

 * @version Fall 2019

 */

public class Client

{

  // instance variables 

  private String lastName;

  private String firstName;

  private int age;

  private int height;

  private int weight;


  /**

   * First constructor for objects of class Client.

   */

  public Client()

  {

    // initialize all instance variables to placeholder values

    this.lastName = "last name";

    this.firstName = "first name";

    this.age = 0;

    this.height = 1;

    this.weight = 1;

  }


  /**

   * Second constructor for objects of class Client.

   * 

   * 

   * Create client object using explicit parameters to specify

   * values for corresponding instance fields.

   * 

   * @param inLastName  last Name of client

   * @param inFirstName  first Name of client

   * @param inAge     age of client

   * @param inHeight   height of client

   * @param inWeight   weight of client

   */

  public Client(String inLastName, String inFirstName, int inAge,

    int inHeight, int inWeight)

  {

    // initialize instance variables

    // using values passed in as parameters

    this.lastName = inLastName;

    this.firstName = inFirstName;

    this.age = inAge;

    this.height = inHeight;

    this.weight = inHeight;

  }



  /**

   * Update the last name of the client.

   * 

   * @param inLastName  last name of the client.

   */

  public void setLastName(String inLastName)

  {

    // Set the last name instance variable to parameter

    this.lastName = inLastName;

  }

   

  /**

   * Return the last name of the client.

   * 

   * @return String last name.

   */

  public String getLastName()

  {

    // return the value of the last name instance variable

    return this.lastName

  }


  /**

   * Update the first name.

   * 

   * @param inFirstName  first name of the client.

   */

  public void setFirstName(String inFirstName)

  {

    // Set the first name instance variable to parameter. 

    // REPLACE this comment with your code 

  }

   

  /**

   * Return the first name of the client.

   * 

   * @return String first name.

   */

  public String getFirstName(

  {

    // REPLACE this comment & return statement with your code 

    return "not correct";

  }


  /**

   * Update the age of the client.

   * 

   * @param inAge  age of the client.

   */

  public void setAge(int inAge)

  {

    // Set the age instance variable to the parameter

    this.age = inAge;

  }

   

  /**

   * Return the age of the client.

   * 

   * @return int first name.

   */

  public int getAge()

  {

    // return the value of the first age instance variable.

    return this.age;

  }   

   

  /**

   * Update the height of the client.

   * 

   * @param inHeight  height of the client.

   */

  public void setHeight(int inHeight)

  {

    // Set the height instance variable to the parameter

    this.height = inHeight;

  }

   

  /**

   * Return the height of the client.

   * 

   * @return int height of client.

   */

  public int getHeight()

  {

    // return the value of the height instance variable.

    return this.height;

  }   

     

  /**

   * Update the weight of the client.

   * 

   * @param inWeight  weight of the client.

   */

  public void setWeight(int inWeight)

  {

    // replace this comment with your code 

  }

   

  /**

   * Return the weight of the client.

   * 

   * @return int weight of client.

   */

  public int getWeight()

  {

    // replace this comment & return statement with your code 

    return -1;

  }     

   

  /**

   * Calculate the BMI of the client.

   * 

   * @return double BMI of client.

   */

  public double calcBMI()

  {

    // return the result of calculating the BMI.

    // Refer to "Common Error 4.1" on page 142 in the textbook for more info

    // if WebCat flags the following calculation as an error.

    return (704 * this.weight) / this.height * this.height;

  }     


  /**

   * Display the client information.

   * 

   * @return String formatted client informatin.

   * 

   * <pre>

   * The label should be printed in the format:

   * 

   * last name, first name

   * Age: 99

   * BMI: 99.999

   * </pre>

   */

  public String toString()

  {

    // initialize the variable that will hold the output string

    String output = "";

     

    // put the name in lastname, firstname format

    output = output + this.lastName + this.firstName + "n";

     

    // include the client age

    output = output + "Age " + this.age + "n";

     

    // include the email address

    output = output + "BMI " + this.calcBMI() + "n";

     

    // return the output string

    return output;

  }

}

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes