Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need a stringbuilder for this. How would I go about doing it? public String to

ID: 3711862 • Letter: I

Question

I need a stringbuilder for this. How would I go about doing it?

public String toString( )
{
    /*
     * The toString returns a verbose description of the HomeOwners policy
     */
    String myType = getClass( ).getName( );
  

   
    return String.format( "%sThis %s policy insures a type %d home at %s. "
                           + "The structure is insured for $%,d.00;%ncontents for $%,d.00. The deductible is $%,.2f. "
                           + "This policy %s part of an Umbrella contract.%n",
                         super.toString( ),
                         myType,
                         getPropType( ),
                         getPropAddress( ),
                         getStructure( ) * 1000,
                         getContents( ) * 1000,
                         getDeductInDollars( ),
                         getUmbrella( )? "is a" : "is not" );
  
  
} // end toString

public tastrinstns String reference to ? formatted description ofthe Homeowners onject: Returns insured, polPren This Honeowners policy insures a type propType hone at propaddress The structure is insured for $structure contents for scontents. deductible is $getDedcutInDolL an Urbrella contract. StringBuilder object. Use the supercless toString method for the first part of the output Lars This policy is/is not part of

Explanation / Answer

public String printDetails() {

String myType = getClass( ).getName( );

String result = super.toString( ) + " This " + myType + " policy insures a type ";

result += String.valueOf(getPropType( )) + " home at " + getPropAddress( ) + " The structure is insured for $";

result += String.valueOf(getStructure( ) * 1000) + ";" + String.valueOf(getContents( ) * 1000) + "contents for ";

result += String.valueOf(getDeductInDollars( )) + ". The deductible is $" + (getUmbrella( )? "is a" : "is not");)

StringBuilder str = new StringBuilder(result);

System.out.println(str.toString());

}

**Comment for any further queries.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote