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...
-
A teacher estimates that, of the students who pass a test, 80% will pass the next test, while of the students who fail a test, 50% will pass the next test. Let x and y denote the number of students...
-
Amber Gray tells you that the accountants where she works are real hair splitters. For example, they make a big issue over the difference between a cost and an expense. She says the two terms mean...
-
True or False. Vibration can cause structural and mechanical failures.
-
Chubbs Inc.s manufacturing overhead budget for the first quarter of 2017 contained the following data. Actual variable costs were indirect materials $13,500, indirect labor $9,500, utilities $8,700,...
-
Max goes to Books R Us to buy a book signed by Michael Jordan for $2500. Books R Us advertises the signature as being authentic and provides a certificate of authenticity. When he goes to make the...
-
Write a letter to the Smith's discussing the results of their tax return, remind them of any deduction substantiation rules they need to follow (receipts, mileage log, etc.), offer suggestions for...
-
In his meeting with financial analysts at the beginning of the year, the company's Chief Executive Officer (CEO) predicted that the company's profits would increase by 25% this year.Unfortunately,...
-
An object's average density p is defined as the ratio of its mass to its volume: p = M/V. The earth's mass is 5.94 10 24 kg, and its volume is 1.08 10 12 km 3 . What is the earth's average density?...
-
Which of the following motions could be described by the motion diagram of Figure Q 1.20? A. A hockey puck sliding across smooth ice. B. A cyclist braking to a stop. C. A sprinter starting a race. D....
-
Which of the following motions is described by the motion diagram of Figure QI .21? A. An ice skater gliding across the ice. B. An airplane braking to a stop after landing. C. A car pulling away from...
-
A squirrel in a typical long glide covers a horizontal distance of 16 m while losing 8.0 m of elevation. During this glide, a. What is the angle of the squirrel's path below the horizontal? b. What...
-
A softball player slides into second base. Use the particle model to draw a motion diagram of the player from the time he begins to slide until he reaches the base. Number the dots in order, starting...
-
Which of the following are perfect capital markets assumptions? a Smaller firms are exempt from paying taxes. b All market participants act rationally. c Compared to producers investors has less...
-
Refer to the data for problem 13-36 regarding Long Beach Pharmaceutical Company. Required: Compute each division's residual income for the year under each of the following assumptions about the...
-
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...
-
Find the time it takes for a transverse wave to travel along a transmission line from one tower to another one \(300 \mathrm{~m}\) away. Assume the horizontal component of the cable tension as 30,000...
-
Fill in the Blank. In the wave-solution \(w(x, t)=w_{1}(x-c t)+w_{2}(x+c t)\), the first term represents the wave that propagates in the __________ directions of \(x\). conditions
-
What is a wave equation? What is a traveling-wave solution?
Study smarter with the SolutionInn App