Question

In: Computer Science

I was wondering if you can tell me if the following code is correct and if...

I was wondering if you can tell me if the following code is correct and if its not can it be fixed so it does not have any syntax errors.

Client one

/**
* 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 a 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;
  

//return "not cor";
  

/**
* 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;
}
}

Solutions

Expert Solution

/**
* 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 a 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
       firstName = inFirstName;
   }

   /**
   * Return the first name of the client.
   *
   * @return String first name.
   */
   public String getFirstName() {
       return firstName;
   }

   // return "not cor";

   /**
   * 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) {
       weight = inWeight;
       // replace this comment with your code
   }

   /**
   * Return the weight of the client.
   *
   * @return int weight of client.
   */
   public int getWeight() {
       return weight;
       // replace this comment & return statement with your code
   }

   /**
   * 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;
   }
}

//it has no syntax errors. added few lines of code


Related Solutions

I was wondering is someone could tell me why my code isn't compiling - Java ------------------------------------------------------------------------------------------------------------...
I was wondering is someone could tell me why my code isn't compiling - Java ------------------------------------------------------------------------------------------------------------ class Robot{ int serialNumber; boolean flies,autonomous,teleoperated; public void setCapabilities(int serialNumber, boolean flies, boolean autonomous, boolean teleoperated){ this.serialNumber = serialNumber; this.flies = flies; this.autonomous = autonomous; this.teleoperated = teleoperated; } public int getSerialNumber(){ return this.serialNumber; } public boolean canFly(){ return this.flies; } public boolean isAutonomous(){ return this.autonomous; } public boolean isTeleoperated(){ return this.teleoperated; } public String getCapabilities(){ StringBuilder str = new StringBuilder(); if(this.flies){str.append("canFly");str.append(" ");} if(this.autonomous){str.append("autonomous");str.append("...
Hello, I was wondering if you could tell me how to do a general Ledger? I...
Hello, I was wondering if you could tell me how to do a general Ledger? I just finish doing a Sales Journal, Purchase Journal, Cash Receipt Journal, Cash Disbursements Journal and a General Journal under one company Sound Bytes Electronics). What I wanted to know is do I use the General Journal to do the General Ledger? Or do I use the Special Journals and the General Journal to do the General Ledger? Can you put me in the right...
Okay, can someone please tell me what I am doing wrong?? I will show the code...
Okay, can someone please tell me what I am doing wrong?? I will show the code I submitted for the assignment. However, according to my instructor I did it incorrectly but I am not understanding why. I will show the instructor's comment after providing my original code for the assignment. Thank you in advance. * * * * * HourlyTest Class * * * * * import java.util.Scanner; public class HourlyTest {    public static void main(String[] args)     {        ...
I need to fix this code, and could you please tell me what was the problem...
I need to fix this code, and could you please tell me what was the problem options 1 and 9 don't work #include <stdio.h> #include <time.h> #include <stdlib.h> // generate a random integer between lower and upper values int GenerateRandomInt(int lower, int upper){     int num =(rand()% (upper - lower+1))+lower;     return num; } // use random numbers to set the values of the matrix void InitializeMatrix(int row, int column, int dimension, int mat[][dimension]){     for(int i =0; i<row; i++){...
please show me or tell me a trick, on how can i tell right away when...
please show me or tell me a trick, on how can i tell right away when a characteristics equation(system) is 1)overdamped 2)underdamped 3)critically damped 4) nonlinear show each an example write neatly!!!!!
Can you please tell me, what would be the correct way of doing it? def updateRepresentation(blank,...
Can you please tell me, what would be the correct way of doing it? def updateRepresentation(blank, secret, letter): """ This function replaces the appropriate underscores with the guessed letter. Eg. letter = 't', secret = "tiger", blank = "_i_er" --> returns "ti_er" Paramters: blank, secret are strings letter is a string, but a single letter. Returns: a string """ #TODO -- complete this function so that it produces a new string #from blank with letter inserted into the appropriate locations....
Can you tell me what is wrong with this code ? def update_char_view(phrase: str, current_view: str,...
Can you tell me what is wrong with this code ? def update_char_view(phrase: str, current_view: str, index: int, guess: str)->str: if guess in phrase: current_view = current_view.replace(current_view[index], guess) else: current_view = current_view    return current_view update_char_view("animal", "a^imal" , 1, "n") 'animal' update_char_view("animal", "a^m^l", 3, "a") 'aamal'
Can someone look into my code and tell me what do you think: Thats Palindrome; //class...
Can someone look into my code and tell me what do you think: Thats Palindrome; //class name Palindrome public class Palindrome {    public static void palindromeChecker(String... str) {        // takes string one by one        for (String s : str) {            // creates a stringbuilder for s            StringBuilder sb = new StringBuilder(s);            // reverses the sb            sb.reverse();            // checks if both...
Can someone tell me the correct answers of this questions? 1) A arm's length transaction, which...
Can someone tell me the correct answers of this questions? 1) A arm's length transaction, which would be reflected in the consolidated financial statements, would include: a-A loan to the president of the subsidiary company- Incorrect b-The purchase of material from a supplier abroad c-The sale of fixed assets that are no longer needed to the subsidiary- Incorrect d-Sales of inventory to a subsidiary 2) When a partner withdraws from a partnership and the remaining partners acquire that interest: a)...
Can someone please tell me if these calculations are correct! I'm reviewing my notes, and my...
Can someone please tell me if these calculations are correct! I'm reviewing my notes, and my professor said to always multiply the lipids by 3 and then divide by 7 to get the total amount of cals of lipids per day... I'm not completely sure why you do that? Can someone explain. Why don't you just stop at 700 cals for lipids? 1. Calculate the number of calories and grams protein for the following TPN solution: D50W in 500cc 10%...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT