Methods

Assignment Help JAVA Programming
Reference no: EM131655

Methods are commonly used to break a problem down into small manageable pieces. A 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.

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.

4. Compile, debug, and run. You should be able to choose any option, but you will always get 0 for the answer. We will fix this in the next task.

Task -2

Value-Returning Methods

1. Write a static method called circleArea that takes in the radius of the circle and returns the area using the formula A = Πr2.

2. Write a static method called rectangleArea that takes in the length and width of the rectangle and returns the area using the formula A = lw.

3. Write a static method called triangleArea that takes in the base and height of the triangle and returns the area using the formula A = ½bh.

4. Write a static method called circleCircumference that takes in the radius of the circle and returns the circumference using the formula C = 2πr.

5. Write a static method called rectanglePerimeter that takes in the length and the width of the rectangle and returns the perimeter of the rectangle using the formula P = 2l +2w.

6. Write a static method called trianglePerimeter that takes in the lengths of the three sides of the triangle and returns the perimeter of the triangle which is calculated by adding up the three sides.

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.

3. Compile, debug, and run. Test out the program using your sample data. 

Reference no: EM131655

Questions Cloud

Benchmarking : What is the need for benchmarking?
Market research report : Market Research Report
Evaluate the fibonacci series : Write a program to evaluate the first 20 numbers of Fibonacci series.
Prepare a power curve for this decision rule : Prepare a power curve for this decision rule
Methods : Assignment describe the basic working of methods. How to write a method in java and how to call a method.
Loops and files : Convert an algorithm using control structures into Java and write a while loop
Explain the median housing price in a community : Explain the median housing price in a community
Top-down recursive descent parser : Write a hand-coded top-down recursive descent parser.
Convert csv file into html file : Convert CSV file into HTML file

Reviews

Write a Review

JAVA Programming Questions & Answers

  Design an abstract data type in java

Design an abstract data type in Java that represents a musical pitch

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Java problem - g queue

A queue is an ordered collection of items in which the removal of items is restricted to the FIFO ( rst in rst out) principle.

  Implement the lexical and syntactic analysis

Implement the lexical and syntactic analysis of Minifun programming language.

  Implementation activities of software development

Analysis, design, and implementation activities of software development

  Loops and files

Convert an algorithm using control structures into Java and write a while loop

  Record managing system application

Build a student record managing system application

  Create a driver class in java

Your project is to create a driver class that uses SuperJavaIceCreamClass.

  Implement avl tree

Implement AVL trees that allows both iterative traversal and recursive traversal.

  World data app

Prepare WorldDataApp project. It implements the NameIndex portion, including creating it in SetupProgram, and searching, viewing and updating it in UserApp program.

  Sorted list adt and the binary search tree adt

Explain the differences between our specifications of the Sorted List ADT and the Binary Search Tree ADT.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd