Question: Java programming. Create a class named Purchase. Each Purchase contains an invoice number, amount of sale, and amount of sales tax. Include set methods for

Java programming. 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 purchases details.

Given 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 + " Enter 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 double tax;

private static final double RATE = 0.05;

public void setInvoiceNumber(int num) {

}

public void setSaleAmount(double amt) {

}

public double getSaleAmount() {

}

public int getInvoiceNumber() {

}

public void display() {

System.out.println("Invoice #" + invoiceNumber +

" Amount of sale: $" + saleAmount + " Tax: $" + tax);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!