Question
In the exercise 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, ask the user whether the Purchase objects should be sorted and displayed in invoice number order or sale amount order. Save the file as SortPurchasesArray.java.
******NEED HELP WITH THIS PROBLEM CANNOT FIGURE IT OUT********
Explanation / Answer
public class Purchase{ int inv; double sale; double tax; double taxAmount = 0.05; public int getInv() { return inv; } public void setInv(int inv) { inv = inv; } public void setSale(double s) { sale = s; tax = sale * taxAmount; } public double getSale() { return sale; } //display public void display() { System.out.println("Invoice number: " + getInv() + " Sale amount: $" + getSale() + " Tax: $" + tax + " Total: $" + (tax + sale)); } } import java.util.Scanner; public class CreatePurchase{ public static void main(String[] args) { Purchase Purchase(); Scanner input = new Scanner(System.in); do { System.out.print("Please enter you invoice number. This will be a number between 1000 and 8000. "); inv = input.nextInt(); one.setInv(inv); } while(inv < 1000 && inv > 8000); { System.out.println("Please enter the amount of your sale. "); sale = input.nextInt(); } } }