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: 3654189 • 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 your programs until it works and the output looks nice. Add the necessary documentation as described in Course Documents, and then attach your .java files to this assignment This Assignment must have display method and tostring method shoud not contain output.

Explanation / Answer

package com.deitel.ch17.exercise; public class Purchase { private double salesTax; private double salesAmount; private String invoiceNumber; // 7.5% as sales Tax private static final double salesTaxPercentage = 0.075; public double getSalesAmount() { return salesAmount; } public void setSalesAmount(double salesAmount) { this.salesAmount = salesAmount; salesTax = this.salesAmount * salesTaxPercentage; } public String getInvoiceNumber() { return invoiceNumber; } public void setInvoiceNumber(String invoiceNumber) { this.invoiceNumber = invoiceNumber; } public double getSalesTax() { return salesTax; } public void display() { System.out.printf("Purchase Details: " + "Invoice Number : %s " + "Sale amount = $ %,.2f " + "Sales Tax = $ %,.2f", invoiceNumber,salesAmount,salesTax); } public static void main(String[] args) { Purchase test = new Purchase(); test.setInvoiceNumber("AB1236547"); test.setSalesAmount(500); 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