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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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