Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How would you write the program for part B? 4. Do two stars (**) as a complete J

ID: 3570090 • Letter: H

Question


How would you write the program for part
B?

4. Do two stars (**) as a complete Java program. Save the program to Bb. The program will be graded on correctness and good programming style. ? a) Function sigmoid. Write a static method sigmoid(_) that takes a double argument x and returns the double value obtained from the formula 1/(1 ? e^-x). Write a main() to calculate sigmoid(2) = 1.156517643. ? b) Recursion. Write a recursive method (and a main() with 1(5) = 6) for the function t(n). t(1)= 2 t(n) = +l(n? l) for n > c) College. Create a class College with instance variables collegeName and clistanceilwqy, a default constructor and a constructor with two parameters to initialize the object for the instance variables, getter and setter for collegeName, and methods for toString? and equals?. The UML is: How would you write the program for part B?

Explanation / Answer

package dd.nhh;

public class NumberSeriesExample {

   /**
   * @param args
   */
   public static void main(String[] args) {
       int x = sum(5);
       System.out.println(x); // 6 (output)
   }

   static int sum(int t)
   {
       int result;
       if(t==1)
           return 2; //base case declaration
       result = 1+sum(t-1);
       return result;
   }
}

input: 5

output:

sum(5) =1+sum(4)=...=1+1+1+1+sum(1) = 4+2 = 6 (Answer) *

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote