Question: Solve Exercise #3 using java and jgrasp. Make sure that every line of code should have a comment tell people what each piece of code
be changed to fix the code? Can you think of a way to write the code correctly without any st/else statements? Exercises 1. Write a method called Eractionsum that accepts an integer parameter n and returns as a double the sum of the first n terms of the sequence In other words, the method should generate the following sequence You may assume that the parameter n is nonnegative. 2. Write a method called rep1 that accepts a string and a number of repetitions as parameters and returns the String concatenated that many times. For example, the call repl("hello", 3) should return "hellohe1lohello". If the number of repetitions is zero or less, the method should return an empty string. 3IWrite a method called season that takes as parameters two integers representing a month and day and returns a string indicating the season for that month and day. Assume that the month is specified as an integer between I and 12 (1 for January. 2 for February, and so on) and that the day of the month is a number between I and 31. If the date falls between 12/16 and 3/15, the method should return "winter". If the date falls between 3/16 and 6/15, the method should return "spring". If the date falls between 6/16 and 9/15, the method should return summer" . And if the date falls between 9/16 and 12/15, the method should return fall 4. Write a method called daysInMonth that takes a month (an integer between 1 and 12) as a parameter and returns the number of days in that month fn this year. For example, the call daysInMonth(9) would return 30 because September has 30 days. Assume that the code is not being run during a leap year (that February always has 28 days). The following table lists the number of days in each month Month 1 Jan 2 Feb 3 Mar 4 Apr 5 May 6 Jun 7 Jul 8 Aug 9 Sep 10 Oct 11 Nov 12 Dec Days 31 28 3 30 31 30 31 31 3031 30 31 5. Write a method called pow that accepts a base and an exponent as parameters and returns the base raised to the given 3, or 81. Assume that the base and exponent power. For example, the call pow(3, 4) should returm 3.33 are nonnegative
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
