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
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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.