This is the question I am stuck on - In the exercises in Chapter 6, you created a class named Purchase. Each Purchase contains an invoice number, amount of sale, amount of sales tax, and several methods. Add get methods for the invoice number and sale amount fields so their values can be used in comparisons. Next, write a 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. This is the code I have -  public class Purchase {    private int invoiceNumber;    private double saleAmount;    private double tax;    private static final double RATE = 0.05;    public void setInvoiceNumber(int num)    {       invoiceNumber = num;    }    public void setSaleAmount(double amt)    {       saleAmount = amt;       tax = saleAmount * RATE;    }    public double getSaleAmount()    {       return saleAmount;    }    public int getInvoiceNumber()    {       return invoiceNumber;    }    public void display()    {       System.out.println("Invoice #" + invoiceNumber +          "  Amount of sale: $" + saleAmount + "  Tax: $" + tax);    } }   -------------------------------------------------------------------------- import java.util.Scanner; public class SortPurchasesArray {     public static void main(String[] args) {         // Write code here     }     public static void sortBySaleAmount(Purchase[] array) {         // Write code here     }     public static void sortByInvoice(Purchase[] array) {         // Write code here     }     public static void display(Purchase[] p, String msg) {         // Write code here     } }

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 7PE
icon
Related questions
Question

This is the question I am stuck on -

In the exercises in Chapter 6, you created a class named Purchase. Each Purchase contains an invoice number, amount of sale, amount of sales tax, and several methods. Add get methods for the invoice number and sale amount fields so their values can be used in comparisons.

Next, write a 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.

This is the code I have - 

public class Purchase
{
   private int invoiceNumber;
   private double saleAmount;
   private double tax;
   private static final double RATE = 0.05;
   public void setInvoiceNumber(int num)
   {
      invoiceNumber = num;
   }
   public void setSaleAmount(double amt)
   {
      saleAmount = amt;
      tax = saleAmount * RATE;
   }
   public double getSaleAmount()
   {
      return saleAmount;
   }
   public int getInvoiceNumber()
   {
      return invoiceNumber;
   }
   public void display()
   {
      System.out.println("Invoice #" + invoiceNumber +
         "  Amount of sale: $" + saleAmount + "  Tax: $" + tax);
   }
}
 
--------------------------------------------------------------------------
import java.util.Scanner;
public class SortPurchasesArray {
    public static void main(String[] args) {
        // Write code here
    }
    public static void sortBySaleAmount(Purchase[] array) {
        // Write code here
    }
    public static void sortByInvoice(Purchase[] array) {
        // Write code here
    }
    public static void display(Purchase[] p, String msg) {
        // Write code here
    }
}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage