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

Implement the class Tip according to the given UML and use it as the background

ID: 3720335 • Letter: I

Question

Implement the class Tip according to the given UML and use it as the background class.

     TipCalculator

private Tip tip; //an instance of Tip

private String[] strLabel={}; //initilize the array

private TextField[] txt;

private String[] strBtn = {}; //initialize the array

private Button[] btn;

      Tip

private double amount; //amount of dollar consumed

private static double taxRate; //percent of tax

private double tipPercent ; //percent of tip

public Tip();

public Tip(double amount, double tipPercent);

public double getAmount();

public void setAmount(double amount);

public double getTipPercent();

public void setTipPercent(double tipPercent);

public static double getTaxRate();

public static void setTaxRate(double taxRate);

public double calculateTax()

public double calculateTip()

public double calculateTotal()

     TipCalculator

private Tip tip; //an instance of Tip

private String[] strLabel={}; //initilize the array

private TextField[] txt;

private String[] strBtn = {}; //initialize the array

private Button[] btn;

Explanation / Answer

public class Tip {

private double amount;

private static double taxRate;

private double tipPercent;

public Tip()

{

amount=0;

tipPercent=0.0;

}

public Tip(double amount, double tipPercent) {

super();

this.amount = amount;

this.tipPercent = tipPercent;

}

public double getAmount() {

return amount;

}

public void setAmount(double amount) {

this.amount = amount;

}

public static double getTaxRate() {

return taxRate;

}

public static void setTaxRate(double taxRate) {

Tip.taxRate = taxRate;

}

public double getTipPercent() {

return tipPercent;

}

public void setTipPercent(double tipPercent) {

this.tipPercent = tipPercent;

}

public double calculateTax()

{

return taxRate*amount;

}

public double calculateTip()

{

return tipPercent*amount;

}

public double totalAmount()

{

return calculateTax()+calculateTip()+amount;

}

}