Which instance variables from the parent class can be used

Assignment Help Programming Languages
Reference no: EM131270842

Assignment

Inheritance

Objective - determine which instance variables and methods from the parent class can be used in a derived class. Use calls to super when you can, for example, in the SortedIntList constructor and in the SortedIntList toString() method (Add a heading to the printed list which says "Sorted List" and then call the IntList toString() method).

Think about this - what is the most efficient way to maintain the sorted list? You could add an element to the sorted list and resort the list each time (inefficient) or ..... Turn in the final source for ListTest and SortedIntList. Also turn in the output leaving the data given for IntList and the following 3 sets of data for SortedIntList (Data from SortedIntList objects should print out in ascending sequence.):

100, 50, 200, 25

7,6,5,4,3,2,1

1, 105, 63, 41, 250, 77, 6

A Sorted Integer List

File IntList.java contains code for an integer list class. Save it to your directory and study it; notice that the only things you can do are create a list of a fixed size and add an element to a list. If the list is already full, a message will be printed. File ListTest.java contains code for a class that creates an IntList, puts some values in it, and prints it. Save this to your directory and compile and run it to see how it works.

Now write a class SortedIntList that extends IntList. SortedIntList should be just like IntList except that its elements should always be in sorted order from smallest to largest. This means that when an element is inserted into a SortedIntList it should be put into its sorted place, not just at the end of the array. To do this you'll need to do two things when you add a new element:

Walk down the array until you find the place where the new element should go.·

Since the list is already sorted you can just keep looking at elements until you find one that is at least as big as the one to be inserted.

Move down every element that will go after the new element, that is, everything from the one you stop on to the end. This creates a slot in which you can put the new element. Be careful about the order in which you move them or you'll overwrite your data!

Now you can insert the new element in the location you originally stopped on.

All of this will go into your add method, which will override the add method for the

IntList class. (Be sure to also check to see if you need to expand the array, just as in the IntList add method.) What other methods, if any, do you need to override? To test your class, modify ListTest.java so that after it creates and prints the IntList, it creates and prints a SortedIntList containing the same elements (inserted in the same order). When the list is printed, they should come out in sorted order.

Reference no: EM131270842

Questions Cloud

Relationship between conflict and group member diversity : What are some of the major differences between a virtual and traditional organization? What are the relationship between conflict and group member diversity. The HAC Reduction program is designed to encourage hospitals by reducing what ?
Assigned an important project : You really want to be assigned an important project but worry that your boss will not give it to you. Your boss has expressed concern lately about your ability to complete some less significant tasks. You are upset and feel these tasks are beneath..
Describe your chosen architecture pattern : Describe your chosen architecture pattern. Explain why you selected the architecture of this case study. Explain how your chosen pattern could be applied to this case study.
Healthcare providers have different view of health care law : Do healthcare providers have a different view of health care law than the general population? Is one more skewed than the other and why ?
Which instance variables from the parent class can be used : Determine which instance variables and methods from the parent class can be used in a derived class. Use calls to super when you can, for example, in the SortedIntList constructor and in the SortedIntList toString.
How the agency head is impacted by political environments : Using the e-Activity, discuss one or two current rulings and comment on how the agency head is impacted by one or two political environments in which the agency must operate
An interactive web site kept constantly updated : The Business Driven Technology textbook defines a Data-Driven Website as "an interactive web site kept constantly updated and relevant to the needs of its customers through the use of a database."
Identify the sequence of transformations : What was the average after 3 months - After how many months would be expected that the average mark would be less than 50?
How is sales territory similar to entrepreneurial venture : How is a sales territory similar to an entrepreneurial venture? If a salesperson views his or her territory as an entrepreneurial venture, how might this change the way in which he or she approaches the management of the territory?

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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