Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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

Java, Programming

  • Category:- Java
  • Reference No.:- M9532529

Have any Question?


Related Questions in Java

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Operating systems assignment -problem 1 sharing the bridgea

Operating Systems Assignment - Problem 1: Sharing the Bridge A new single lane bridge is constructed to connect the North Island of New Zealand to the South Island of New Zealand. Farmers from each island use the bridge ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As