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 5% of the sale amount. Also include a display method that displays a purchase’s details.
Provided code:
import java.util.*;
public class CreatePurchase
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
Purchase purch = new Purchase();
int num;
double amount;
String entry;
final int LOW = 1000, HIGH = 8000;
System.out.println("Enter invoice number");
entry = input.next();
num = Integer.parseInt(entry);
while(num <= LOW || num >= HIGH)
{
System.out.println("Invoice number must be between " +
LOW + " and " + HIGH + "\nEnter invoice number");
entry = input.next();
num = Integer.parseInt(entry);
}
System.out.println("Enter sale amount");
entry = input.next();
amount = Double.parseDouble(entry);
while(amount < 0)
{
System.out.println("Enter sale amount");
entry = input.next();
amount = Double.parseDouble(entry);
}
purch.setInvoiceNumber(num);
purch.setSaleAmount(amount);
purch.display();
}
}
public class Purchase { private int invoiceNumber; private double saleAmount; private static double SALES_TAX = 0.05; public void setInvoiceNumber(int invoiceNumber) { this.invoiceNumber = invoiceNumber; } public void setSaleAmount(double saleAmount) { this.saleAmount = saleAmount; } public void display() { System.out.println("Invoice number: " + invoiceNumber); System.out.println("Sales amount: " + saleAmount); double tax = invoiceNumber * SALES_TAX; System.out.println("Tax amount: " + tax); System.out.println("Total purchase amount: " + (tax + saleAmount)); } }
Get Answers For Free
Most questions answered within 1 hours.