Write program that performs sort by using binary search tree

Assignment Help Data Structure & Algorithms
Reference no: EM131552646

Project Assignmet

1. Specification

Design, write and test a program that performs a sort by using a binary search tree. The program should be able to sort lists of integers or lists of fractions in either ascending or descending order. One set of radio buttons should be used to determine whether the lists contain integers or fractions and a second set should be used to specify the sort order.

The main class P3GUI should create the Swing based GUI shown below. The GUI must be generated by code that you write. You may not use a drag-and-drop GUI generator.

Pressing the Perform Sort button should cause all the numbers in the original list to be added to a binary search tree. Then, an inorder traversal of the tree should be performed to generate the list in sorted order and that list should then be displayed in the Sorted List text field.

In addition to the main class that defines the GUI, you should have a generic class for the binary search tree. That class needs a method to insert a new value in the tree and a method that performs an inorder tree traversal that generates and returns a string that contains the tree elements in sorted order. The insert method does not need to rebalance the tree if it becomes unbalanced. It should allow duplicate entries and it must be written using recursion.

Other methods may be defined if needed.

The third class required for this project is one that defines fractions. It should have a constructor that accepts a string representation of a fraction and a toString method. It must implement the Comparable interface, which means a compareTo method is also required.

A second example of a run of this program is shown below that sorts fractions in descending order:

Note that fractions are to be written with a slash separating the numerator and denominator with no spaces on either side of the slash. Spaces should be used to separate the fractions.

The only error checking required of this program is to check for nonnumeric input or improperly formatted fractions such as 3/4/8. A nonnumeric input should cause a NumberFormatException to be thrown. A malformed fraction should cause a custom exception MalformedFractionException to be thrown. The main class must catch these exceptions and display an appropriate error message as shown below for NumberFormatException (for MalformedFractionException the displayed message should be "Malformed Fraction").

Your program should compile without errors.

The Google recommended Java style guide (https://google.github.io/styleguide/javaguide.html) should be used to format and document your code. Specifically, the following style guide attributes should be addressed: header comments include filename, author, date and brief purpose of the program; In-line comments used to describe major functionality of the code; the meaning and the role of variables and constants are indicated as code comments; meaningful variable names and prompts applied; class names are written in UpperCamelCase; variable names are written in lowerCamelCase; constant names are in written in All Capitals; braces use K&R style.

In addition the following design constraints should be followed: declare all instance variables private; avoid the duplication of code.

2. Submission requirements

Submit the following to the Project 3 assignment area no later than the due date listed in your LEO classroom.

1. All .java source files (no other file types should be submitted). The source code should use Java code conventions and appropriate code layout (white space management and indents) and comments. All submitted files may be included in a .zip file.

2. The solution description document P3SolutionDescription (.pdf or .doc / .docx) containing the following:

(1) Assumptions, main design decisions, error handling;

(2) 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;

(3) A table of test cases including the test cases that you have created to test the program. The table should have 5 columns indicating (i) what aspect is tested, (ii) the input values, (iii) the expected output, (iv) the actual output and (v) if the test case passed or failed. Each test case will be defined in a table row.

(4) Relevant screenshots of program execution;

(5) Lessons learned from the project.

Attachment:- Project-Assignment.pdf

Reference no: EM131552646

Questions Cloud

Determine value of charge-to-mass ratio of the hydrogen ion : You know that one faraday of charge releases one mole of hydrogen atoms. From that fact determine the value of the charge-to-mass ratio of the hydrogen ion.
Based on internal rate of return analysis : DelRay Foods must purchase a new gumdrop machine. Based on an internal rate of return analysis, which machine should be recommended?
Identify a state health policy and the tools : Which would be the most appropriate researchable population for use in your research project?
What would be the fractional increase in the droplet mass : Suppose the charge on a 1-µm radius droplet increased by 3e because it picked up three nitrogen ions.
Write program that performs sort by using binary search tree : Design, write and test a program that performs a sort by using a binary search tree. The GUI must be generated by code that you write.
What is the maximum speed to which they can be accelerated : A cyclotron (Fig.) is an apparatus for accelerating charged particles to very high kinetic energies. Rapidly moving charged particles are coaxed into circular.
Considering the purchase of earth-moving equipment : A land development company is considering the purchase of earth-moving equipment.
Describe the meaning of dual diagnosis : Describe the meaning of dual diagnosis and how it impacts counseling.Classify Gregory's primary and secondary diagnoses.
Periodically raise long term capital pay for capital project : Financial managers must periodically raise long term capital (funding) to pay for capital projects.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  They have collected by interviewing members of a village.

An efficient algorithm is proposed to do this: either it produces proposed dates of birth and death for each of the n people so that all the facts hold true, or it reports (correctly) that no such dates can exist. That is the facts collected by th..

  Discuss when you think a hash table should be used

Discuss when you think a hash table should be used and when you think it should it be avoided. Reply to others with support for or arguments against the use of hash tables in given circumstances.

  Convert the following expression in postfix

Convert the following expression in postfix (reverse Polish notation). Remember the rules of precedence for arithmetic operators. To get full credit, you need to show all work done. i.e. sample snapshot of the stack

  Create a file index in dynamic memory

Write a program that uses the B-tree ADT to create a file index in dynamic memory. When the program starts, it reads the file and creates the B-tree index.

  Describe why full binary tree requires to have node

Describe why. Full binary tree requires to have a node with 0 or 2 children and complete tree have their child starting from left. Choose the one true statement. Every binary tree is either complete or full.

  Compare network-based and host-based ids use in enterprise

Compare and contrast network-based and host-based IDS use in an enterprise. Determine the feasibility and necessity of utilizing one of these IDS implementations over the others.

  Write a recursive method that can generate patterns

COSC 2006 -Data Structures - You should also write a static main method that allows you to test the other seven methods and examine this pattern of asterisks and blanks, and write a recursive method.

  Design a linked list structure

Design a linked list structure Music that contains data fields Name, Artist, Number_of_Songs, and a pointer to the list. Design the structure with three members and fill in data for each member.

  Solve the problem using the selection sort

Write a program that will create an unsorted array with 10 integer elements. you may prompt the user for the elements or you may populate the elements.

  What is the role of data models in database design

What is data integrity, and what is the significance of a lack of data integrity? Define data independence. What is the role of data models in database design?

  Hash values

Suppose these names have the following hash values. Insert them into the extendible hash table shown below. Each leaf can only hold 4 entries.

  How space efficient is your hamming code

Construct a specific error in more than this number of bits and explicitly show that the Hamming algorithm fails to detect the error. How space (number of bits required) efficient is your Hamming code?

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