Question: The folloing to java files input 5 objects into an array and can then be sorted by invoice number or price. Make the following two

The folloing to java files input 5 objects into an array and can then be sorted by invoice number or price. Make the following two modifications:

1. Enhance the program by displaying a menu that asks the user how they want to sort the services menu. 1) Sort by Service Description, 2) Sort by Price, 3) Sort by Time (Minutes), or 0) to Exit.

2. Add a do...while() loop that keeps prompting the user for the next preferred sort order until the user finally chooses 0 to exit

import java.util.Scanner; public class SortPurchasesArray { public static void main(String[] args) { final int size = 5; int i; Purchase[] purchase = new Purchase[size]; Scanner input = new Scanner(System.in); for(i = 0; i purchase[k+1].getInvoice()) { tempPurchase = purchase[k]; purchase[k]=purchase[k+1]; purchase[k+1]=tempPurchase; } } } } private static void sortBySales(Purchase[] purchase) { Purchase temp; for(int i = 0; ipurchase[j+1].getAmount()) { temp=purchase[j]; purchase[j]=purchase[j+1]; purchase[j+1]=temp; } } } } private static void print(Purchase[] purchase) { System.out.printf("%-15s%-10s%-10s ","Invoice","Sales","Tax"); for(int i = 0;i

public class Purchase { private final double tax = .05; private int invoiceNumber; private double saleAmount; private double salesTax; public void setInvoice(int invoiceNumber) { this.invoiceNumber=invoiceNumber; } public void setAmount(double saleAmount) { this.saleAmount=saleAmount; salesTax = saleAmount*tax; } public int getInvoice() { return invoiceNumber; } public double getAmount() { return saleAmount; } public double getTax() { return salesTax; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!