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

Create a class named Purchase. Each Purchase contains an invoice number, amount

ID: 3660920 • Letter: C

Question

Create a class named Purchase. Each Purchase contains an invoice number, amount of sale, and amount of sales tax. Include set methods for the invoice number and sale amount. Within the set() method for the sale amount, calculate the sales tax as 7.5% (using a static filed in the Purchase class) of the sale amount. Also include a display method that displays a purchase's details in a well formatted output display. Save the file as Purchase.java. Compile and run the program until it works and the output looks nice.

Explanation / Answer

class Purchase
{
    private int invoiceNumber;
    private double amount;
    private double tax;

    private static double salesTax = 7.5;

    public void setInvoiceNumber(int invoiceNumber)
    {
        this.invoiceNumber = invoiceNumber;
    }

    public void setAmount(double amount)
    {
        this.amount = amount;
        this.tax = amount * (salesTax / 100);
    }

    public void display()
    {
        System.out.println("Invoice Number: " + invoiceNumber);
        System.out.println("Amount: $" + amount);
        System.out.println("Tax: $" + tax);
    }

    public static void main(String[] args)
    {
        Purchase test = new Purchase();
        test.setInvoiceNumber(1);
        test.setAmount(2.49);
        test.display();
    }
}

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