Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Chapter 6 Computer Programming - Methods ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// [Please answer Task 3 with the missing code under the bolded sections] Code Listing 5.1 (Geometry.java) import java.util.Scanner;

Chapter 6 Computer Programming - Methods

image text in transcribed

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

[Please answer Task 3 with the missing code under the bolded sections]

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 method's return value char letter; // The user's Y or N decision double radius; // The radius of the circle double length; // 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; // The second side of the triangle double side3; // The third side of the triangle

// Create a scanner object to read from the keyboard Scanner keyboard = new Scanner(System.in);

// The do loop allows the menu to be displayed first do { // TASK #1 Call the printMenu method

choice = keyboard.nextInt();

switch (choice)

{ case 1: System.out.print("Enter the radius of " + "the circle: "); radius = keyboard.nextDouble();

// TASK #3 Call the circleArea method and // store the result in the value variable

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();

// TASK #3 Call the rectangleArea method and // store the result in the value variable

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();

// TASK #3 Call the triangleArea method and // store the result in the value variable

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(); // TASK #3 Call the circumference method and // store the result in the value variable

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();

// TASK #3 Call the perimeter method and // store the result in the value variable

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: "); side1 = 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();

// TASK #3 Call the perimeter method and // store the result in the value variable

System.out.println("The perimeter of " + "the triangle is " + value); break; default: System.out.println("You did not enter " + "a valid choice."); }

keyboard.nextLine(); // Consume the new line

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'); }

// TASK #1 Create the printMenu method here // TASK #2 Create the value-returning methods here // TASK #4 Write javadoc comments for each method }

Task #3 Calling Methods 1. Add lines in the main method in the GeometryDemo class which will call these methods. The comments indicate where to place the method calls 2. Below, write some sample data and hand calculated results for you to test all 6 menu items Sample data Input Expected output Actual o Menu iteml Menu item2 Menu item3 enu item4 Menu item5 enu item6 3. Compile, debug, and run. Test out the program using your sample data. Complete 3rd column (Actual output) in table above

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

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago