Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Differentiate between various leadership theories;

Answered: 1 week ago