Question: Create a class named Yourlastname _ Yourfirstname _ midterm ( 5 pts ) . In this class, 1 . Write a static method named problem

Create a class named Yourlastname_Yourfirstname_midterm(5 pts). In this class, 1. Write a static method named problem that accepts a positive integer as the argument and returns the sum of all the positive even numbers that are less than or equal to the input number. You mustuse a while loop to solve the problem. (15 pts)Test case: problem1(15) returns 56(because 2+4+6+8+10+12+14=56).2. Write a static method named problem that receives a positive integer n as the argument andcalculates the sum below by using a loop. Return the result.total =1 x 2+2x3+...+ n x (n +1)(15 pts)Test case: problem2(5) returns 70(because 1x2+2x3+3x4+4 x 5+5 x 6=70).3. Write a static method named problem that accepts a string. Replace every occurrence of the first character with "$" except for the first character itself. Capitalize the first letter of this word. Returnthe results. (15 pts)Test case: problem3("abcabcabcabc") returns "Abc$bc$bc$bc".4. Write an inner public class named Triangle (not static). In this class, 1) Write three private instance variables, a, b, and c. Each instance variable represents the lengthof a line (type double).(6 pts)2) Write a constructor method to initialize each instance variable. (3 pts)3) Write a public get/set method for each instance variable. (6 pts)4) Write a public method named is_triangle) to calculate whether you can form a valid triangle with these three lines. Return true if a valid triangle can be formed, return false otherwise. Hint:the length of a side must be less than the combined length of the other two sides. (10 pts)5) Write a public method named get_triangle_type). In this method, check whether you can form a valid triangle with these three lines by using the method, is_triangle(). If no, return "cannotform a triangle". If yes, determine whether the triangle is equilateral, isosceles, or scalene. Return the result. Hint: An equilateral triangle has 3 equal sides. An isosceles triangle has 2equal sides. A scalene triangle has 3 different sides. (15 pts)Test case: 1) Create two objects of the Triangle class, triangle1 with lines of length 20,40.5, and 15.5, andtriangle2 with lines of length 20.5,15,20.5.2) For each object, call is_triangle() and get_triangle_type() respectively.5. Write the main method to run each method with the provided test case. (10 pts)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!