Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

80 HR ethics and professional standards.

Answered: 1 week ago

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago