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

This program will help you start doing GUI programming, and is a good example of 2D arrays. Mine Sweeper is a classic game that is played on a 2D grid of cells. At the beginning of

Colossus has just purchased a computer for its new automated reservation system. You have been asked to program the new system.  You are to write a program to assign seats on ea

I need Java expert with tomcat tuning experience Project Description: Require a Java expert to fix memory issues with tomcat. Skills required: Java, Apache

Mine craft plug-in Coder Project Description: Some custom plugging for my Mine craft server. Skills required: Java, Editing

Project Description: Our project consists of a plain application, both for iPad/iOS (Newsstand app) and Android 4.x which will download PDF magazines from the internet, after ha

Consider the following code? What input is needed for x in order for the sum variable that is output at the end of the code to be 12 ? (In other words: what do I need to make X be

The SwitchAction class gives a means to switch from a resource in one module to another resource in a dissimilar module. SwitchAction is useful only if you have multiple modules in

What is an intelligent system? Intelligent systems are the programs established to perform complicated jobs in which reflect human brain and thoughts. If the algorithms are too m

1. The purpose of this problem is to practice using generics.  Create a generic class with a type parameter that simulates drawing an item at random out of a box. For exampl