Methods are commonly used to break a problem down into

Assignment Help JAVA Programming
Reference no: EM13347722

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: EM13347722

Questions Cloud

Part - 1q 1 define benchmarkingq 2 what is the need for : part - 1q. 1. define benchmarking.q. 2. what is the need for benchmarking?q. 3. what are the types of benchmarking?q.
Write a market research reportfinal conclusion of the : write a market research reportfinal conclusion of the launching of this mall either this shopping malls idea is
Part a write a program to evaluate the first 20 numbers of : part a write a program to evaluate the first 20 numbers of fibonacci series. use the stack memory to store the
Part-1reinforce understanding of power beta and : part-1reinforce understanding of power beta and alpha.problem a packing process is designed to fill steel drums with
Methods are commonly used to break a problem down into : methods are commonly used to break a problem down into small manageable pieces. a large task can be broken down into
This is a simulation of rolling dice actual results : this is a simulation of rolling dice. actual results approach theory only when the sample size is large. so we will
Problem 1 in a study relating college grade point average : problem 1 in a study relating college grade point average to time spent in various activities students are asked how
You will build a recursive-descent parser for the right : you will build a recursive-descent parser for the right recursive version of the classic expression grammar found in
The comma-separated values csv file format is a delimited : the comma-separated values csv file format is a delimited data format commonly used as a portable representation of

Reviews

Write a Review

JAVA Programming Questions & Answers

  Question hierarchy of section

Add a class AnyCorrectChoiceQuestion to the question hierarchy of Section 9.1 that allows multiple correct choices. The respondent should provide any one of the cor- rect choices. The answer string should contain all of the correct choices, separa..

  Write a class array that encapsulates an array

Write a class Array that encapsulates an array and provides bounds-checked access. The private instance variables should be int index and inarray[10]. The public members should be a default constructor and methods (signatures shown below) to provide ..

  Use a gui interface to control and display result of program

The scenario is inspired by a Library Management System (LIMS). For the first version of the project, the LIMS is a very basic one, allowing just for the import of data from a text file and perfom some basic search operations.

  Simulate a simple multiuser computer system

Prepare a java program to simulate a simple multiuser computer system

  Construct java program named collegelist

Construct a set of classes for a college to use in many student service and personnel applications. Classes you require to design include following:

  Java threads

This is an introductory assignment on Java synchronization. You will use Java Threads while learning more about concurrency and achieving atomicity using Java’s inbuilt mechanisms.

  Design implement and test an object-oriented java program

Design, implement and test an object-oriented Java program for processing single-variable polynomials represented as lists.

  List data structures to be used in solution

write a program that will prompt the user for an input file name to read from. The Input file will consist of records made up of first name, last name and an account balance of individuals and store the individuals in an ArrayList.

  Create a class named blooddata

Create a class named BloodData that includes fields that hold a blood type (the four blood types are O, A, B, and AB) and an Rh factor

  Solution for the problem and mention algorithms

Explain the purpose of the program as detail as possible and develop a solution for the problem and mention algorithms to be used and list data structures to be used in solution.

  Write applet which reads five numbers-draw equivalent stars

Write the applet which reads five numbers (each between 1 and 30). For each number read, your program must design line containing that number of adjacent asterisks.

  Design an abstract data type in java

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

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