Answered step by step
Verified Expert Solution
Question
1 Approved Answer
***NEED HELP ASAP PLEASE WITH THIS PROBLEM!** - SIMPLE UNDERSTANDING PLEASE! Consider the following interface for unary integer functions and example implementation: interface Fun {
***NEED HELP ASAP PLEASE WITH THIS PROBLEM!** - SIMPLE UNDERSTANDING PLEASE!
Consider the following interface for unary integer functions and example implementation: interface Fun { public int eval(int i); } class Inc implements Fun { public int eval(int i) { return i+1; }} (a) Write code for class C. Class C composes two functions (that is, when given an argument C.eval applies the first function to the argument and the second function to the result of the first, returning the result of the second function). As an example of usage, consider the following: Fun inc = new Inc(); System.out.println (inc.eval(2)); // prints 3 Fun t5 = new TimesN(5); System.out.println (t5.eval(2)); //prints 10 Fun f = new C(t5,t5); System.out.println (f.eval(2)); // prints 50 Fun g = new C(f,inc); System.out.println (g.eval(2)); // prints 51 (b) Writing a JUnit Test. In new C(F1,F2).eval(n), we wish to ensure that f1.eval is performed before f2.eval. Write a unit test for class C to ensure that this is the case
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started