A Mergeable Interface Some objects can be combined with other objects of the same type to create larger objects of the same type. This is not the case with Remote or Film objects, but it is the case with String s, MusicCollection s, or ClassList s. a. Defi ne a Mergeable interface with one method Object merge(Object x).

A Mergeable Interface Some objects can be combined with other objects of the same type to create larger objects of the same type. This is not the case with Remote or Film objects, but it is the case with String s, MusicCollection s, or ClassList s. a. Defi ne a Mergeable interface with one method Object merge(Object x). b. Design a class IntegerSet that implements Mergeable . IntegerSet stores a set of integers. Methods of IntegerSet should include: void printElements(); int size(); boolean elementOf(int x); sim23356_ch12.indd 580 12/15/08 6:52:17 PM Chapter 12 Inheritance 581 c. Defi ne merge(Object x) so that if x and y belong to IntegerSet then x.merge(y) returns a reference to an IntegerSet, z , containing the integers in x and/or y. Set z contains no duplicates . For example, if x {1, 2, 3, 4, 5} and y {3, 4, 5, 6, 7, 8} then z {1, 2, 3, 4, 5, 6, 7, 8}. d. A particular lottery allows people to play any set of numbers from 1 through 1,000,000. Each number played costs $1. There is one winning number chosen each week. A group of friends play the lottery, and each one has some set of favorite numbers. Possibly, some of the friends have chosen the same numbers. They decide to pool their numbers and split the winnings if any one of their numbers wins. Write a test class that creates three IntegerSet objects containing the lottery numbers played by three different friends. Your test class should create a merged set from the three sets and print out all the numbers in it and how much it will cost to play these numbers (i.e., how many numbers).

No Answer
Programming in Java 0 Answer Kashif Asghar

Write an abstract Box class that has three integer dimensions : length, width, and depth , and two methods: surfaceArea() and volume().

Write an abstract Box class that has three integer dimensions : length, width, and depth , and two methods: surfaceArea() and volume(). Box should implement the Comparable interface, but leave compareTo(...) undefi ned. That is, compareTo(…) is an abstract method.

Create two subclasses of Box: BoxArea and BoxVolume . Each of these subclasses extends Box and does nothing extra except implements the abstract method compareTo(...) .

Note that since Box implements Comparable , the derived classes BoxArea and BoxVolume do not also need to explicitly implement Comparable , but they do need to implement compareTo(…).

• BoxArea defi nes compareTo(...) by comparing surface areas.
• BoxVolume defi nes compareTo(...) by comparing volumes.

Write a class with a single static method public static boolean orderedUp( Comparable[] x, int size) that determines whether or not the elements of Comparable array x are in strict ascending order.

Write a test class with a main() method that asks the user to enter three dimensions for each of fi ve different boxes. Create two arrays of BoxArea and BoxVolume , each containing the data for these fi ve boxes.

Your test class should print a message indicating whether or not the boxes in each array are in strict ascending order according to the appropriate compareTo(…) methods.

No Answer
Programming in Java 0 Answer Kashif Asghar

What mass of K2CO3 is needed?

What mass of K2CO3 is needed to prepare 200 mL of a solution having a potassium ion concentration of 0.150 M?

Solved
Organic Chemistry 1 Answer Anonymous(s) Post

What is the entropy of the discrete-time source in bits/output (sample)? What is the entropy in bps (bits/second)?

Solved
Electrical Machines 1 Answer Anonymous(s) Post

Cash Budget for the Month of April.

An Ltd. Projects Budgeted sales and purchase data for March and April are as follows:

 

March

April

Sales

Rs 450000

500000

Purchases

Rs 325000

375000

Salaries

Rs.75000

85000

Office Rent

Rs 65000

75000

Bed Debt Expenses

5000

7000

Depreciation expense

7000

7000

Cash Balance at End

Rs.150000

    __

An Ltd. offers its customers to pay 40% cash and pay 60% in next month. However, 30% payment for purchases is made on cash and remaining is paid in next month. All other expenses are paid when incurred.

Required:
Cash Budget for the Month of April.          

Solved
Accounting Equation 1 Answer Anonymous(s) Post