a. Fix the following method before adding it to the class. public void getPrice
ID: 655627 • Letter: A
Question
a. Fix the following method before adding it to the class.
public void getPrice ()
{
return price;
}
b. Fix the following method before adding it to the class.
public void setOccasion (String occasion)
{
occasion = occasion;
}
c. 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);
}
d. Fix the following method before adding it to the class.
public boolean equals (Object g)
{
return (this == g);
}
e. What is wrong with the following method?
public void setTaxRate (double newTaxRate)
{
TAX_RATE = newTaxRate;
}
f. Fix the following method before adding it to the class.
public double calcTax (TAX_RATE)
{
return TAX_RATE * price;
}
g. Fix the following code before adding it to the main method.
Gift g = new Gift ("radio", 59.99, "birthday", false);
Gift.setPrice (99.99);
h. Fix the following code before adding it to the main method.
Gift g = new Gift ("radio", 59.99, "birthday", false);
g.setTaxable () = true;
Explanation / Answer
a.
public double getPrice ()
{
return price;
}
b.
public void setOccasion (String occasion1)
{
occasion = occasion1;
}
c.
public void toString ()
{
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 == g);
}
e.
public void setTaxRate (double newTaxRate)
{
TAX_RATE = newTaxRate; //TAX_RATE is final literal, its value cannot be changed
}
TAX_RATE is final literal, its value cannot be changed
f.
public double calcTax (TAX_RATE)
{
return TAX_RATE * price;
}
TAX_RATE is final literal it cannot be used as parameter to accept value.
g.
Gift g = new Gift ("radio", 59.99, "birthday", false);
g.setPrice (99.99);
h.
Gift g = new Gift ("radio", 59.99, "birthday", false);
g.setTaxable (true);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.