Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part A Create a method or methods that use recursion to calculate n? by using n (n 1)2 +2n-1. So, for example, 172 16 +2*17-1.

image text in transcribed
image text in transcribed
image text in transcribed
Part A Create a method or methods that use recursion to calculate n? by using n (n 1)2 +2n-1. So, for example, 172 16 +2*17-1. You have a lot of freedom. You can create a main method or use a test case to run your recursive method. You can write a wrapper or not. You can allow the user to input integers, or just hard-code the parameters in the test case or main. However you choose to do it, you should test several input values and demonstrate to me that your method works. 2. Part B Download the file Lab04-FindMax-Source.zip to a directory available to Eclipse, and import it into Eclipse as usual. 3. Open the file Test max.java and run it as a JUnit Test. You should get a red bar and errors. (a) In Test max.java, write more tests to test the method findMax ), which takes a LinkedComparableStack object and finds the maximum item in the stack. Note that the LinkedComparableStack class extends the LinkedStack class, so you can use push O to put integers onto the stack stk1. These tests should all fail initially (b) Look at LinkedComparableStack.java. Read my notes about the class in that file. Com- plete the methods findMax () and myPrivateFindMax() as described in the file's com ments. Note that both return a reference of type T. The return value from the findMax () method should point to the largest value in the stack 4. Answer the following questions is the file answers.txt a) Since we are testing findMax () with integers, why don't we use the > operator to test if we've found a bigger integer? b) Can you think why we didn't add findMax) to the interfaces in this package, or even to the LinkedStack class? 5, Take a screenshot of the entire Eclipse window showing each test file with a green JUnit bar after the last task is complete. Call them 1ab04AScreenshot.png and lab04BScreenshot. 6. Printed on paper to hand in. Please number your pages and complete the Table of Contents. ga clipse-workspace-Lab04B-FindMax-Source/src/testMax/Test-max-Java-Eclip Recursion.java LinkedStack.java Test max.java 3 backage testM 3inport static org.junit.Assert.*; public class Test_max t 13 LinkedComparableStack stkl; 14e @Before 15 public void setup) throws Exception stkl new LinkedComparableStack> extends LinkedStackeTs ( 4 public LinkedComparableStack)t // constructor uses superclass constructor method super); x In this class, if A and B are both type T, * then we can use A.compareTo(B) for comparing A to B. 10 The result will be 0 if A is the same as B, * positive if A is greater than B, * and negative if A is less than B. 12 13 14 15 16 17 18 (So, A.compareTo(B) basically does A-B.) Note the "extends Comparable

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Implementing Ai And Machine Learning For Business Optimization

Authors: Robert K Wiley

1st Edition

B0CPQJW72N, 979-8870675855

More Books

Students also viewed these Databases questions