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

Program for using arraylists in two ways, In this lab, you will practice us...

In this lab, you will practice using ArrayLists in two ways.  The first is in the problem domain class Question.java (see the UML diagram shown below) which contains data for trivi

Write an application for a video store, Do you provides a Complete source C...

Do you provides a Complete source Codes for this application: " a. Write an application for a video store. Place the names of 10 of your favorite movies in a combo box. Let the use

Need cocos2d-x developer - puzzle game, cocos2d-x puzzle game for kids P...

cocos2d-x puzzle game for kids Project Description: I am seeking a skilled, reliable, and not very expensive cocos2d-x developer (with experience with iOS, Android, and prefe

Website for swapping and selling books, Website for swapping/selling books ...

Website for swapping/selling books Project Description: Seeking a website where students can sell and buy books. I want them to swap books as well. Payment options are requir

Explain any five buzz words in java, Question 1 Explain any five buzz w...

Question 1 Explain any five buzz words in Java 2 Explain exception classes and also explain common exceptions in java 3 Explain primitive and abstract data type in java

Calculates number of negative and positive numbers in array, Question 3 ...

Question 3 Using this line: var posneg : array [1..15] of integer; Write a program that calculates the number of negative and positive numbers in the array. Users will

Uses of fileinputstream and fileoutputstream, Java Programming 1. Write...

Java Programming 1. Write a program in Java to find the highest of any five numbers. How do you compile and execute this Java program? 2. Write a program to explain the Exce

Java program that reads in a file of products, Write a Java program called ...

Write a Java program called SalesInfoMiner that reads in a file of products, stored in text format (2 lines per entry). The program must then read in information about past sales t

Cross platform stock market game, Cross platform stock market game Proje...

Cross platform stock market game Project Description: I want someone to develop a simple stock market game. This will mainly be a facebook and android app, face book being mo

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