Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3651231 • 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 filed 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.

Create an application that declares a purchase object and prompts the user for purchase details. When you prompt for an invoice number, do not let the user proceed until a number between 1000 and 8000 has been entered. When you prompt for a sale amount, do not proceed until the user has entered a nonnegative value. After a valid Purchase object has been created, display the object's invoice number, sale amount, and sales tax. Save the file as CreatePurchase.java

Explanation / Answer

Please rate...

purchase.java

===================================================

class Purchase
{
    int invoiceNumber;
    int amountOfSales;
    double amountOfSalesTax;
    static double rate=7.5;
    public void setInvoiceNumber(int i)
    {
        invoiceNumber=i;
    }
    public void setAmountOfSales(int a)
    {
        amountOfSales=a;
        amountOfSalesTax=(7.5*a)/100;
    }
    public void display()
    {
        System.out.println("The deatils are:");
        System.out.println("Invoice Number: "+invoiceNumber);
        System.out.println("Amount of Sales: "+amountOfSales);
        System.out.println("Amount of sales tax: "+amountOfSalesTax);
    }
}

=====================================================

CreatePurchase.java

=====================================================

import java.util.Scanner;

class CreatePurchase
{
    public static void main(String args[])
    {
        Purchase purchase=new Purchase();
        Scanner s=new Scanner(System.in);
        System.out.println("Enter the details: ");
        while(true)
        {
            System.out.print("Enter invoice number[between 1000 and 8000]: ");
            int i=s.nextInt();
            if(i>=1000 && i<=8000){purchase.setInvoiceNumber(i);break;}
            else System.out.println("Wrong entry,enter again");
        }
        while(true)
        {
            System.out.print("Enter amount of purchase[should be non-negative]: ");
            int i=s.nextInt();
            if(i>=0){purchase.setAmountOfSales(i);break;}
            else System.out.println("Wrong entry,enter again");
        }
        purchase.display();
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote