Question

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

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.

CreatePurchase

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();
}
}

Purchase.java

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);
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Purchase.java

public class Purchase {

private int invoiceNumber;

private double saleAmount, saleTax;

private static final double TAX = 5;

/**

* @param invoiceNumber the invoiceNumber to set

*/

public void setInvoiceNumber(int invoiceNumber) {

this.invoiceNumber = invoiceNumber;

}

/**

* @param saleAmount the saleAmount to set

*/

public void setSaleAmount(double saleAmount) {

this.saleAmount = saleAmount;

this.saleTax = TAX * this.saleAmount / 100;

}

public void display() {

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

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

}

}

CreatePurchase.java

import java.util.Scanner;

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();

}

}

Add a comment
Know the answer?
Add Answer to:
Create a class named Purchase. Each Purchase contains an invoice number, amount of sale, and amount...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT