Different methods of comparison

Assignment Help JAVA Programming
Reference no: EM133432130

Social Networking and Cybersecurity Best Practices

Project

The second programming project involves writing a program that examines a file of polynomials and determines whether the polynomials in that file are in strictly ascending order using two different methods of comparison.

Each line of the input file will contain one polynomial. On each line will be the terms of the polynomial. Each term will be represented as a pair of values. The first element of that pair is a real value that represents the coefficient and the second an integer value, which is its corresponding exponent. For example, 5.6 3 4 1 8.3 0 represents the polynomial 5.6x3 + 4x + 8.3. They are intended to be written from the highest exponent to the lowest, but ensuring that is true is a program requirement. Exponents with zero coefficients will be omitted

The program for this project should consist of four outer classes. The Polynomial class is the first of those four. Instances of the Polynomial class should define an individual polynomial. Polynomial objects should be represented internally by a singly linked list. Each node of that linked list should contain one term of the polynomial consisting of its coefficient and exponent. You are not permitted to use the predefined Java LinkedList class, but instead must create the nodes of the linked list as instances of a static nested class inside the Polynomial class. The Polynomial class must implement both the Iterable and Comparable interfaces. It must have four public methods.

1. A constructor that accepts a string that defines one polynomial in the same format as provided in the input file.

2. A compareTo method that compares two polynomials. If the two polynomials have different highest order exponents, the one with the highest exponent is the greatest. If their highest exponents are the same, their coefficients are compared. If two polynomials have the same highest order exponent with the same coefficients the next highest exponent is examined, and so on.

3. An iterator method that produces an iterator the iterates across the terms of the polynomial from highest exponent to lowest and returns and an object that contains only the coefficient and exponent of the next term.

4. A toString method that converts a polynomial to a string. Terms with 0 coefficients should be omitted entirely. The exponent of the term with an exponent of 1 should omit the exponent and the term with exponent 0 should omit the variable x as well. As an example, the polynomial "5.6 3 4 1 8.3 0" should be converted to the following string "5.6x^3 + 4x + 8.3".

The second class is InvalidPolynomialSyntax, which defines an unchecked exception that contains a constructor that allows a message to be supplied. It is thrown by the constructor of the Polynomial class should the supplied string contain coefficients or exponents of an improper type or should the exponents fail to be listed in strictly descending order.

The third class is OrderedList, which is a utility class that contains two overloaded implementations of a method named checkSorted, which determines whether a List object, supplied as a parameter, is in strictly ascending order. Both methods should be class (static) methods. The first of the overloaded methods should accept a list that contains elements that implement Comparable. The second should instead be supplied an additional parameter that is an object of a class that implements the Comparator interface. Refer to the signatures of the two sort methods in the predefined Java Collections class as a model for how these two methods should be defined. Do not duplicate code, but instead ensure that first overloaded method calls the second.

The fourth outer class is the class that contains the main method. The main method should allow the user to select the input file from the default directory by using an object of the JFileChooser class. It should then populate an ArrayList of objects of type Polynomial as it reads in the lines of the file. As the polynomials are read in, they should also be displayed in the format provided by the toString method. Should the InvalidPolynomialSyntax exception be thrown, it should be caught and a JOptionPane message should be displayed containing the reason for the invalid syntax. The list of polynomials should be then checked to see whether it is in sorted order according to two orderings. The first check is the one that uses the compareTo method of the Polynomial class. We refer to this first ordering as the strong order. The second results from the use of a comparator. We refer to it as the weak order. It should display whether it fails to be sorted by either of both of the two orderings or if it is sorted according to both.

Inside the main class, a named lambda expession should be defined that implements the Comparator interface. Its compare method should consider only the exponents and not the coefficients in comparing the polynomials, much like how functions are categorized by Big-O.

As an example, consider the following list of polynomials:

4.0x3 + 2.5x + 8.0

5.0x4 + 5.0

4.5x4 + 5.7x2 + 8.6

This list fails to be sorted by the strong order that considers both the coefficients and exponents because the third polynomial is less than the second because of the coefficients on the x4 terms. The coefficient on that term in the second polynomial is 5.0, which is greater than 4.5, the coefficient on the corresponding term in the third polynomial.

They are sorted by the weak order that considers only the exponents, however. The third polynomial is greater than the second because the third has a x2 term and the second one does not.

You are to submit two files.

1. The first is a .zip file that contains all the source code for the project. The .zip file should contain only source code and nothing else, which means only the .java files. If you elect to use a package the .java files should be in a folder whose name is the package name. Every outer class should be in a separate .java file with the same name as the class name. Each file should include a comment block at the top containing your name, the project name, the date, and a short description of the class contained in that file.

2. The second is a Word document (PDF or RTF is also acceptable) that contains the documentation for the project, which should include the following:
a. A UML class diagram that includes all classes you wrote. Do not include predefined classes.
You need only include the class name for each individual class, not the variables or methods
b. A test plan that includes test cases that you have created indicating what aspects of the program each one is testing
c. A short paragraph on lessons learned from the project

Reference no: EM133432130

Questions Cloud

What stance would you take in response to the essay prompt : What stance would you take in response to the essay prompt? Which sources might you choose? Why? Are there any specific challenges you would see with this essay
Identity by describing myself as an animal lover : In a world dominated by meta reality of social media, I would define my personal identity by describing myself as an animal lover, someone who loves to travel
What event from history would you like to learn more about : What is something you discovered in one of your other college classes (in the past or currently) that you would like to learn more about.
What are differences between primary and secondary research : What are the differences between primary and secondary research? What are the differences between "scholarly" and "non-scholarly" sources?
Different methods of comparison : CMSC 100 Social Networking and Cybersecurity Best Practices, University of Maryland - examines a file of polynomials and determines whether the polynomials
What does professionalism mean to you in words : What does professionalism mean to you in words? Is incivility common in the workplace? What might be its costs? In some job leads, it states: "no drama".
How can you use the principles in the settings you encounter : Identify a specific ethical standard; perhaps share a specific story in which you showed particularly excellent ethical decision making. Now, consider where
Why dogs are superior to cats, written by an avid dog-owner : An interview with a local pediatric doctor about the rate of flu among local infants An article about why dogs are superior to cats, written by an avid
How will you know the implementation and solution have been : How long will it take? How will you know the implementation and solution have been successful? Where will the solution be implemented?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Which reverses the order of an arrays elements

Write a method named, reverse, which reverses the order of an array's elements without creating another array - elements and then verify the array elements

  Java program that will add the corresponding elements

Develop a Java program that will add the corresponding elements of two 1-dimensional arrays X and Y to produce the 1-dimensional array Z. Arrays X, Y, Z have the same dimension [M].

  Implement a threads and a gui interface

Implement a threads and a GUI interface using advanced Java Swing classes - Implement a JTable to also show the contents of the data file. There are lots of options here for extending your program.

  Sequence of method in vector class

Construct a Vector class implementing a number of vector operations as methods along with a testing program to verify the class is working.

  The frantic pipe layer game

Design the Frantic Pipe Layer game

  What are the merits and demerits of the use of mainframes

write a 200- to 300-word short-answer response to the followingwhat are the advantages and disadvantages of the use of

  Explains the principles of polymorphism and inheritance

You have been tasked with preparing a training document that explains the principles of polymorphism, inheritance, and encapsulation.

  Write a java loop

write a java loop ( of your choice ) that produces exactly the following output to the screen: 2-4-6-8-

  Data structures and algorithms

Code analysis and programming.

  Explain what it means to swallow an exception

Explain what it means to swallow an exception, and why that's almost never an acceptable practice.

  Write a statement that prints the number of characters

Write a statement that prints the number of characters in a String object called myString. Write statements to prompt for and read user's age using Scanner variable

  Prepare a thread function to initialize int array

Prepare a thread function to initialize int array x so that each element receives its index in the array: x[i]=i, and each thread initializes its portion of the array.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd