Define a method called getDensity that could be added to the definition of the class SpeciesSecondTry in Listing 5.6. This method has one parameter of type double that is named area. The parameter area gives the area occupied by the species, expressed in square miles. The method getDensity returns a value of type double that is equal to the number of individuals per square mile of the species. You can assume that the area is always greater than zero. (Hint: The definition is very short.)
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Java: An Introduction to Problem Solving and Programming plus MyProgrammingLab with Pearson eText -- Access Card Package (7th Edition)
Additional Engineering Textbook Solutions
Starting Out with Python (3rd Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Starting Out With Visual Basic (8th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
- Write a class called Investment with fields called principal and interest. The constructor should set the values of those fields. There should be a method called value_after that returns the value of the investment after n years. The formula for this is p(1+i)ⁿ, where p is the principal, and i is the interest rate.arrow_forwardpython pleaseWrite a class called Point that represents a point in 2D plane.- The constructor accepts the x and y dimensions of the point.- Provide a method getX that returns the x coordinate of a point, and another method getYthat returns the y coordinate of a point.- Provide a method called translate that changes the original coordinates of the point byadding a given values for x and y coordinates.- Provide a method distanceTo that calculates the distance between that point and anotherone.Use this equation to calculate the Distance math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2))While the math is a library you should import. Where the (x1, y) is the coordinates of the first pointand (x2, y2) is the coordinates of the second pointThe output should be like this screenshot.arrow_forwardin class Song, write the calculation in method getEstEarnings of class Song to evaluate estimated earnings. Note that while in the real world, other methods would be used to estimate earnings, in this simplified model, the estimated earnings will be the length of the title, multiplied by the a value extracted by the ministry using the method getSongPartEst(hint.. the singer keeps a reference to the ministry. You can observe how the reference is used in method getClaimableEarnings). public int getEstEarnings() { return 0;//Q2. Perform this calculation } public int getClaimableEarnings() { int est = getEstEarnings(); if (est > singer.getMinistry().getMinClaimable()) return est; else return 0; }arrow_forward
- In Java As discussed in the class, overloaded methods are two or more methods in the sameclass that use the same name but differ in the signature. Following are headings forthree overloaded findMinimum methods.int findMinimum(int a, int b, int c)double findMinimum(double a, double b, double c)double findMinimum(double a, double b, double c, double d).These methods should return the given arguments' minimum (smallest) value. Yourtask is to implement these static overloaded methods.public class Minimum{ public static void main(String args []) { int oneI = 50; // first number int twoI =14; // second number int threeI =18; // third number double oneD = 44.0; // first number double twoD =14.0; // second number double threeD =18.0; // third number double fourD =0.0; System.out.println("The minimum of" + oneI + ","+ twoI + "," + "and" +threeI + "is:" + findMinimum(oneI,twoI,threeI); System.out.println("The minimum of" + oneD + ","+ twoD + "," + "and" +threeD +"is:" + +…arrow_forwardAdd another public method dblValue() to the Fraction class which returns the double precision approximation value of the fraction. That is, the floating point result of actually dividing numerator by denominator. N.B. this method does not do any display itself, but can be called by a client program to be used in an output statement. Eg: if a client has a fraction frac that represents 1 / 2,then a method call to frac.dblValue() should return the double number 0.5.Use the client program to test this functionality; i.e. provide an outputstatement to display the double value of a fraction. import java.util.ArrayList;import java.util.Scanner; //Define the class Fractionclass Fraction{private int n, d;public Fraction(){//Initialize the valuesthis.n = this.d = 0;}public Fraction(int n, int d){//Initialize the variablesthis.n = n;this.d = d;}//Define the getter function getNum() that returns the numeratorpublic int getNum(){//Returns numeratorreturn n;}//Define the getter function getDen()…arrow_forwardCould you please help me with this Exercise? The language is JAVA. Thank You! Exercise 11.4 A “rational number” is a number that can be represented asthe ratio of two integers. For example, 2/3 is a rational number, and you canthink of 7 as a rational number with an implicit 1 in the denominator. The purpose of this exercise is to write a class definition that includes a va-riety of methods, including constructors, static methods, instance methods, modifiers, and pure methods:1. Define a class called Rational. A Rational object should have twointeger instance variables that store the numerator and denominator.2. Write a constructor that takes no arguments and sets the numerator to0 and denominator to 1.3. Write an instance method called printRational that displays a Rationalobject in a reasonable format. 11.10 Exercises 199 4. Write a main method that creates a new object with type Rational,sets its instance variables to the values of your choice, and displays theobject.5. You now have…arrow_forward
- Write a java program in a class CountPoor that counts the number of families that are considered poor. Write and use a class Family that has the attributes. income—a double value that is the income for the family size—the number of people in the family and the following methods: Family(income, size)—a constructor that sets the attributes isPoor(housingCost, foodCost)—a method that returns true if housingCost + foodCost * size is greater than half the family income (foodCost is the average food cost for an individual, while housingCost is for the family) toString—a method that returns a string containing the information about the family The program should read an integer k from the keyboard and then create an array of size k whose base type is Family. It should then create k objects of type Family and put them in the array, reading the income…arrow_forwardWrite a program that calls methods for each of the following mini problems from its main method. Us a single Scanner for the program declared in the class asprivate Static Scanner keyboard = new Scanner(System.in); Write a method that reads a line of text from the keyboard and then displays the line, but with the first occurrence of hate changed to love. For example, a possible sample dialogue might beEnter a line of text.I hate you.I have rephrased that line to read:I love you.You can assume that the word hate occurs in the input. If the word hate occurs more than once in the line, your program will replace only its first occurrence. Write a method that asks the user to enter a favorite color, a favorite food, a favorite animal, and the first name of a friend or relative. The program should then print the following two lines, with the user’s input replacing the items in italics: I had a dream that Name ate a Color Animal and said it tasted like Food!For example, if the user entered…arrow_forwardCan you implement an interface in your class? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first. Problem Statement# You are given an interface Addition which contains a method signature int add(int num1, int num2). You need to write a class called Calculator which implements the Addition interface. The add(int, int) method takes two integers and returns their sum. Input# Calls the add(int, int) method by passing num1 and num2. Output# Returns the addition of num1 and num2.arrow_forward
- In Public Class, create a static void method called Info_AHW that takes 3 parameters - an int and two double. When the method is called, we pass along the age (A), then the height (H), and then the weight (W), which is used inside the method to print the person's age, then the height and then the weight. NOTE: The Print out must follow the output below Afterward, in the main method, get the User input using the Scanner class to get the three input - the int age, the double height and the double weight. Then, call your Info_AHW method and pass your arguments (age, height, weight) into that method. Hint: When getting the int input, use -> sc.nextInt(); When getting the double input, use -> nextDouble(); Input: 5 65.5 70.2 Output: Your age is 5 ; your height is 65.5 ; and your weight is 70.2 Note: -There is a single space between every word and semicolon -There is no space at the endarrow_forwardWrite a new method for the atom class called ision that will return true or false, depending upon whether the atom is an ion. An atom is an ion if it is charged (i.e., if the number of electrons ≠ the number of protons).arrow_forwardWrite a program that simulates the Magic 8 Ball game. The class should have a method that returns an answer at random. Test your class by outputting the answer several times.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education