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

  Program for insertion sort and selection sort algorithms

Write a program involving the insertion sort, merge sort and selection sort algorithms.

  Php code to add-delete product using ajax programming

PHP Code to add a new product and delete a existing product Implement AJAX Programming based solutions to write code to add a new product to the database.

  Application to print the sum of cubes

Write down the application to print the sum of cubes. Prompt for and read two integer values and print sum of each value raised to third power.

  Application to convert kilometers in miles

Application will input number of kilometers, compute number of miles, and display number of miles. You will use a constant to store the kilometers-to-miles conversion factor.

  Develop logic to accept number of passengers-zones as input

Develop the logic for a program that accepts the number of passengers and zones crossed as input. the output is the ticket charge.

  Timer interrupt to coordinate peripherals on microcontroller

The timer interrupts to coordinate peripherals on the microcontroller. Use code from prior labs to drive the peripherals and will make minor modifications to use the interrupts.

  Create logic for program to enter each household size

Create logic for a program that allows a user to enter each household size and find out the mean and median household size in Marengo.

  Designing the site links

Company needs to be able to schedule the time of day when the connections are available for replication. Replication should not occur during peak business hours. When designing the site links, which of the following options should you use?

  Appropriate for two classes to inherit from superclass

CDs and DVDs have several common characteristics. Would it be appropriate for these two classes to inherit from a common superclass?

  Implementing class called card for standard playing card

Design and implement a aclass called Card that represents a standard playing card. each card has a suit and a face value.

  Creating website-based sales system for retail firm

Assume that you have been hired to create website-based sales system for large international retail sales firm.

  Writing program of long term parking

Write an enitre program about the long term parking, and calculate the parking total fare.

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