Program using a data structure to represent a set, JAVA Programming

* Using a data structure to represent a set

* Writing and using a checked exception

* Extending the Exception class

What should you upload via Blackboard?

The files, SET.java, OrderedPair.java, and OrderedPairException.java.

   The current version of SET.java contains compiler errors that should be resolved asyou write the code for this project.

Coding Standards

*At most one return in each method

* Do not use the break, continue or goto keywords

* Write comments for any method you write

* If the main method generates an OrderedPairException then display the message returned by the getMessage method.

* Use try-catch blocks to catch exceptions in the main method.

* Test your code by using the SET.java file posted online.

PART1:

Write a class with the header

public class OrderedPair>

implements Comparable>

instance variables

private Key x

private Key y

constructor

publicOrderedPair(Key x, Key y) // initialize the instance variables

methods

(i) accessor and mutator methods for the instance variables.

(ii) publicintcompareTo(OrderedPair s)

if (this.x  is not equal to s.x) then return x.compareTo(s.x)

else return y.compareTo(s.y)

(iii)  public String toString() - returns a String that represents x and y as an ordered pair.  For instance, if x = "cat " and y = "dog ", then this method returns  the String, "(cat , dog ) ". 

PART2

A class with the header

public class OrderedPairException extends Exception

This class has a constructor with the following header

publicOrderedPairException(String msg)

The only statement in this constructor uses the parameter, msg, to invoke the constructor in the Exception class.

PART3:

Add the following methods to the SET class

public SET difference(SETst)

Returns the complement of this set with the set object represented by the parameter,

st.  (In order words, return this - st)

public void display()

Displays the contents of this set. Use the toString method to display each element in the set.  If the set is null or it's empty then display "Empty Set".

public SetorderedPairs(SETst) throws OrderedPairedException

Returns a set consisting of the ordered pairs in this set and the set represented by the parameter, st.

If this set is null or it's empty then throw an OrderedPairException that contains the message "First Coordinate Set is Null".

If the set represented by the parameter st is null or it's empty then throw an

OrderedPairException that contains the message "Second Coordinate Set is Null".

Example  if c = {"A", "B", and "C"} and d = {"X", "Y"}  then the set of order pairs is

{ ("A", "X"), ("A", "Y"), ("B", "X"), ("B", "Y"), ("C", "X"), ("C", "Y") }

Posted Date: 3/28/2013 1:39:02 AM | Location : United States







Related Discussions:- Program using a data structure to represent a set, Assignment Help, Ask Question on Program using a data structure to represent a set, Get Answer, Expert's Help, Program using a data structure to represent a set Discussions

Write discussion on Program using a data structure to represent a set
Your posts are moderated
Related Questions
Project Description: Overview I am seeking an Oracle ADF mobile app and web service to be created that takes a list of contacts stored on an Android mobile phone or tablet an

In Java not all classes must be described separate from each other. You may put the definition of one class under the definition of another class. The class inside class is called

Need Mahjong puzzle game I want someone to make this game ( Mahjong puzzle game) for me in Android ONLY. If you have high level programming knowledge in Android then please b

how i made a calculator in java plz tell help me

Explain java.lang.string library in java? Strings are objects. Specifically they're instances of the class java.lang.String . This class has several methods which are useful f

Super() Constructer: It is used to call constructor of parent class. Should be the first statement in the body of constructor. Using this we can access private variables

eAgro Portal Project: Technology Used: Java Server Faces, JSR 168 Specification, Websphere Portal Server5.0, DB2 database And Rational Application Developer, Jasper Report Too

Explain data entry issues? DATA ENTRY: There is new data entered every day. New customers are added every day. Some of the data entry needs the manual entry within computer s

can i have code on this assignment: The code in the main method should do the following: 1. Prompt the user for a string input value for the amount in dollars and store it in a va

What is the basic difference among Publish Subscribe model and P2P model? Ans) Publish Subscribe model is typically used in one-to-many situation. It is unreliable but very quic