Write program to merge two files that contain polynomials

Assignment Help Programming Languages
Reference no: EM1357715

Write a program that merges two files that contain polynomials. To merge two files, the input files must be in sorted order. The merge operation repetitively selects the smaller value from the two files. When two sorted files are merged, the result will be sorted.

This program should contain three classes. The first class Project1 should contain the two methods described below:

The main method, which calls the checkSorted method twice to verify that each of the input files is sorted in ascending order. It should catch the exception FileUnsorted if it is thrown, display an error message and terminate the program. Otherwise, it then performs the merge operation. The output is to be displayed on the screen.

A class method called checkSorted, which returns a BufferedReader object. The user should supply the name of the input file. The file should be read and it should be verified that the file is in ascending order. If it is not, the exception FileUnsorted should be thrown. Otherwise, after the file has been completely read, it should be closed and reopened to position it at the beginning of the file.

The second class should be a class named Polynomial. It should implement the Comparable interface. The polynomial should be stored as an array of integers. The size of the array should be one more than the highest exponent. This class should contain the following methods.

A constructor.

A class method named input that reads in a polynomial. The buffered reader for the file should be passed to this method as a parameter. The polynomials in the file will be stored as integer pairs that represent a coefficient and its corresponding exponent. For example, 5 3 4 1 8 0 represents the polynomial 5x3 + 4x + 8. They will always be written from the highest exponent to the lowest. Exponents with zero coefficients will be omitted.
A toString method that converts a polynomial to a string. The polynomial 5x3 + 4x + 8 should be converted to the following string "5x^3 + 4x + 8".

A method compareTo that compares two polynomials. The comparison should be similar to the Big-O comparison of methods. 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. The following examples should help explain the ordering:

6x4 + 7x2 + 3 > 20x3 + 8x2 + 10
7x4 + 7x2 + 3 > 6x4 + 17x2 + 7x + 30
6x4 + 9x2 + 3 > 6x4 + 7x +9

The third class should be the exception FileUnsorted. It requires no methods or instance data.

Reference no: EM1357715

Questions Cloud

Compute the intrinsic value of a warrant : The Redford Investment Corporation bought 100 Cinema Corporation warrants one year ago and would like to exercise them today. The warrants were purchased at $24 each,
Explain organizational development consultant : Explain Provide a brief scenario if you were an Organizational Development consultant.
Operating leverage-roe-eva : Explain what operating leverage, ROE, EVA are and how they measure performance. Pick another performance measure of your choice and explain it as well.
Rewards and compensation in recruitment strategy : develop a draft of the Rewards and Compensation portion of the Recruitment and Selection Strategy/Rewards and Compensation Plan for each position and region
Write program to merge two files that contain polynomials : Write a program that merges two files that contain polynomials. To merge two files, the input files must be in sorted order.
Distinguish between moodiness and depression : Many people erroneously believe that teenagers are inherently morose and moody. In fact, it can sometimes be difficult to distinguish between moodiness and depression.
Evaluating financial aspects of the american red cross : I need some help to start in writing a 700-word paper in APA format with references evaluating financial aspects of the American Red Cross. Answering these questions
Dealing with hrm challenges and trends : A new trend for HRM is monitoring work at home employee's utilizing new technology - Strategies for Dealing with HRM Challenges and Trends
What average total force acted on the car : What average total force acted on the car. How far did the car travel during that time.

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

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

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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