1. Homepage
  2. Programming
  3. CS111 Assignment 6: Recursion

CS111 Assignment 6: Recursion

Engage in a Conversation
JavaWeather Generatorweather prediction functionUSRutgers University

Recursion – 50 course points

This assignment consists of writing a program that plots a Sierpinski triangle.  A second program entails a function that appends strings recursively. CourseNana.COM

Refer to our Programming Assignments FAQ for instructions on how to install VSCode, how to use the command line and how to submit your assignments. CourseNana.COM

Start your assignment early. CourseNana.COM


We provide this ZIP FILE containing Sierpinski.java and libraries needed for this assignment. CourseNana.COM

We provide this ZIP FILE containing RecursiveAppend.java and libraries needed for this assignment. CourseNana.COM

Observe the following rules: CourseNana.COM

  1. DO NOT use System.exit().
  2. DO NOT add the project or package statements.
  3. DO NOT add import statements.
  4. DO NOT change the class name.
  5. DO NOT change the headers of ANY of the given methods.
  6. DO NOT add any new class fields.
  7. ONLY display the result as specified by the example for each problem.
  8. DO NOT print other messages, follow the examples for each problem.
  9. USE StdIn, StdOut, StdRandom, and StdDraw libraries.

Sierpinski (25 points)The Sierpinski triangle is an example of a fractal pattern like the H-tree pattern from Section 2.3 of the textbook. CourseNana.COM

order 1
order 2
order 3
order 4
order 5
order 6

The Polish mathematician Wacław Sierpiński described the pattern in 1915, but it has appeared in Italian art since the 13th century. Though the Sierpinski triangle looks complex, it can be generated with a short recursive function. Your main task is to write a recursive function sierpinski() that plots a Sierpinski triangle of order n to standard drawing. Think recursively: sierpinski() should draw one filled equilateral triangle (pointed downwards) and then call itself recursively three times (with an appropriate stopping condition). It should draw 1 filled triangle for n = 1; 4 filled triangles for n = 2; and 13 filled triangles for n = 3; and so forth. CourseNana.COM

API specification. When writing your program, exercise modular design by organizing it into four functions, as specified in the following API: CourseNana.COM

public class Sierpinski { 

   // Height of an equilateral triangle whose sides are of the specified length. 
   public static double height(double length) 

   // Draws a filled equilateral triangle whose bottom vertex is (x, y) 
   // of the specified side length. 
   public static void filledTriangle(double x, double y, double length) 

   // Draws a Sierpinski triangle of order n, such that the largest filled 
   // triangle has bottom vertex (x, y) and sides of the specified length. 
   public static void sierpinski(int n, double x, double y, double length) 

   // Takes an integer command-line argument n; 
   // draws the outline of an equilateral triangle (pointed upwards) of length 1; 
   // whose bottom-left vertex is (0, 0) and bottom-right vertex is (1, 0); and 
   // draws a Sierpinski triangle of order n that fits snugly inside the outline. 
   public static void main(String[] args) 

Restrictions: You may not change either the scale or size of the drawing window. CourseNana.COM

This video may be helpful to understand how the triangles are drawn. CourseNana.COM

Recursive Append (25 points). On RecursiveAppend.java write a recursive method appendNTimes that receives two arguments, a string and an integer. The method appendNTimes returns the original string appended to the original string n times. CourseNana.COM

  1. Use the following method header:public static String appendNTimes (String original, int n)
  2. Examples:
  3. appendNTimes("cat", 0) returns “cat”
  4. appendNTimes("cat", 1) returns “catcat”
  5. appendNTimes("cat", 2) returns “catcatcat”
  6. The following restrictions apply to method appendNTimes:
    • Do not use loops (whiledo/while, or for).
    • Your code must return a string without extra space, comma or any other character that is not in the original string

    You may write your own main method to test your appendNTimes method. Autolab will ignore your main method. CourseNana.COM

Before submission

  1. Collaboration policy. Read our collaboration policy here.
  2. Update @author. Update the @author tag of the files with your name, email and netid.
  3. Submitting the assignment. Submit Sierpinski.java via the web submission system called Autolab. To do this, click the Assignments link from the course website; click the Submit link for that assignment.

Getting help

If anything is unclear, don’t hesitate to drop by office hours or post a question on Piazza. Find instructors office hours by clicking the Staff  link from the course website. In addition to office hours we have the CAVE (Collaborative Academic Versatile Environment), a community space staffed with lab assistants which are undergraduate students further along the CS major to answer questions. CourseNana.COM

Get in Touch with Our Experts

Wechat WeChat
Whatsapp Whatsapp
Java代写,Weather Generator代写,weather prediction function代写,US代写,Rutgers University代写,Java代编,Weather Generator代编,weather prediction function代编,US代编,Rutgers University代编,Java代考,Weather Generator代考,weather prediction function代考,US代考,Rutgers University代考,Javahelp,Weather Generatorhelp,weather prediction functionhelp,UShelp,Rutgers Universityhelp,Java作业代写,Weather Generator作业代写,weather prediction function作业代写,US作业代写,Rutgers University作业代写,Java编程代写,Weather Generator编程代写,weather prediction function编程代写,US编程代写,Rutgers University编程代写,Javaprogramming help,Weather Generatorprogramming help,weather prediction functionprogramming help,USprogramming help,Rutgers Universityprogramming help,Javaassignment help,Weather Generatorassignment help,weather prediction functionassignment help,USassignment help,Rutgers Universityassignment help,Javasolution,Weather Generatorsolution,weather prediction functionsolution,USsolution,Rutgers Universitysolution,