Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

15.3: Being Methodical Copy and paste the starter code into a new file called Methodical.java Write the required methods as described by the comments (i.e.

15.3: Being Methodical

  • Copy and paste the starter code into a new file called Methodical.java
  • Write the required methods as described by the comments (i.e. you fill in the body of the method).
  • Then, run the code when you are finished to see if you wrote the methods correctly.
  • Check the test results and make any alterations to your methods as necessary.
  • When all of the tests pass, upload your code to Canvas.

/* * @author * CIS 36A * */ public class Methodical { /* * Given two int values, returns their sum. * Unless the two values are the same, then return double their sum. * sumDouble(1, 2) 3 * sumDouble(3, 2) 5 * sumDouble(2, 2) 8 */ public static int sumDouble(int a, int b){ return 0; } /* * Given 2 ints, a and b, return true if one of them is 10 * or if their sum is 10. * makes10(9, 10) true * makes10(9, 9) false * makes10(1, 9) true */ public static boolean makes10(int a, int b) { return false; } /* * We have two monkeys, a and b, and the parameters * aSmile and bSmile indicate if each is smiling. * We are in trouble if they are both smiling * or if neither of them is smiling. * Return true if we are in trouble. * monkeyTrouble(true, true) true * monkeyTrouble(false, false) true * monkeyTrouble(true, false) false */ public static boolean monkeyTrouble(boolean aSmile, boolean bSmile) { return false; } /*Return true if the given non-negative number is a multiple of 3 * or a multiple of 5. Use the % "modulus" operator * or35(3) true * or35(10) true * or35(8) false * */ public static boolean or35(int a) { return false; } /* * Given a string, return a new string where "not " has been added to the front. * However, if the string already begins with "not", return the string unchanged. * notString("candy") "not candy" * notString("x") "not x" * notString("not bad") "not bad" */ public static String notString(String str) { return ""; } /* * Given a string, return a new string where the first and last chars have been exchanged * frontBack("code") "eodc" * frontBack("a") "a" * frontBack("ab") "ba" */ public static String frontBack(String str) { return ""; } /* * We'll say that a number is "teen" if it is in the range 13..19 inclusive. * Given 3 int values, return true if 1 or more of them is/are teen. * hasTeen(13, 20, 10) true * hasTeen(20, 19, 10) true * hasTeen(20, 10, 13) true */ public static boolean hasTeen(int num1, int num2, int num3) { return false; } public static void main(String[] args) { int result; boolean answer; String value; System.out.println("***Testing sumDouble*** "); result = sumDouble(1, 2); System.out.println("Should print 3: " + result); result = sumDouble(3, 2); System.out.println("Should print 5: " + result); result = sumDouble(2, 2); System.out.println("Should print 8: " + result +" "); System.out.println("***Testing makes10*** "); answer = makes10(9, 10); System.out.println("Should be true: " + answer); answer = makes10(9, 9); System.out.println("Should be false: " + answer); answer = makes10(1, 9); System.out.println("Should be true: " + answer + " "); System.out.println("***Testing monkeyTrouble*** "); answer = monkeyTrouble(true, true); System.out.println("Should be true: " + answer); answer = monkeyTrouble(false, false); System.out.println("Should be true: " + answer); answer = monkeyTrouble(true, false); System.out.println("Should be false: " + answer + " "); System.out.println("***Testing or35*** "); answer = or35(3); System.out.println("Should be true: " + answer); answer = or35(10); System.out.println("Should be true: " + answer); answer = or35(8); System.out.println("Should be false: " + answer + " "); System.out.println("***Testing notString*** "); value = notString("candy"); System.out.println("Should be not candy: " + value); value = notString("x"); System.out.println("Should be not x: " + value); value = notString("not bad"); System.out.println("Should be not bad: " + value + " "); System.out.println("***Testing frontBack*** "); value = frontBack("code"); System.out.println("Should be eodc: " + value); value = frontBack("a"); System.out.println("Should be a: " + value); value = frontBack("ab"); System.out.println("Should be ba: " + value + " "); System.out.println("***Testing hasTeen*** "); answer = hasTeen(13, 20, 10); System.out.println("Should be true: " + answer); answer = hasTeen(20, 19, 10); System.out.println("Should be true: " + answer); answer = hasTeen(20, 10, 13) ; System.out.println("Should be true: " + answer); answer = hasTeen(20, 10, 45) ; System.out.println("Should be false: " + answer + " "); System.out.println("***End of Tests***"); } }

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

Students also viewed these Databases questions

Question

=+34-1 Define cognition, and describe the functions of concepts.

Answered: 1 week ago

Question

9. Describe the characteristics of power.

Answered: 1 week ago

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago