Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Chapter 6 Exercise 15, you created a class named Purchase. Each Purchase contains an invoice number (invoiceNumber ), amount of sale ( sale
In Chapter 6 Exercise 15, you created a class named Purchase. Each Purchase contains an invoice number (invoiceNumber ), amount of sale ( sale Amount ), amount of sales tax ( tax ). Add get and set methods for the invoice number and sale amount fields so their values can be used in comparisons. Include a display method to display the invoice number, sale amount, and tax information. Next, implement the SortPurchase Array program that declares an array of five Purchase objects and prompt a user for their values. Then, in a loop that continues until a user inputs a sentinel value of Z, ask the user whether the Purchase objects should be sorted and displayed in invoice number order or sale amount order by entering the values of I and S respectively. An example of the program is shown below: Enter invoice number >> 104 Enter sale amount >> 456 Enter invoice number >> 102 Enter sale amount >> 400 Enter invoice number >> 103 Enter sale amount >> 24.50 Enter invoice number >> 101 Enter sale amount >> 275 Enter invoice number >> 100 Enter sale amount >> 300 Sort Purchases by (I) nvoice number, or (S)ale amount? S Sorted by sale amount Invoice #103 Amount of sale: $24.5 Tax: $1.225 Invoice #3101 Amount of sale: $275.0 Tax: $13.75 Invoice %100 Amount of sale: $300.0 Tax: $15.0 Invoice #102 Amount of sale: $400.0 Tax: $20.0 Invoice #104 Amount of sale: $456.0 Tax: $22.8 Sort Purchases by (I) nvoice number, or (S)ale amount? or enter Z to quit >> Z Grading Write your Java code in the area on the right. Use the Run button to compile and run the code. Clicking the Run Checks button will run pre-configured tests against your code to calculate a grade. Purchase.java SortPurchasesArray.ja... + 1 public class Purchase 2 { 8 9 1234567 0 0 0 12345678 10 11 { { private int invoice Number; private double sale Amount; private double tax; } private static final double RATE = 0.05; public void setInvoice Number(int num) invoiceNumber = num; public void setSale Amount (double amt) sale Amount = amt; tax = sale Amount * RATE; public double getSale Amount ( ) } { return saleAmount; 19 } 20 public int getInvoice Number() 21 { 23 } 24 return invoice Number; public void display() 29} 30 } 222222222228 25 26 { System.out.println("Invoice #" + invoice Number + "I Amount of sale: $" + sale Amount + Tax: $" + tax); Purchase.java Sort PurchasesArray.ja... + 1 import java.util.Scanner; 2 public class SortPurchasesArray { 3 public static void main(String[] args) { 4 5 } 6 8 9 10 // Write your code here public static void sortBySale Amount (Purchase[] array) { // Write your code here } public static void sortBy Invoice (Purchase[] array) { // Write your code here public static void display(Purchase[] p, String msg) { // Write your code here 11 } 12 13 14 } 15 } 16
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started