Question

In: Computer Science

I. Answer part A, B, and C 1a) Return true if the given int parameter is...

I. Answer part A, B, and C

1a)

Return true if the given int parameter is both positive and less than 10, and false otherwise. Remember that 0 is not positive!


positiveLessThan10(10) → false
positiveLessThan10(9) → true
positiveLessThan10(11) → false

1b)

Return true if the parameters are in ascending order, from left to right. Two values that are equal are considered to be in ascending order. Remember, you can just type return true or return false to return true or false. Both true and false are reserved words in Java.


isAscending(1, 2, 3) → true
isAscending(1, 2, 2) → true
isAscending(3, 2, 1) → false

1c)

Return true if the parameters are in ascending order, from left to right, or in descending order from left to right. Two values that are equal are considered to be in either ascending or descending order.


isAscendingOrDescending(1, 2, 3) → true
isAscendingOrDescending(1, 2, 2) → true
isAscendingOrDescending(3, 2, 1) → true

Solutions

Expert Solution

public class Methods {
    
    // A)
    public static boolean positiveLessThan10(int n) {
        return n > 0 && n < 10;
    }

    // B)
    public static boolean isAscending(int n1, int n2, int n3) {
        return n1 <= n2 && n2 <= n3;
    }

    // C)
    public static boolean isAscendingOrDescending(int n1, int n2, int n3) {
        return (n1 <= n2 && n2 <= n3) || (n1 >= n2 && n2 >= n3);
    }

    public static void main(String[] args) {
        System.out.println(positiveLessThan10(10));
        System.out.println(positiveLessThan10(9));
        System.out.println(positiveLessThan10(11));

        System.out.println(isAscending(1, 2, 3));
        System.out.println(isAscending(1, 2, 2));
        System.out.println(isAscending(3, 2, 1));

        System.out.println(isAscendingOrDescending(1, 2, 3));
        System.out.println(isAscendingOrDescending(1, 2, 2));
        System.out.println(isAscendingOrDescending(3, 2, 1));
    }
}


Related Solutions

IV. Answer parts A,B, and C 4a) Return true if the letter 'a' occurs in the...
IV. Answer parts A,B, and C 4a) Return true if the letter 'a' occurs in the given String, and false otherwise. containsA("abc") → true containsA("wxyz") → false containsA("bcaca") → true 4b) Return true if the letter 'a' does not occur in the given String, and false otherwise. notContainsA("abc") → false notContainsA("wxyz") → true notContainsA("bcaca") → false 4c) Count the number of times a given char occurs in a given range of a String parameter (i.e. starting at a given start...
C++ A void function named NextLeapYear() that takes an int reference parameter. If the parameter is...
C++ A void function named NextLeapYear() that takes an int reference parameter. If the parameter is positive, the function will assign it the next leap year after it; otherwise, the function will assign 4 to it.
I need the answer for PART B and PART C of this question: You have recently...
I need the answer for PART B and PART C of this question: You have recently been appointed management accountant for Rugby Coffee Mugs Pty Ltd. The company commenced its operations on 1 July 2019 manufacturing one size coffee mugs with individual club names and club logos of rugby union clubs playing in the New South Wales, Queensland, Victoria and Western Australia local rugby union competition. The company currently does not have any management accounting controls and part of your...
Part 1: answer (a), (b), (c), and (d). Part 2: answer (a), (b), (c), and (d)....
Part 1: answer (a), (b), (c), and (d). Part 2: answer (a), (b), (c), and (d). Godspeed, and good luck!!! CC11 Cookie Creations Natalie and her friend Curtis Lesperance decide that they can benefit from joining Cookie Creations and Curtis’s coffee shop. In the first part of this problem, they come to you with questions about setting up a corporation for their new business. In the second part of the problem, they want your help in preparing financial information following...
III. Answer part A,B, and C. (in JAVA) 3a) Return the number of times the letter...
III. Answer part A,B, and C. (in JAVA) 3a) Return the number of times the letter 'a' occurs in a String. countA("abc") → 1 countA("wxyz") → 0 countA("bcaca") → 2 3b) Return the number of times the given letter ch occurs in the given String str. countNumChar("abc", "a") → 1 countNumChar("wxyz", "b") → 0 countNumChar("bcaca", "c") → 2 3c) Count the number of characters that are either a or b in a String. Try to use only one for loop....
VI. Answer part A, B, and C of question 5. 5a) Given a String str1 and...
VI. Answer part A, B, and C of question 5. 5a) Given a String str1 and a String str2, return true if str1 contains any character in str2 anyChar("abc", "xyz") → false anyChar("abc", "xya") → true anyChar("abc", "xyzxyzbxyzxyz") → true 5b) Given a String str1 and a String str2, return true if str1 does not contains any character in str2, and false otherwise. noChar("abc", "xyz") → true noChar("abc", "xya") → false noChar("xyzxyzbxyzxyz", "xyzb") → false 5c) Given a String str1...
C++ Q2.   Given the code as below. Which statement is correct? int myAry[100]; for(int i=0; i<100;...
C++ Q2.   Given the code as below. Which statement is correct? int myAry[100]; for(int i=0; i<100; i++) myAry = i + 2; for(int i=100; i>0; i--) cout << myAry[i] << '\t'; The first for loop assigns myAry 99 values and the null character. The second for loop prints out myAry elements backwards. The index in the second for loop is out of bounds. Only the first loop needs the null character. Q3. A value returning function that takes one parameter,...
Given the following Java code: class C { public int foo(C p) { return 1; }...
Given the following Java code: class C { public int foo(C p) { return 1; } } class D extends C { public int foo(C p) { return 2; } public int foo(D p) { return 3; } } C p = new C(); C q = new D(); D r = new D(); int i = p.foo(r); int j = q.foo(q); int k = q.foo(r); (Remember that in Java every object is accessed through a pointer and that methods...
Answer the following questions based on the given c file: #include #include #include    int c...
Answer the following questions based on the given c file: #include #include #include    int c = 0; void *fnC() {     int i;     for(i=0;i<10;i++)     {   c++;         printf(" %d", c);     }       } int main() { int rt1, rt2;   pthread_t t1, t2; int trial_count = 0; // For every trial, lets zero out the counter and run the count routine “twice”     // as threads that can be scheduled onto independent cores instead of running     // in sequence. for...
ONLY ANSWER PART C, D AND E 1A. Suppose The lifetime for a competing brands of...
ONLY ANSWER PART C, D AND E 1A. Suppose The lifetime for a competing brands of tires are independent of each other and approximately normal with unknown means but known variances σ^2= 975 miles^2 and σ^2= 965 miles^2. We gather did some testing under controlled conditions and have the following summary statistics: n1= 75 ̄x1= 3251.4 n2= 60 ̄x2= 3274.7 Construct a 80% confidence interval for the difference in population means,μ1−μ2. B.Using the same setup as part A, conduct a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT