Fix the following method before adding it to the class. Public String toString()
ID: 3582903 • Letter: F
Question
Fix the following method before adding it to the class. Public String toString() {System.out.println ("description = + description); System.out.println ("price = "+ price); System.out.println ("occasion = " + occasion); System.out.println ("taxable = + taxable); Fix the following method before adding it to the class. public Boolean equals (object g) {return (this == g);} What is wrong with the following method? public void setTaxRate(double newTaxRate) TAX_RATE = newTaxRate;} Fix the following method before adding it to the class. public double calcTax(TAX_RATE) {return TAX_RATE * price;}Explanation / Answer
c) In this question if variables written in the System.out.println() statement are not publically declared int the class then this variables must be passed as a arguments to the toString() method. Since the toString() method does not returning any value return type of method shoud be made as void.
public void toString(String description,double price,String occasion,double taxable)
{
System.out.println("description = "+ description);
System.out.println("price = "+ price);
System.out.println("occasion = "+ occasion);
System.out.println("taxable = "+taxable);
}
d)
public boolean equals(Object g)
{
return (this==(class_name) g); //Type cast the g object into class_name object.
}
e)
public void setTaxRate(double newTaxRate)
{
double TAX_RATE=newTaxRate;
}
f)
public double calcTax(double TAX_RATE,double price)
{
return TAX_RATE * price ;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.