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

Assignment Help:

* 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") }


Related Discussions:- Program using a data structure to represent a set

Write html and javascript code which displays a textbox, Write HTML and Jav...

Write HTML and JavaScript code which displays a textbox and button on a web page? While user enters text in the text box and clicks the button it displays in that text in the m

What happens to static fields of class during serialization, What happens t...

What happens to the static fields of a class during serialization? There are three exceptions in which serialization does not necessarily read and write to the stream. These

Calling the function, You may call function from any other place into your ...

You may call function from any other place into your JavaScript code. After the function is executed, the control goes back to other script which called it.  alert('Example 1: t

What are the various struts tag libraries, The Struts tag libraries are: ...

The Struts tag libraries are: ? HTML Tags ? Logic Tags ? Template Tags ? Bean Tags ? Tiles Tags ? Nested Tags

Explain what is object in java language, Explain what is Object in JAVA lan...

Explain what is Object in JAVA language? They are foundation of object oriented language. They are data structure holds data fields and properties and methods

Android app implemented on a website, iPhone /Android app implemented on a ...

iPhone /Android app implemented on a website Project Description: I need someone to implement an iPhone/Android app onto a website page, So users can be able to use the Ap

What do mean by synchronized and synchronized statements, What do mean by ...

What do mean by synchronized methods and synchronized statements ?

Write a java client by using arraylists, 1. The purpose of this problem is ...

1. The purpose of this problem is to practice using ArrayLists.Write a Java client file containing a mainmethod plus other methods as needed to solve the following problem (no clas

Compiler design limit the loops, Problem : Compiler Design - Limit the loop...

Problem : Compiler Design - Limit the loops Rajni is a newbie to the programming and while learning the programming language he came to know the following rules: ???• Each program

Develop a customer relationship management system, You are a newly recruite...

You are a newly recruited programmer, working for an IT company. This company won a contract to develop a Customer Relationship Management System (CRM) for a major retailer. The CR

Write Your Message!

Captcha
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