Purchase Solution

Java solution to verify records are in alphabetical order

Not what you're looking for?

Ask Custom Question

Dear OTA,

I need a Java solution that can verify if records are in alphabetical order based on last name then first name. I need this solution in 2 classes:

1. One with the main method that prompts the user for the input filename (merchants.txt). If the input file cannot be opened, the method should continue to reprompt the user for the correct filename, until the file can be opened. The file should be read, and the method should verify that the file is in ascending order. If it is not, an appropriate error message should be displayed, and the program should terminate. As the merchant records are read in, they should be displayed on the screen.

2. The second class should be named "Merchant" and I want it to implement the predefined interface "Comparable". Its instance variables should include first name, last name, an integer number of orders completed, and a floating-point rating average. This class should contain the following methods:

- A method "inputFile" that reads in a merchant record from a file. All the data fields should be separated by at least one space. The order of the fields is first name, last name, orders, and rating.

- A method "displayOutput" that writes out a merchant record to the screen. The name should be output last name first, separating the last and first names with a comma.

- A method "compare_To" that compares two merchant records. I just need the names compared. The last name is more significant than the first. The method should return a -1 if the 1st name is less than the 2nd, a 0 if they are equal, and a 1 if the 1st name is greater than the next name.

- A method "equals_To" that compares two merchants. I just need the names compared as with the compare_To method.

Lastly, close the file.
Thanks!

Attachments
Purchase this Solution

Solution Summary

A Java solution to verify records are in alphabetical order is provided. The solution is in two classes.

Purchase this Solution


Free BrainMass Quizzes
C++ Operators

This quiz tests a student's knowledge about C++ operators.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Javscript Basics

Quiz on basics of javascript programming language.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.