Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment you will write a superclass and subclass. You will be free to choose the names and contents for these classes as long

For this assignment you will write a superclass and subclass. You will be free to choose the names and contents for these classes as long as your classes meet the specifications listed below. Perhaps theres some pairing (superclass and subclass) that you think would be helpful to you in some other situation (perhaps connected with a hobby, your job, ).

You will also write a test program to show that your classes perform as designed.

The superclass will contain:

  • At least two instance variables (you may choose to have more):
    • One instance variable of a primitive data type (e.g., int, double, boolean, char).
    • One instance variable of the String data type.
  • Two constructors:
    • A default constructor that will set the objects instance variables to some default settings.
    • A full constructor:
      • This constructor will receive data for all the objects instance variables as input parameters and will store this data in the objects instance variables.
  • .get() and .set() methods for the objects instance variables.
  • A .toString() method that displays the current contents of the objects instance variables between square brackets.
  • A .compareTo() method that involves at least the two required instance variables in the ordering of objects.
  • A static .enterObject() method that collects data for an object, instantiates the object and returns its address to the calling method.
  • There may be other methods as you desire.

The subclass will contain:

  • At least two instance variables (you may choose to have more):
    • One instance variable of a primitive data type (e.g., int, double, boolean, char).
      • This data type will be different than the primitive data type in the superclass.
    • One instance variable of the String data type.
  • Two constructors:
    • A default constructor that will set the objects instance variables to some default settings.
    • A full constructor:
      • This constructor will receive data for all the objects instance variables as input parameters and will store this data in the objects instance variables.
  • .get() and .set() methods for the objects instance variables.
  • A .toString() method that displays the current contents of the objects instance variables between square brackets.
  • A .compareTo() method that involves at least the two required instance variables in the ordering of objects.
  • A static .enterObject() method that collects data for an object, instantiates the object and returns its address to the calling method.
  • There may be other methods as you desire.

You will also write a test program to demonstrate that your superclass and subclass perform as designed. The test program will perform the following tasks (at least):

  • Allow the user to set up a superclass object and display (using superclass .toString() method) the superclass object set up.
  • Allow the user to set up and subclass object and display (using the subclass .toString() method) the subclass object set up.
  • Allow the user to set up a second subclass object and display (again using the subclass .toString() method) the second subclass object set up.
  • Compare the two subclass objects set up and display them (again using the subclass .toString() method) the two objects in smaller larger order.

NOTE: Although your superclass and subclass will both contain .get()/.set() methods, you do not need to specifically show that these operate as designed (thats too much coding); the reader can tell if they are written correctly. However, if any of these are called in the program while performing other tasks, be sure they operate correctly.

Your package of three classes (superclass, subclass, test program) will also display your ability to use Javas exception-handling statements to handle exceptions that may arise; it is your choice as to where you position these instances as long as both situations occur.

  • There will be one instance where an exception is caught and handled in the method where it originates.
    • This could be in the superclass, subclass or test program.
  • There will be a second instance where an exception is thrown and handled in the method that called the method in which the exception occurs.
    • The exception will occur in a method of the superclass or the subclass and will be handled in the test program.

So that a reader can find this code easily, put comments in the code to identify these occurrences. Dont expect the reader to search for them.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions

Question

=+Who are they?

Answered: 1 week ago

Question

=+Understand the fi eld of comparative IHRM.

Answered: 1 week ago

Question

=+j Understand different types of regions in the world.

Answered: 1 week ago