a) Define an interface called 'Function' using Java's Generic Types. The interface should have two methods....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
a) Define an interface called 'Function' using Java's Generic Types. The interface should have two methods. The first method is compute(), which takes input of type A and produces output (as return-type) of type B. The second method is printName(), which prints the name of its implementing class. [4 marks] b) Define an abstract class called 'AbstractFunction' that implements the Function interface. It should implement printName() method. The method compute() should be defined as abstract. [5 marks] c) Define a class called 'DuplicateFunction' that extends the AbstractFunction class. It should implement the compute() method, which takes a String as input and returns another String by duplicating the input string. [4 marks] d) Define a class called 'RepeatFunction' that extends the AbstractFunction class. It should define two fields, an integer 'count' and a function 'fun' (of type Function). It should implement the compute() method, which repeatedly calls the fun's compute() method for the 'count' number of times. [8 marks] e) Suppose the main() method in a test class is as follows. What is the output? public static void main(String[] args) { } Duplicate Function df = new Duplicate Function (); Repeat Function rf = new Repeat Function (1, df); System.out.println (rf.compute ("Object Orientation")); a) Define an interface called 'Function' using Java's Generic Types. The interface should have two methods. The first method is compute(), which takes input of type A and produces output (as return-type) of type B. The second method is printName(), which prints the name of its implementing class. [4 marks] b) Define an abstract class called 'AbstractFunction' that implements the Function interface. It should implement printName() method. The method compute() should be defined as abstract. [5 marks] c) Define a class called 'DuplicateFunction' that extends the AbstractFunction class. It should implement the compute() method, which takes a String as input and returns another String by duplicating the input string. [4 marks] d) Define a class called 'RepeatFunction' that extends the AbstractFunction class. It should define two fields, an integer 'count' and a function 'fun' (of type Function). It should implement the compute() method, which repeatedly calls the fun's compute() method for the 'count' number of times. [8 marks] e) Suppose the main() method in a test class is as follows. What is the output? public static void main(String[] args) { } Duplicate Function df = new Duplicate Function (); Repeat Function rf = new Repeat Function (1, df); System.out.println (rf.compute ("Object Orientation"));
Expert Answer:
Answer rating: 100% (QA)
a Define an interface called Function using Javas Generic Types The interface should have two methods The first method is compute which takes input of ... View the full answer
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
What is the Sales and Cost, given following information: Revenue = 10 million Operational Expense = 8.1 m Amortization = 43 million Dep = 50 million Total Interest Bearing Debt = 30 million Cash...
-
In mathematics, a magma is a type of algebraic structure that has a set of elements, all of the same type, and one binary operation. Such a pairing of a set (ex. Positive integers) with this...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
An inclined manometer is a useful device for measuring small pressure differences. The formula given in Section 3.4 for the pressure difference in terms of the liquid-level difference h remains...
-
The point charges in FIGURE 19-42 have the following values: q1 = +2.1 C, q2 = +6.3 C, q3 = -0.89 C. (a) Given that the distance d in Figure 19-42 is 4.35 cm, find the direction and magnitude of the...
-
The Bolognese Corporation is in the process of setting price standards for its direct materials. Polymer clay is used in one product. The polymer clay is purchased for $14 per kilogram. The Bolognese...
-
Presented below are the consolidated financial statements of The Mann Corporavane, CHECK tion as of year-end 2016 and 2015. Required Using the above financial data, prepare the statement of cash flow...
-
The following information is available for Shanika Company for 2016: Instructions 1. Prepare the 2016 statement of cost of goods manufactured. 2. Prepare the 2016 income statement. Inventories...
-
Conquistador Hurricane Sales price $5,600 $3,800 Variable cost of goods sold (3,530) (2,550) Manufacturing margin $2,070 $1,250 Variable selling expenses (782) (452) Contribution margin $1,288 $798...
-
Suppose that East-West airlines is a small airline that offers passanger air transportation between two major east coast cities, namely Boston and New York; two major west coast cities , namely San...
-
Key Enterprises started the year with the following: Assets $100,000; Liabilities $30,000; Common Stock $60,000; Retained Earnings $10,000. During the year, the company earned revenue of $5,000, all...
-
Malaysia has achieved tremendous annual economic growth rate since 1990. Prepare a suitable diagram to show the trend of GDP growth rate since 1990 to 2022. From the diagram, critically evaluate and...
-
What type of network is used for an online bank (E-Banking) or in other words an online banking company? Example of online banking companies like Chime, Ally, Nerd Wallet Personal Area Network (PAN)...
-
How does transformational leadership theory work? how does transformational leadership help organizations to develop organizational behavior? How does transformational leadership effects on...
-
Have a program that will compile but has some run time errors involving number formating. I was hoping you could help me out with this. its involving the section with "parseInt". The section is at...
-
Cassidy's "Demand Doctor" is none other than John Maynard Keynes, a major economic theorist we talked about earlier. Keynes says that a growing economy requires strong aggregate demand, and in a time...
-
On January 2, 2020, Swifty Corporation issued $2,200,000 of 10% bonds at 99 due December 31, 2029. Interest on the bonds is payable annually each December 31. The discount on the bonds is also being...
-
What recommendations would you make to Big Four firms to help them (1) avoid confrontations with governmental officials in an authoritarian society and (2) deal effectively with such confrontations...
-
Repeat Programming Project 7, but write the program as JavaFx application. Use a constant for the initial velocity of the ball. Draw a circle for the position of the ball at each second. The...
-
Write a recursive method that will compute cumulative sums in an array. To find the cumulative sums, add to each value in the array the sum of the values that precede it in the array. For example, if...
-
Repeat Programming Project 8 in Chapter 1, but add yes-or-no dialogs to allow the user to make the following color changes: Change the color of the solid center circle from black to red. Change the...
-
Assume that you have 890 total equivalent units of materials and 863 total equivalent units of conversion costs. Also assume that your beginning inventory is composed of \($3,390\) of materials and...
-
Assume that you have completed and transferred 800 units out of your department during the period and that you have determined your average cost per equivalent unit of direct materials to be...
-
Assume that your ending inventory is composed of 90 equivalent units of materials and 63 equiva- lent units of conversions costs and that you have determined your average cost per equivalent unit of...
Study smarter with the SolutionInn App