Create a class named Purchase. Each Purchase contains an invoice number, amount
ID: 3907897 • 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 field 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, add the necessary documentation as described in Course Documents, and then attach your .java file to this assignment. Do not attach the .class file, attach only your source code. This assignment is due the last day of the academic week.
Explanation / Answer
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package purchase;
public class Purchase {
private String invNo;
private double saleAmt;
private double saleTax;
private static double salesTaxPer = 7.5;
public void setInvNo(String invNo) {
this.invNo = invNo;
}
public void setSaleAmt(double saleAmt) {
this.saleAmt = saleAmt;
//set sale amt
this.saleTax = saleAmt*salesTaxPer/100;
}
public String getInvNo() {
return invNo;
}
public double getSaleAmt() {
return saleAmt;
}
public double getSaleTax() {
return saleTax;
}
public void Display(){
//display the data
System.out.println("Invoice Number : " + invNo);
System.out.println("Sale Amount : " + saleAmt);
System.out.println("Sale Tax("+ salesTaxPer +"%): " + saleTax);
System.out.println("Total Amount :" + (saleAmt+ saleTax));
}
public static void main(String[] args) {
//create obj
Purchase pur = new Purchase();
//set data
pur.setInvNo("123");
pur.setSaleAmt(1000);
pur.Display();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.