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

I. Answer part A,B, C and D. 1a) Count the number of times a given char...
I. Answer part A,B, C and D. 1a) Count the number of times a given char occurs in a given range of a String parameter (i.e. starting at a given start index, and up to but not including and end index). If end is greater than the length of the String, then the method should stop looking at the end of the String. countCharsInRange("java", "v", 1, 2) → 0 countCharsInRange("java", "v", 0, 2) → 0 countCharsInRange("java", "v", 0, 3) →...
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...
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...
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.
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....
This is a question about C# programming: True / False questions: for (int i=5; i <...
This is a question about C# programming: True / False questions: for (int i=5; i < 55; i+=5) { decimal decPrcPerGal = decGalPrc + i; decPayPrc = iBuyGall * decPrcPerGal; if (decPrcPerGal > decMAX_GALPRC) { continue; } if (decPrcPerGal > decMAX_GALPRC) { break; } Console.WriteLine(" {1} gallon(s) at {0,3} would cost {2,8:$###,##0.00}", decPrcPerGal, iBuyGall, decPayPrc); } In the code above: 1. If decGalPrc is 10.57 decPrcPerGal will always be some number of dollars and 57 cents   True/ False? 2. In...
C++ EXERCISES (a) Given int a = 5, b = 2, c = 4, and d...
C++ EXERCISES (a) Given int a = 5, b = 2, c = 4, and d = 5; determine the value of the expression: d % b * c > 5 || c % b * d < 7.    (b) Which repetition statement is preferred for user data input and its validation?              (c) Write a for statement to populate an array, double val[NUMCOUNT], for the following case: Use a counter named double count that has an initial value of 16.2,...
In Python Complete the oddNumbers() functions to take an int (as a parameter). Return a list...
In Python Complete the oddNumbers() functions to take an int (as a parameter). Return a list of all of the odd numbers between 1 and one less than the parameter. Also, complete the evenNumbers() functions to take an int (as a parameter). Return a list of all of the even numbers between 2 and one less than the parameter.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT