Ten Unrelated Methods
Total Page:16
File Type:pdf, Size:1020Kb
Project: Five Methods in One File, Test Methods Given in Another File Collaboration: Solo. This is a Lab, not a Programming Project so you may talk to each other and collaborate. This Lab asks you to write five methods related to primitive types, Strings, and if statements. You are asked to write five methods--one at a time--in class FiveMethods. You also must write at least one test method for each of these five unrelated method class FiveMethodsTest. First, begin a new Java Project in Eclipse named FiveMethods.
First get these two Files into a new Eclipse project. You should have no compiletime errors.
1. FiveMethods.java (has all five method stubs) 2. FiveMethodsTest.java (has all the test written completely)
Here are the beginnings of the two required classes. Change YOUR NAME to your name.
// This class has tests for five methods to provide practice for testing // methods that do things with Strings and a few of the primitive types. // // Programmer: YOUR NAME // import static org.junit.Assert.*; import org.junit.Test; public class FiveMethodsTest {
FiveMethods myMethods = new FiveMethods();
@Test public void testAntiMatter() { // Three test cases to test method antiMatter(String matter) assertEquals("Anti-Shoes", myFuns.antiMatter("Shoes")); assertEquals("Anti-Tennis Racket", myFuns.antiMatter("Tennis Racket")); assertEquals("Anti-LOL", myFuns.antiMatter("LOL")); } }
// This class has five unrelated methods to provide practice for implementing // methods that process Strings and some of the primitive types. // // Programmer: YOUR NAME // public class FiveMethods {
public String antiMatter(String matter) { // TODO: Change this method so it meets the specs return "Needs work"; } }
1) public String antiMatter(String matter) Everyone knows that interplanetary space travel systems are fueled by letting matter and anti-matter mix. With this in mind, code a method that will take a String with the name of some thing or idea. Return a String with "Anti-" prepended to it. This method will tell us what to mix with that thing or idea so we can create a reaction to fuel our ships! Don't forget the dash!
matterAntiMatter ("Shoes") → "Anti-shoes" matterAntiMatter ("Tennis Racket") → "Anti-Tennis Racket" matterAntiMatter ("LOL") → "Anti-LOL" 2) public double triangleArea(double base, double height)
Given the base and height of a triangle, let triangleArea return the area of the triangle. Assume positive input since negative lengths do not make sense.
triangleArea (5.0, 5.0) → 12.5
3) public String halfAndHalf(String str)
Complete method halfAndHalf to return a new string that has the upper case version of the first half of the argument at the end and the lower case version of the last half of the argument at the beginning. halfAndHalf("x2y4abcd") → "abcdX2Y4" halfAndHalf("AbcDef") → "defABC" halfAndHalf("Hello") → "lloHE" halfAndHalf("U of A") → "f aU O"
If there is an odd number of letters, there should be one more lower case letters at the beginning of the result. Assume the String arguments length >= 2.
4) public SELECTION
4) public IF..ELSE
Turn this into Webcat TBA
Grading Criteria (100pts) When you have completely tested all methods, turn in your project to WebCat. You will be graded as follows: ____+100 Web-Cat correctness and code coverage. • Your code must compile using the specified names • Rick's tests must pass • You must have tested all of your methods with assertions in test methods • You must execute all statements in all methods at least once • All of your assertions must pass on WebCat • The final WebCat submission will be the one that is graded unless you inform us • WebCat employs a multiplication feature that means 90% and 90% results in 0.81 * 80 or 64.8/80 points. This is only 81% rather than 90%.