I know that I am extremely close but somehow I am jumbled up. My package has two
ID: 3554504 • Letter: I
Question
I know that I am extremely close but somehow I am jumbled up. My package has two classes listed below. The CreatePurchase class is trying to call from the Purchase class to display the invoice number, sale amount, and sales tax. I will also list the origional question. Please help fix my my Java class and dont just make your own.
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
Explanation / Answer
package com.sampath.chegg;
public class Purchase
{
private double invoiceNumber;
private double amountOfSales;
private double salesTax;
public void setInvoiceNumber(double iNumber)
{
invoiceNumber = iNumber;
}
public void setAmountOfSales(double n)
{
amountOfSales = n;
salesTax = (5.0/100) * n;
}
public void purchaseDetails()
{
System.out.println("Purchase Details: ");
System.out.println("Invoice Number: " + invoiceNumber);
System.out.println("Sales Total: " + amountOfSales);
System.out.println("SalesTax: " + salesTax);
}
}
package com.sampath.chegg;
import java.util.*;
public class CreatePurchase {
public static void main(String args[]) {
int iNumber;
int n;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter Invoice Number: ");
iNumber = keyboard.nextInt();
while (iNumber < 1000 || iNumber > 8000) {
System.out.println("Invalid Entry! Please enter a number between "
+ "1000-8000:");
iNumber = keyboard.nextInt();
}
Purchase p = new Purchase();
p.setInvoiceNumber(iNumber);
System.out.println("Enter Sales Amount");
n = keyboard.nextInt();
while (n < 0) {
System.out.println("Invalid Entry! Please enter a positive value.");
n = keyboard.nextInt();
}
p.setAmountOfSales(n);
p.purchaseDetails();
keyboard.close();
}
}