Menu

(Solved) : Part 1 1 Exercise Write Method Takes Single Argument Integer Prints Number Passed Whether Q44128697 . . .

In Java pleasePart 1 1. In this exercise you will write a method that takes a single argument, an integer, and prints the number passed inIf user enters 2 and 999, then sartSumBucketer (input); // Should print - Greater than 30. Part 3 Boolean Expressions Using1. Create a method called intToWord which takes as an argument an integer. Using a switch, return rock if the argument is 0

Part 1 1. In this exercise you will write a method that takes a single argument, an integer, and prints the number passed in and whether or not it is even or odd. This method is named oddEvenChecker, and should work as follows: oddEvenChecker (3); // Should print “3 is an odd number” oddEvenChecker (8); // Should print “8 is an even number is helpful to know about the modulo operator, represented in Java by the symbol %. Modulo returns the remainder of the number in front of it divided by the number behind it-so for example, the value of the expression 7% 3 is 1 (because 7 divided by 3 is 2 with a remainder of 1). 2. Now implement another method, multipleOfChecker, that takes two arguments, both integers. It then prints whether or not the first number is a multiple of the second number. For instance: multipleOfChecker (16 , 4); // Should Print “16 is a multiple of 4” multipleOfChecker (11,3); // Should Print “11 is not a multiple of 3” You should test your methods in main using various combinations of inputs to rule out any logical bugs. Part 2 In this exercise you will write a method that takes a Scanner object from main and uses it to ask the user to input two doubles using the keyboard, surns their square roots, and prints a statement based on what bucket the result is in. The possible buckets are “Less than 10″,”Between 10 and 20”, “Between 20 and 30”, and “Greater than 30.” Negative numbers should be rejected with the appropriate message printed to the user. The method is named sqrtSunBucketer and it should work as follows: If user enters 23 and 16, then sartSumBucketer (input ); // Should print – Less than 10″ If user enters 2 and 999, then sartSumBucketer (input); // Should print – Greater than 30.” Part 3 Boolean Expressions Using pen and paper, figure out the truth-value of the following boolean expressions. Then put the following code in your Lab3’s main and run it to check your answers. You will have to use print statements to check them. Please upload a picture of your handwritten work. boolean isFiveLess – 5 < 15; boolean isEven – ( % 2 — 0); boolean isOdd = ! (isEven); boolean istenLessOrEqual = ( 10 <= 160/10); int a – 3, int b – 5; boolean i SALess – 0 <b; Part 4 1. Write a method that takes two distinct numbers as input and returns the greater of the two values. Unlike in lab 2. you are NOT allowed to use any library functions in this method (such as Math.max or Math.min). 2. Write a method that takes three distinct numbers as input and returns the smallest of the three values Unlike in lab 2, you are NOT allowed to use any library functions in this method (such as Math.max or Math.min). Hint: usc nested if statements. Part 5 For the final part of the lab, we will ask you to create a version of rock-paper-scissors game. This program will take a user input of 0, 1, or 2. which represent “rock”, “paper” or “scissors” respectively. You will then generate a random number for the computer between 0 and 2. Then, decide and print the winner of the game. 1. Create a method called intToWord which takes as an argument an integer. Using a switch, return “rock” if the argument is 0, “paper” for 1, and “scissors” for 2. If the integer is not 0, 1, or 2 print “invalid selection”. 2. Create a method findWinner which takes as arguments two integers: user and compchoice, and determines the winner It should return one of three strings: “Tie.” “<compChoices beats <userChoices. I win.” “<userChoice> beats <compChoices. You win,” 3. Fill out the main method such that a user must choose a number, then the computer randomly generates a number between 0 and 2, and then on of the the following strings are printed by calling the methods you wrote previously: “You chose <userChoices. I choose <compChoices. <winner beats closer. <winner win.” “You chose <userChoices. I choose <comp Choices. Tie.” e.g. “You chose rock. I chose paper. paper beats rock. I win.” e.g. “You chose paper. I chose paper. Tie.” e.g. “You chose paper. I chose rock. paper beats rock. You win.” Extra (Not for credit): Can you adjust your program so that ties cause you to re-run the game? Part 6 Remember to submit your java code to Canvas! Show transcribed image text Part 1 1. In this exercise you will write a method that takes a single argument, an integer, and prints the number passed in and whether or not it is even or odd. This method is named oddEvenChecker, and should work as follows: oddEvenChecker (3); // Should print “3 is an odd number” oddEvenChecker (8); // Should print “8 is an even number is helpful to know about the modulo operator, represented in Java by the symbol %. Modulo returns the remainder of the number in front of it divided by the number behind it-so for example, the value of the expression 7% 3 is 1 (because 7 divided by 3 is 2 with a remainder of 1). 2. Now implement another method, multipleOfChecker, that takes two arguments, both integers. It then prints whether or not the first number is a multiple of the second number. For instance: multipleOfChecker (16 , 4); // Should Print “16 is a multiple of 4” multipleOfChecker (11,3); // Should Print “11 is not a multiple of 3” You should test your methods in main using various combinations of inputs to rule out any logical bugs. Part 2 In this exercise you will write a method that takes a Scanner object from main and uses it to ask the user to input two doubles using the keyboard, surns their square roots, and prints a statement based on what bucket the result is in. The possible buckets are “Less than 10″,”Between 10 and 20”, “Between 20 and 30”, and “Greater than 30.” Negative numbers should be rejected with the appropriate message printed to the user. The method is named sqrtSunBucketer and it should work as follows: If user enters 23 and 16, then sartSumBucketer (input ); // Should print – Less than 10″
If user enters 2 and 999, then sartSumBucketer (input); // Should print – Greater than 30.” Part 3 Boolean Expressions Using pen and paper, figure out the truth-value of the following boolean expressions. Then put the following code in your Lab3’s main and run it to check your answers. You will have to use print statements to check them. Please upload a picture of your handwritten work. boolean isFiveLess – 5

Expert Answer


Answer to Part 1 1. In this exercise you will write a method that takes a single argument, an integer, and prints the number passe…

OR