Program for write a class with the header, JAVA Programming

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/25/2013 5:42:58 AM | Location : United States







Related Discussions:- Program for write a class with the header, Assignment Help, Ask Question on Program for write a class with the header, Get Answer, Expert's Help, Program for write a class with the header Discussions

Write discussion on Program for write a class with the header
Your posts are moderated
Related Questions

How does an exception permeate through the code? An unhandled exception moves up the method stack in search of a matching When an exception is thrown from a code which is wrapp

Complete Back end and Front End Development Project Description: This work is a part of ongoing project. The need is to prepare and integrate the web part of this project.

Explain what is Naming Applets in java applets? You can give an applet a name by using the NAME attribute of the APPLET element. This allows communication between different app

While you declare a variable in a function, the variable can be accessed within that function only.  While you exit the function, the variable is destroyed.  These variables are ca

Describe about Applet Security? The possibility of surfing the Net, wandering across a random page, playing an applet and catching a virus is a fear in which has scared several

Normal 0 false false false EN-US X-NONE X-NONE      Obj ec t Ori e n

Modify both of the above clients (to write separate clients) to extract the exchange rate from a live web service that performs currency conversion. You can choose a Java or a .NET

Give an example for Passing Arguments to Methods ? class Car { String licensePlate = ""; // e.g. "New York 543 A23" double speed = 0.0; // in kilometers per h

Java program need to compile Project Description: i have one program required to compile to run it . Skills required: Java