CS210: Software Development
软件开发代写 Submission: Submit Recursion.java and RecursionTestClass.java to Gradescope. Do not submit the entire project.The goal of this assignment
PA3 Recursion Tyler Conklin and Clark Penado
PA3 Recursion 软件开发代写
Due: Wednesday 9/18 by 11:30PM
Submission: Submit Recursion.java and RecursionTestClass.java to Gradescope. Do not submit the entire project.
Overview 软件开发代写
The goal of this assignment is to practice recursion and testing. In a typical PA, you write one small recursive part of a larger assignment. I did not want you to waste your time on things you have already done in both PA1/PA2 (file reading, formatting output, etc…). So instead this assignment is all recursive functions.
Assignment 软件开发代写
In this assignment, you will implement different recursive methods. Open the starter code to see the different methods. They are all commented describing the purpose of each function. Note, the problems are not arranged in order of difficulty. You may find the first function the hardest or easiest, who knows. The functions are reproduced here:
/**
*Writea recursive function that finds the index of s2 in Do not use any
*string functions except for .length(), .equals(), and .substring(). Do notuse
*anyloops, or any data
*@params1
*@params2
*@returnReturns the index of the first time that 软件开发代写
*s2 appears in s1 or -1 if s2 is notcontained
*in s1.
*/
public static int indexOf(String s1, String s2) {}
/**
*Writea recursive function that removes the first k even numbers
*fromthe If there are less than k even elements in the stack,
*just remove all even elements. Do not use any loops or datastructures
*otherthan the stack passed in as a 软件开发代写
*@paramstack
*@paramk
*@returnReturns the number of elements removed from the
*/
public static int removeEvenNumbers(Stack<Integer> stack, int k) {}
/**
*Writea recursive function that accepts an integer and
*returns a new number containing only the even digits, in thesame
*If there are no even digits, return 0. Yourfunction should
*workfor positive or negative You are NOT allowed
*touse any data You are not allowed to use Strings to
*solve this problem 软件开发代写
*@paramn
*@returnThe input with only the even digits remaining in the same
*/
public static int evenDigits(int n) {}
/**
*Writea recursive function that evaluates a Queue<Character> as a mathematical
*This queue can have any of the following characters:
*{’(’, ’)’, ’+’, ’*’} or any single digit Evaluate this expression and
*returnthe For example, for the expression:
*”(((1+2)*(3+1))+(1*(2+2)))”,each of these characters would be in the
*As you recursively evaluate characters from the expression, you will
*removethe characters from the After evaluating the above expression,
*youshould return You are guaranteed that there are NO two digit numbers,
*andthat the expression is well formed (parenthesis match, ..). Do not use any
*Do not use any data structures besides the q passed in as a parameter.软件开发代写
*@paramq
*@returnThe result of the mathematical
*/
*public static int evaluate(Queue<Character> q) {}
/**
*Writea recursive function that accepts a stack of integers and
*replaceseach int with two copies of that For example,
*callingrepeatStack and passing in a stack of { 1, 2, 3} would change
*thestack to hold { 1, 1, 2, 2, 3, 3}. Do not use any Do not use
*anydata structures other than the stack passed in as a
*@paramstack
*/
public static void repeatStack(Stack<Integer> stack) {}
/**
*Writea recursive function that accepts a Queue<Integer>. It
*shouldchange every int in this queue to be double its original
*You may NOT use loops or any other data structures besides
*the queue passed in as a You may use a helperfunction.
*@paramq
*/
public static void doubleElements(Queue<Integer> q) {}
Sample Outputs 软件开发代写
Below is some sample code that I wrote inside of RecursionTestClass.java. Below each print statement, I have written a comment showing what should be printed.
System.out.println(Recursion.indexOf("Hello", "lo")); // 3 Stack<Integer> stack = new Stack<Integer>(); stack.push(2); stack.push(3); stack.push(4); stack.push(55); stack.push(6); stack.push(17); stack.push(8); System.out.println(Recursion.removeEvenNumbers(stack, 2)); // 2 System.out.println(stack); // [2, 3, 4, 55, 17] System.out.println(Recursion.evenDigits(-1364035)); // 1335 String expr = "(((1+2)*(3+1))+(1*(2+2)))"; Queue<Character> q = new LinkedList<Character>(); for (char ch: expr.toCharArray()) { q.add(ch); } System.out.println(Recursion.evaluate(q)); // 16 System.out.println(stack); // [2, 3, 4, 55, 17] Recursion.repeatStack(stack); System.out.println(stack); // [2, 2, 3, 3, 4, 4, 55, 55, 17, 17] Queue<Integer> q2 = new LinkedList<Integer>(); q2.add(34); q2.add(15); q2.add(0); Recursion.doubleElements(q2); System.out.println(q2); [68, 30, 0]
Testing
You are responsible for testing your code (as it should be). The testing code that you will write is in RecursionTestClass.java. We have given you one example of the format of a test. You can also refer to any of the drills, we are using the same style of testing as is done for the drills.软件开发代写
Remember you need to test the normal case, and the edge cases. What are all the weird (but valid) inputs that you might receive? What sorts of inputs might cause issues with your code?
Hints
- Pay attention in class when going over the recursive
- Refer back to the recursive examples done in
- Startearly!
- There are 6 problems. You have roughly one week to do the assignment. Just like we learn about decomposing a large problem into smaller tasks, why don’t you set yourself a goal of doing roughly one of the problems every day? That way you are not stuck with doing a whole bunch of tough recursive problems the night before it is due.
- Remember that often recursive functions are very little code, but it is difficult to figure out what that code is. Spend a lot of time designing an algorithm before jumping into the code. Use a pen and paper!软件开发代写
- The key insight you need to find in these recursive problems is how are they self-similar? Look for patterns. Look for the simplest case, and then try to figure out how to do a tiny bit of work to make a complicated case just a little bit simpler.
- For the evaluate function, you mightfind
Character.isDigit(char ch) and Character.getNumericValue(char ch)
helpful.
- For the doubleElements function, it might be useful to have another parameter. This might mean creating a helper function.
- Take the recursive leap of faith. Trust your function to do what it
Grading Criteria
Unless otherwise specified, you are not allowed to use any data structures or loops in solv- ing these problems.
For this PA, we have only provided one testcase so that you can see the format of how one is written. We will be testing your code on a lot of different testcases, make sure you do the same.软件开发代写
Grades for PA2 are due Wednesday 9/18 by 5:00PM. If you have not received your grade by then, it means your UGTA is slacking! Post privately to Clark and me and we will look into it.
Since this PA is more like a drill than a traditional programming assignment, it will be graded slightly differently. There will be no deductions pertaining to a clean main() method, as well as other traits of a larger program. Instead, we will be grading your testing coverage. So your grade will consist of functionality of your code, style/code clarity, and how well your tests cover different possible scenarios. Of course we still care about many pieces of code clarity,
like the below:
- Should use only static
- Each static method should be short and concise. A method should only perform one task. If you have a method that is performing multiple tasks, break it into smaller meth- ods. We think a good rule of thumb for method length is 30 lines.
- Make things as simple as possible. This means avoiding nested loops, nested condi- tionals, and too many levels of user-defined methods calling other user-defined method (chaining) whenever possible.软件开发代写
- You should be able to read, understand, and explain your own code weeks after you wrote it.
- Use meaningful variable
- Remember that indentation and spacing are great tools to make your code more read- able. Eclipse should automatically indent the proper levels for you. As long as you stick with those defaults you should be fine.
Note:
you do not need to have a file header comment for either file. You do need to comment your testcases though.软件开发代写
Write your own code. We will be using a tool that finds overly similar code. Do not look at other students’ code. Do not let other students look at your code or talk in detail about how to solve this programming project. Do not use online resources that have solved the same or similar problems. It is okay to look up, ”How do I do X in Java”, where X is indexing into an array, splitting a string, or something like that. It is not okay to look up, ”How do I solve this programming assignment from CSc210” and copy someone else’s hard work in coming up with a working algorithm.
S210:软件开发
PA3递归Tyler Conklin和Clark Penado
PA3递归
截止时间:9/18星期三晚上11:30
提交:将Recursion.java和RecursionTestClass.java提交给Gradescope。不要提交整个项目。
概述
该作业的目标是练习递归和测试。在典型的PA中,您编写了较大分配的一小部分递归部分。我不想让您浪费时间在PA1 / PA2中已经完成的事情(文件读取,格式化输出等)。因此,此分配是所有递归函数。软件开发代写
任务
在此分配中,您将实现不同的递归方法。打开入门代码以查看不同的方法。它们都被注释以描述每个功能的目的。注意,问题不是按照困难的顺序排列的。谁知道,您可能会发现最困难或最简单的第一个功能。这些功能在此处复制:
/ **
*编写一个递归函数,以找到s1中s2的索引。请勿使用任何
* .string(.length()、. equals()和.substring()除外的字符串函数。不使用
*任何循环或任何数据结构。
* @参数s1
* @参数s2
* @ return返回第一次的索引
* s2出现在s1或-1中(如果不包含s2)
*在s1中。
* /
公共静态int indexOf(String s1,String s2){}
/ **
*编写一个递归函数以删除前k个偶数
*来自堆栈。如果堆栈中少于k个偶数元素,
*只需删除所有偶数元素。不要使用任何循环或数据结构
*除了作为参数传递的堆栈之外。软件开发代写
* @参数堆栈
* @参数k
* @ return返回从堆栈中删除的元素数。
* /
公共静态int removeEvenNumbers(Stack <Integer> stack,int k){}
/ **
*编写一个接受整数的递归函数
*以相同的方式返回仅包含偶数位的新数字
*命令。如果没有偶数,则返回0。您的函数应
*用于正数或负数。你没有权限
*使用任何数据结构。不允许使用字符串来
*也可以解决此问题。
* @参数n
* @ return输入仅保留偶数位的输入软件开发代写
*命令。
* /
public static int evenDigits(int n){}
/ **
*编写一个递归函数,将Queue <Character>评估为数学
*表达。此队列可以具有以下任何字符:
* {’(’,’)’,“ +”,“ *”}或任何一位数字。评估此表达式,然后
*返回结果。例如,对于表达式:
*“((((1 + 2)*(3 + 1))+(1 *(2 + 2)))”,其中每个字符都位于
* q。当您递归计算表达式中的字符时,您将
*从q中删除字符。对上述表达式求值后,
*您应该返回16。确保没有两位数字,
*并且该表达式格式正确(括号匹配等)。请勿使用任何
*循环。除了作为参数传入的q之外,不要使用任何数据结构。
* @参数q
* @ return数学表达式的结果。
* /
公共静态整数评估(队列<字符> q){}
/ **
*编写一个递归函数,该函数接受一堆整数并
*将每个int替换为该整数的两个副本。例如,
*调用repeatStack并传递{1,2,3}的堆栈会改变
*用于容纳{1,1,2,2,3,3}的堆栈。不要使用任何循环。不使用
*除了作为参数传入的堆栈以外的任何数据结构。软件开发代写
* @参数堆栈
* /
公共静态无效的repeatStack(Stack <Integer> stack){}
/ **
*编写一个接受Queue <Integer>的递归函数。它
*应将此队列中的每个int更改为其原始值的两倍
*价值。您不得使用循环或其他任何数据结构
*作为参数传入的队列。您可以使用助手功能。软件开发代写
* @参数q
* /
公共静态无效的doubleElements(Queue <Integer> q){}
样本输出
以下是我在RecursionTestClass.java中编写的一些示例代码。在每个打印语句的下面,我写了一条注释,显示应打印的内容。
// 3 Stack<Integer> stack = new Stack<Integer>(); stack.push(2); stack.push(3); stack.push(4); stack.push(55); stack.push(6); stack.push(17); stack.push(8); System.out.println(Recursion.removeEvenNumbers(stack, 2)); // 2 System.out.println(stack); // [2, 3, 4, 55, 17] System.out.println(Recursion.evenDigits(-1364035)); // 1335 String expr = "(((1+2)*(3+1))+(1*(2+2)))"; Queue<Character> q = new LinkedList<Character>(); for (char ch: expr.toCharArray()) { q.add(ch); } System.out.println(Recursion.evaluate(q));软件开发代写 // 16 System.out.println(stack); // [2, 3, 4, 55, 17] Recursion.repeatStack(stack); System.out.println(stack); // [2, 2, 3, 3, 4, 4, 55, 55, 17, 17] Queue<Integer> q2 = new LinkedList<Integer>(); q2.add(34); q2.add(15); q2.add(0); Recursion.doubleElements(q2); System.out.println(q2); [68, 30, 0]
测验
您负责测试您的代码(应如此)。您将编写的测试代码在RecursionTestClass.j中
ava。我们为您提供了测试格式的一个示例。您也可以参考任何练习,我们正在使用与练习相同的测试样式。
请记住,您需要测试正常情况和边缘情况。您可能会收到什么奇怪的(但有效的)输入?什么样的输入可能会导致您的代码出现问题?
提示
•遍历递归示例时要在课堂上注意。
•请参考在课堂上完成的递归示例。
•尽早开始!
有6个问题。您大约有一个星期的时间来做作业。就像我们了解将一个大问题分解为较小的任务一样,为什么不将自己的目标设定为每天处理大约一个问题呢?这样一来,您就不必在即将到来的前一天晚上处理一大堆棘手的递归问题。
请记住,递归函数通常只包含很少的代码,但是很难弄清楚该代码是什么。在进入代码之前,要花很多时间设计算法。用笔和纸!
您需要在这些递归问题中找到的关键见解是它们如何自相似?寻找模式。寻找最简单的情况,然后尝试弄清楚如何做一点点的工作,以使复杂的情况稍微简单一些。软件开发代写
•对于评估功能,您可能会发现
Character.isDigit(char ch)和Character.getNumericValue(char ch)
乐于助人。
对于doubleElements函数,拥有另一个参数可能会很有用。这可能意味着创建一个辅助函数。
•进行信仰的递归飞跃。相信您的职能可以做应做的事情。
分级标准
除非另有说明,否则不允许使用任何数据结构或循环来解决这些问题。
对于此PA,我们仅提供了一个测试用例,以便您可以看到编写方式。我们将在许多不同的测试用例上测试您的代码,确保您执行相同的操作。
PA2的等级将于9月18日(星期三)下午5:00到期。如果那时您还没有收到成绩,则意味着您的UGTA懈怠!私下发布给我和克拉克,我们将进行调查。
由于此PA比传统的编程任务更像是练习,因此其评分将略有不同。不会涉及到干净的main()方法以及大型程序的其他特征的推论。相反,我们将为您的测试范围评分。因此,您的成绩将包括代码的功能,样式/代码的清晰度以及测试涵盖不同可能情况的程度。当然,我们仍然关心许多代码的清晰度,如下所示:
•应仅使用静态方法。软件开发代写
每种静态方法都应简短明了。一种方法应仅执行一个任务。如果您具有执行多个任务的方法,请将其分解为较小的方法。我们认为方法长度的一个好的经验法则是30行。
使事情尽可能简单。这意味着要避免嵌套循环,嵌套条件和尽可能多级别的用户定义方法调用其他用户定义方法(链接)。
在编写代码几周后,您应该能够阅读,理解和解释自己的代码。
•使用有意义的变量名。
请记住,缩进和间距是使代码更易读的好工具。 Eclipse应该自动为您缩进适当的级别。只要您坚持使用这些默认值,就可以了。软件开发代写
注意:您不需要为任何一个文件添加文件头注释。但是,您确实需要注释您的测试用例。
编写您自己的代码。我们将使用一个发现过度相似代码的工具。不要看其他学生的代码。不要让其他学生看您的代码或详细谈论如何解决此编程项目。请勿使用已解决相同或相似问题的在线资源。可以查找“如何在Java中执行X”,其中X正在索引到数组,拆分字符串或类似内容。不能随意查找“我如何解决CSc210的编程任务”,并抄袭他人在提出有效算法方面的辛苦工作。
其他代写:algorithm代写 analysis代写 app代写 assembly代写 Haskell代写 C++代写 course代写 数学代写 考试助攻 web代写 program代写 cs作业代写 Programming代写 source code代写 finance代写 Data Analysis代写