Program for write a class with the header, JAVA Programming

Assignment Help:

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 for write a class with the header

Nonrecursive implementations of the min() and floor() method, Write nonrecu...

Write nonrecursive implementations of the min() and floor() methods in BST.java. Make sure to use only one return in your method. Use an insertion sort (discussed in class) to s

What does it mean that a method or class is abstract, What does it mean tha...

What does it mean that a method or class is abstract? An abstract class cannot be instantiated. Abstract methods may only be included in abstract classes. However, an abstract

Malformedurlexception and unknownhostexception, When MalformedURLException ...

When MalformedURLException and UnknownHostException throws? Ans) When the particular URL is not connected then the URL throws MalformedURLException and If InetAddress? methods g

Difference between bean factory and application context, On the surface, an...

On the surface, an application context is similar as a bean factory. But application context offers much more.. ? Application contexts give a means for resolving text messages,

Define object-to-relational (o/r) mapping, Object-to-Relational (O/R) mappi...

Object-to-Relational (O/R) mapping : There are various ways to persist data and the persistence layer is one of the most important layers in any application development. O/R ma

Recursive Division Maze Generation, can you tell me what the code for a 2d ...

can you tell me what the code for a 2d random java array using Recursive Division Maze Generation

Describe features of spring, Here are some features of spring:- ? Lightw...

Here are some features of spring:- ? Lightweight: spring is lightweight when it comes to size and transparency. The essential version of spring framework is around 1MB. And t

Discuss features of java, Question 1 Discuss features of JAVA Question...

Question 1 Discuss features of JAVA Question 2 What are primitive data types? Discuss Question 3 Explain data conversion function ValueOf ()? Question 4 What are th

What do you understand by instantiating an object, Question: (a) To be ...

Question: (a) To be considered object-oriented(OO), a language should support abstraction, encapsulation, inheritance and polymorphism. Explain briefly each of the terms in

Session scope and Request scope, What is the difference among session scope...

What is the difference among session scope and request scope when saving formbean? Ans) When the scope is request, the values of formbean would be there for the current request.

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