Question

NEED HELP THE PROBLEM-SOLVING PROCESS WITH THE UML DIAGRAM + ACTIVITY DIAGRAMS TO RUN THE CODE...

NEED HELP THE PROBLEM-SOLVING PROCESS WITH THE UML DIAGRAM + ACTIVITY DIAGRAMS TO RUN THE CODE PROGRAM PLEASE!!

Problem1. (20 points) Recursive Coding Problem. Using the Problem Solving Process. Write a Java application that implements these two functions using recursive methods (recursion must be used).

  1. First Recursive Function. When one passes an integer as input (n for example), the return should return (output) the sum as follows:

1 + 1/2 + 1/3 + 1/4 + ... 1/(n-1) + 1/n

Example:

If the function's argument is 4, the function should return the value of 2.083 which is the sum of: 1 + 1/2 + 1/3 + 1/4.

Sample Output:

This application will calculate the solution for the following function:

x = 1 + 1/2 + 1/3 + 1/4 + … 1/(n-1) + 1/n Please enter an integer: 4

x = 1 + 1/2 + 1/3 + 1/4 = 2.083.

  1. Second Recursive Function. The second function when you pass it an integer (n for example) is supposed to print lines of asterisks in the following format:

*

**

***

****

****

***

**

*

Sample Output One:

Please enter an integer (1-10) an I will print a recursive Bar Chart: 1

*

*

Sample Output Two:

Please enter an integer (1-10) an I will print a recursive Bar Chart: 3

*

**

***

***

**

*

Summary, Given n, code will print n lines starting with one asterisk on line 1 followed by two asterisks on line 2, all the way to n asterisks on line n. Then, after line n print the mirror image of the first n lines.

Additional Guidance. You need to implement a main function in your class that will do the following:

  1. Ask the user to read an integer (n)
  2. Pass the integer to the first function and call it to return the sum.
  3. Print the sum.
  4. Ask the user to read another integer (can also be n)
  5. Pass the integer to the second function to print the asterisks in the format mentioned.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;
public class Main{
public static double sumfun(int n)
{
if(n==0)
{
return 0.0;
}
else
{
return sumfun(n-1)+1.0/(double)n;
}
}
public static void secondfun(int n,int num)
{
if(n-1==num)
{
return;
}
for(int i=0;i<n;i++)
{
System.out.print("*");
}
System.out.println("");
secondfun(n+1,num);
for(int i=0;i<n;i++)
{
System.out.print("*");
}
  
System.out.println("");
  
}
public static void main(String []args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter n for sum: ");
int n=sc.nextInt();
System.out.println(sumfun(n));
System.out.println("Enter n for second function: ");
n=sc.nextInt();
secondfun(1,n);

}
}

Add a comment
Know the answer?
Add Answer to:
NEED HELP THE PROBLEM-SOLVING PROCESS WITH THE UML DIAGRAM + ACTIVITY DIAGRAMS TO RUN THE CODE...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a python program (recursive.py) that contains a main() function. The main() should test the following...

    Write a python program (recursive.py) that contains a main() function. The main() should test the following functions by calling each one with several different values. Here are the functions: 1) rprint - Recursive Printing: Design a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. 2) rmult - Recursive Multiplication: Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times...

  • I need help with this question in JAVA. I need the code, the UML diagram and...

    I need help with this question in JAVA. I need the code, the UML diagram and the pseudocode Do a recursive method that return every possible k permutations of the String non-zeros number given Sample input : "123" , 2 output : "1-2", "1-3", "2-3", "2-1", "3-1", "3-2"

  • Please write a C++ Program for the following problem >> Vector: Calculation the sum of each...

    Please write a C++ Program for the following problem >> Vector: Calculation the sum of each two adjacent Numbers.... >>【Description】 Read integer numbers from keyboard and store them into a vector. Calculation the sum of each two adjacent Numbers, store the result into another vector. Then output the result inversely. For example, if the input is 1 2 3 4 5 then the output is 9 7 5 3 【 Input】 There are 5 test cases. For each case, there...

  • PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end...

    PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end please include a main function that tests the functions that will go into a separate driver file. Prototypes int R_get_int (void); int R_pow void R Jarvis int start); void R_fill_array(int arrayll, int len); void R_prt_array (int arrayl, int len) void R-copy-back (int from[], int to [], int len); int R_count_num (int num, int arrayll, int len) (int base, int ex) 3. Build and run...

  • NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET...

    NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET CODE TO RUN!! THANKS Extend the DeckofCards and the Card class in the book to implement a card game application such as BlackJack, Texas poker or others. Your game should support multiple players (up to 5 for BlackJack). You must build your game based on the Cards and DeckofCards class from the book. You need to implement the logic of the game. You can...

  • I need help writing this program in C++. Thanks so much for your help in advance...

    I need help writing this program in C++. Thanks so much for your help in advance Function 1: Write a function that accepts an integer argument and returns the sum of all the integers from 1 up to the number passed as an argument. For example, if 50 is passed as an argument, the function will return the sum of 1, 2, 3, 4, ... 50. Use recursion to calculate the sum. Demonstrate the function in a program. A sample...

  • Please code in MatLab or Octave Output should match Sample Output in the second picture Thank...

    Please code in MatLab or Octave Output should match Sample Output in the second picture Thank You 4. In this problem we will investigate using loops to calculate the product of two matrices. Given an mxn matrix A and an n x p matrix B, the matrix product C = AB is the m xp matrix with Cij = R=1 Qikbky. Write a program which calls a function get matrix.dimensions which should • print a description of the purpose of...

  • need help with python ( no loops used please!) Write a recursive function named sum_digits that...

    need help with python ( no loops used please!) Write a recursive function named sum_digits that takes a given a non-negative integer N and returns the sum of its digits. Hint: Mod (%) by 10 gives you the rightmost digit (126 % 10 is 6), while doing integer division by 10 removes the rightmost digit (126/10 is 12). This function has to be recursive; you are not allowed to use loops to solve this problem! This function takes in one...

  • PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs...

    PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs to:             -define a recursive procedure/function and call it.             -use syscall operations to display integers and strings on the console window             -use syscall operations to read integers from the keyboard. Assignment Description: Implement a MIPS assembly language program that defines "main", and "function1" procedures. The function1 is recursive and should be defined as: function1(n) = (2*n)+9                      if n <= 5              =...

  • c++ fibonacci code using loops Here are 8 Fibonacci numbers: 1, 1, 2, 3, 5, 8,...

    c++ fibonacci code using loops Here are 8 Fibonacci numbers: 1, 1, 2, 3, 5, 8, 13, 21 Note that the first Fibonacci number is 1, F(1) = 1 The second Fibonacci number is 1, i.e. F(2) = 1 Other Fibonacci numbers in the sequence is the sum of two previous Fibonacci numbers. For example F(3) = F(2) + F(1). In general F(n) = F(n-1) + F(n-2) Write a program to do the following tasks. User entries are shown in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT