Question
I'm having trouble with this one. Can someone help me please? Declare a public class MethodTest... Inside MethodTest, write the following methods: - A method
I'm having trouble with this one. Can someone help me please?
Declare a public class MethodTest...
Inside MethodTest, write the following methods:
- A method summation() which takes an integer parameter, assumed to be positive, and returns an integer equal to the summation from 1 to X. That is, if 5 is passed in, the method should return 5+4+3+2+1, or 15. If 3 is passed in, the method should return 6. If 1 is passed in, the method should return 1. You don't have to handle cases where 0 or a negative integer is passed in. - A method dupStr() which takes two parameters, the first being a string and the second being an integer, assumed to be positive, and returns a string equal to the first parameter copied a number of times equal to the second parameter. So, dupStr("test",3) should return "testtesttest". - A method countLetter() which takes two parameters, the first being a string and the second being a character which may or may not occur in the string. The method returns the number of times the character appears in the string. So, countLetter("apple",'p') should return 2. countLetter("apple",'k') should return 0. Make sure to handle the case where you're passed in the empty string (such as countLetter("",'b')). You always return 0 with the empty string since there are no letters in it. You should declare each of these methods as public and static, and you should declare the MethodTest class public as well. You can write whatever you want in your main method as long as it compiles, since I will not be using your main method when grading. I suggest you use your main method to test your methods and make sure they work correctly. Name of program should be: MethodTest
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started