Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

8 9 // // Directions: Implement the following methods // // 10 11 12 // Goal understand using Static classes i.e. the Math class was

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

8 9 // // Directions: Implement the following methods // // 10 11 12 // Goal understand using Static classes i.e. the Math class was not designed to be Instantiated (make objects) // It is a class that provides functionality and will be used to complete one of the methods import java.lang. Math; public class Lab2Exercises { // computes area of a hexagon when given its side public static int areaOfAHexagon(double a) { //TODO } 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 // computes perimeter of a hexagon when given its side public static int perimeterOfAHexagon (double a) { //TODO } asww85% // Returns the count of character that are vowels in the given String // Also print the given string in lowercase. // We suggest using built-in String methods (not a loop). // https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/String.html public static int countVowels(String str) { //TODO A A } // TODO A } 22 23 24 25 26 27 28 29 30 31 32 33 // computes perimeter of a hexagon when given its side public static int perimeterOfAHexagon(double a) { //TODO } // Returns the count of character that are vowels in the given String // Also print the given string in lowercase. // We suggest using built-in String methods (not a loop). // https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/lang/String.html public static int countVowels(String str) { //TODO A } 34 35 36 37 38 39 40 41 O // Use a Scanner to reads a number (integer) that is exactly 5 digits long and print it in reverse // for example: 12304 will be printed as 40321. Your solution doesn't need to work for numbers ending in zero(es) // or numbers that aren't exactly 5 digits long. // You MUST use divide and/or modulus operators and may save part of the number, then concatenate back // together as a string and return it. 42 43 A 44 45 public static String reverse5DigitNumber(double usrNumber) { //TODO } 46 47 48 49 50 51 // test client public static void main(String[] args) { //TODO: Modify to test all methods from above. // Use Scanner to read inputs from user. Don't use Scanner inside above functions! 52 e A } 53 54 55 56 } 12 13 14 15 16 17 18 19 20 A class Lab2CompoundExercises { public static void main(String args[]){ differentOperators(); question20; } // 1. Review the following method (differentOperators). You will create two new methods, name them as you see fit, and implement the following changes: // la. Change differentOperators to use ONLY simple-assignment operators and not compound. All printf statements should print the // same values. // 1b. Change differentOperators() to use a post-increment operator each time there used to be a pre-increment operator, // and vice versa. Does this change the result? public static void differentOperators({ 21 22 int result = 11; // result is 11 System.out.println(result); result--; // result is now 10 System.out.println(result); 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 result /=- 2; // result is now -5 System.out.println(result); result *=- 20; // result is now 100 System.out.println(result); result %=+ 4; // result is now o System.out.println(result); result++; // result is now 1 System.out.println(result); 41 } 42 43 43 44 45 46 47 48 49 50 51 52 53 54 55 // 2. In the following program, using comments in this file, explain why the value "6" is printed thrice in a row: // Also, explain why "g" became "6" from line 51 to 52. public static void question20 { int i = 6; ++i; System.out.println(i); // "7" i++; System.out.println(i--); // "8" System.out.println(-i); // "6" System.out.println(i--); // "6" System.out.println(++i); // "6" A } } 56

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

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago