Concept explainers
(Geometry: area of a pentagon) The area of a pentagon can be computed using the following formula:
Write a method that returns the area of a pentagon using the following header:
public static double area(double side)
Write a main method that prompts the user to enter the side of a pentagon and displays its area. Here is a sample run:
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Modern Database Management
Thermodynamics: An Engineering Approach
Electric Circuits. (11th Edition)
SURVEY OF OPERATING SYSTEMS
Java: An Introduction to Problem Solving and Programming (8th Edition)
Starting Out With Visual Basic (8th Edition)
- use only C# programming Write a method call CubeIt(int x, ref int cube) that takes two arguments and does not return a value. The method will cube the first argument and assign it to the second argument.In your main, call this method twice and print the value of the parameters after each method call. Write a method with the following header: static void CalculateTuitionFee(int numberOfCourses, double costPerCourse, ref double fees). This method will calculate and assign the required fees amount to the third argument. [Fees = number of courses * cost per course + 15.25].From your program Main() method, call the CalculateTuitionFee () method four times supplying different arguments each time and display the value of the third argument after each method call. Write a method that takes four parameter of type int. The method will assign the sum of the first two arguments to the third and the difference of the first two to the fourth. This method should be coded so that the calling…arrow_forwardWrite a method that returns a random number from alist of numbers passed in the argument. The method header is specified as follows:public static int getRandom(int... numbers)arrow_forwardUsing METHOD SAMPLE Problem: Create a method that will compute the value of PI, if pi is 3.14. Given formula is : value = pi x square of radius Solution: float area(int radius) final float pi = 3.14f; float val; val = pi * (float) (radius * radius); return(val); Direction: Analyze the given problem and create a java method. Problem: Create a method that will compute the Mass (m). Acceleration(a) is 9.80. if Force (F) is equal to acceleration multiplied by mass.arrow_forward
- Use java code to completearrow_forwardJAVA Notes: all program codes should be written with method/s separated from the main() structure. Use a separate code files for each. Programming Problems: 1. Write a value-returning method, isVowel, that returns the value true if a given character is a vowel, otherwise return false. Also write a program to test your method. 2. Write a program that prompts the user to enter a sequence of characters and output the number of vowels and consonants separately. (use the method isVowel written in problem 1). 3. Write a program that output inflation rates for two successive years and whether the inflation rates are increasing or decreasing. Ask the user to input the current price of an item and its price, one year and two years ago. To calculate the inflation rate for a year, subtract the price of the item for that year and from the price of the item from one year ago and then divide the result by the price a year ago. Your program must contain a method to calculate the results. Use…arrow_forward2. A pentagonal number is defined as n(3n-1)/2 for n = 1, 2, ..., etc.. Therefore, the first few numbers are 1, 5, 12, 22, ... . Write a method with the following header that returns a pentagonal number: %3D public static int getPentagonalNumber(int n) For example, getPentagonalNumber(1) returns 1 and getPentagonalNumber(2) returns 5. Write a test program that uses this method to display the first 100 pentagonal numbers with 10 numbers on each line. Numbers are separated by exactly one space.arrow_forward
- Please solve the question for beginners in programming 1. Write a method that receives the radius and returns the area of a circle. 2. Write a main method that calls the previous methodarrow_forwardpublic static int cube(int num { return num num num; } What is the correct statement to pass value 8 to this method and assigns its return value to a variable named result? O cube(8) = int result; int result = cube(8) O int result = O int result = int cube(8);arrow_forwardWrite the following two methods: computeDiameter: This method accepts the radius (r) of a circle, and returns its diameter (2*r; radius = 7.5). Declare all variables used here & initialize radius: Show method call: Write method code here: displayData: This method accepts two arguments: radius & diameter. The output should have appropriate messages on the screen. Show method call: Write method code here:arrow_forward
- Write a method that finds the average of 4 double numbers. The parameters consist of 4 double numbers read in main and then passed to the method. The method will then return the average to main which will display the value to the user. public static double avg (double a, double b, double c, double d)arrow_forwardLook at the header of the method below, and then implement a sample call to it in your code.private static void ShowValue ()arrow_forwardJava: Class: WordCount Write a method using the header below (remember your Javadoc comment) public static int countWords(String str) that returns a count of all words in the string str. Words are separated by spaces. For example, countWords("Mary had a little lamb") should return 5. Your method should work correctly if there are multiple spaces between words. Use helper methods to find the position of the next space following a given position, and the position of the next non-space character following a given position. Write a test program [main()] to test the method.arrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage