Question: The Task #1 only. please help!! Chapter 5 Lab Methods Lab Objectives . . Be able to write methods Be able to call methods Be




Chapter 5 Lab Methods Lab Objectives . . Be able to write methods Be able to call methods Be able to write javadoc comments Be able to create HTML documentation for our Java class using javadoc Introduction Methods are commonly used to break a problem down into small manageable pieces. large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct order. This also allows for efficiencies, since the method can be called as many times as needed without rewriting the code each time. Finally, we will use documentation comments for each method, and generate HTML documents similar to the Java APIs that we have seen. Task #1 void Methods 1. Copy the file Geometry.java (code listing 5.1) from the Student CD or as directed by your instructor. This program will compile, but when you run it, it doesn't appear to do anything except wait. That is because it is waiting for user input, but the user doesn't have the menu to choose from yet. We will need to create Task #1 void Methods 1. Copy the file Geometry java (code listing 5.1) from the Student CD or as directed by your instructor. This program will compile, but when you run it, it doesn't appear to do anything except wait. That is because it is waiting for user input, but the user doesn't have the menu to choose from yet. We will need to create this. 2. Above the main method, but in the Geometry class, create a static method called printMenu that has no parameter list and does not return a value. It will simply print out instructions for the user with a menu of options for the user to choose from. The menu should appear to the user as This is a geometry calculator Choose what you would like to calculate 1. Find the area of a circle 2. Find the area of a rectangle 3. Find the area of a triangle 4. Find the circumference of a circle 5. Find the perimeter of a rectangle 6. Find the perimeter of a triangle Enter the number of your choice: 3. Add a line in the main method that calls the printMenu method as indicated by the comments Code Listing 5.1 (Geometry.java) import java.util.Scanner: This program demonstrates static methods public class Geometry { public static void main(String args) int choice; //the user's choice double value = 0; //the value returned from the method char letter 1/the Y or N from the user's decision to exit double radius; //the radius of the circle double length; 1/the length of the rectangle double width; //the width of the rectangle double height: //the height of the triangle double base; //the base of the triangle double side1; // the first side of the triangle double side2 1/the second side of the triangle double side3; //the third side of the triangle Il create a scanner object to read from the keyboard Scanner keyboard = new Scanner (System.in); Ildo loop was chose to allow the menu to be displayed first do { Il call the printMenu method choice = keyboard.nextInt(); switch (choice) { case 1: System.out.print("Enter the radius of the circle: "); radius = keyboard.nextDouble(); I call the circle Area method and store the result in the value System.out.println("The area of the circle is" value); break; case 2: System.out.print("Enter the length of the rectangle: "); length = keyboard.nextDouble(); System.out.print("Enter the width of the rectangle: "); width = keyboard.nextDouble(); Il call the rectangle Area method and store the result in the value System.out.println("The area of the rectangle is + value); break; case 3: System.out.print("Enter the height of the triangle: "); height = keyboard.nextDouble(); System.out.print("Enter the base of the triangle: "); base = keyboard.nextDouble(); Il call the triangleArea method and store the result in the value System.out.println("The area of the triangle is " + value); break; case 4: System.out.print("Enter the radius of the circle: "); radius = keyboard.nextDouble(); Ilcall the circumference method and store the result in the value System.out.println("The circumference of the circle is + value); break; case 5: System.out.print("Enter the length of the rectangle: "); length = keyboard.nextDouble(); System.out.print("Enter the width of the rectangle: "); width = keyboard.nextDouble(); Il call the perimeter method and store the result in the value System.out.println("The perimeter of the rectangle is * + value); break; case 6: System.out.print("Enter the length of side 1 of the triangle: "); side 1 = keyboard.nextDouble(); System.out.print("Enter the length of side 2 of the triangle: "); side2 = keyboard.nextDouble(); System.out.print("Enter the length of side 3 of the triangle: "); side3 = keyboard.nextDouble(); Il call the perimeter method and store the result in the value System.out.println("The perimeter of the triangle is " + value); break; default: System.out.println("You did not enter a valid choice."); 3 Il consumes the new line character after the number keyboard.nextLine(); System.out.println("Do you want to exit the program (Y/N)?:"); String answer = keyboard.nextLine(): letter = answer.charAt(0); }while (letter != 'Y' && letter != 'y'); } }
Step by Step Solution
There are 3 Steps involved in it
To solve Task 1 you need to create a printMenu method and call it in the main method as per the given instructions Heres how you can do it Step 1 Create the printMenu Method Add the following static m... View full answer
Get step-by-step solutions from verified subject matter experts
