Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CISC231 Foundations of Computing ll Midterm (100 pts): Create a class named Yourlastname_Yourfirstname_midterm(5 pts). In this class, 1. 5. Write a static method named probleml

image text in transcribed
CISC231 Foundations of Computing ll Midterm (100 pts): Create a class named Yourlastname_Yourfirstname_midterm(5 pts). In this class, 1. 5. Write a static method named probleml 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 must use a while loop to solve the problem. (15 pts) Test case: problem1(15) returns 56 (because 2 + 4 + 6 + 8 + 10 + 12 + 14 = 56). Write a static method named problemZ that receives a positive integer n as the argument and calculates the sum below by using a loop. Return the result. total:1x2+2x3+...+nx(n+1)(15 pts) Test case: problem2(5) returns 70 (because 1 x 2 + 2 x 3 + 3 x 4 + 4 x 5 + 5 x 6 = 70). Write a static method named problem3 that accepts a string. Replace every occurrence of the first character with "S\" except for the first character itself. Capitalize the first letter of this word. Return the results. (15 pts) Test case: problem3(\"abcabcabcabc") returns \"Abc$bc$bc$bc". 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 length of 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 \"cannot form 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 2 equal sides. A scalene triangle has 3 different sides. (15 pts) Test case: 1) Create two objects of the Triangle class, trianglel with lines of length 20, 40.5, and 15.5, and triangleZ with lines of length 20.5, 15, 20.5. 2) For each object, call is_triangleo and get_triangle_type() respectively. Write the main method to run each method with the provided test case. (10 pts) Pagel 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Chromatin fibres is made up of DNA AND........?

Answered: 1 week ago

Question

The structure of DNA was first discovered by.........

Answered: 1 week ago

Question

The three components of a nucleotide are....... and........?

Answered: 1 week ago

Question

Primary function of root ?

Answered: 1 week ago