Concept explainers
Suppose every species in the world has a peculiar birthing pattern. After a female is born, a male is born, then a female, and so on. Give the definition of a method, called getFemalePopulation, that you could add to the definition of the class SpeciesFirstTry in Listing 5.3 to return the number of females in the population. Also, give the definition of a method called getMalePopulation that similarly returns the number of males in the population. If the population is an odd number, you have one species member left over after pairing males and females. Assume that species member is a female. For example, if the population is 7, there are 3 males and 4 females. But if the population is 8, there are 4 males and 4 females. (Hint: The definitions are 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 (4th Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Starting out with Visual C# (4th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Starting Out with Python (3rd Edition)
- In this exercise, you are going to build on your Circleclass from the previous exercise. You are going to add 2 method, areaDifference and perimeterDifference. Both methods take a doubleradius of a second circle and return the difference from the current circle. For example, if you create a Circle object with a radius of 4 and call areaDifference(3), you will return the diffence between the area of a circle with radius 4 and the area of a circle with a radius of 3. perimeterDifferencewould be the same. Make sure you create at least one Circle and test and print the results of your methods. given: public class Circle{private double radius;public Circle(double theRadius){radius = theRadius;}// Add a method called area that returns the area of a circle// using Math.PIpublic double area(){return Math.PI*radius*radius;}// Add a method called perimeter that returns the perimeter of a// circle using Math.PIpublic double perimeter(){return Math.PI*2*radius;}}arrow_forwardWrite a JAVA CODE with a main() method that asks the user to input an integer array of 10 elements.Next, create three methods described below. From inside your main() method, call each of thethree methods described below and print out the results of the methods 2, 3, which return values. 1. printReverse() - a method that receives an array of integers, then reverses the elements ofthe array and prints out all the elements from inside the method. Print all in one lineseparated by commas (see sample output below). Do not print the ‘trailing’ comma!!2. getLargest() – a method that receives an array of integers, then returns the largest integervalue in the array. Return largest integer and print from main(), not method.3. computeTwice()- a method that receives the previously reversed array of integers, thenreturns an array of integers which doubles the value of each number in the array (see thesample output below). Return new array of integers print from main(), not method.. USING A JAVA…arrow_forwardWrite a JAVA CODE with a main() method that asks the user to input an integer array of 10 elements.Next, create three methods described below. From inside your main() method, call each of thethree methods described below and print out the results of the methods 2, 3, which return values. 1. printReverse() - a method that receives an array of integers, then reverses the elements ofthe array and prints out all the elements from inside the method. Print all in one lineseparated by commas (see sample output below). Do not print the ‘trailing’ comma!!2. getLargest() – a method that receives an array of integers, then returns the largest integervalue in the array. Return largest integer and print from main(), not method.3. computeTwice()- a method that receives the previously reversed array of integers, thenreturns an array of integers which doubles the value of each number in the array (see thesample output below). Return new array of integers print from main(), not method.. THE OUTPUT…arrow_forward
- Write a JAVA CODE with a main() method that asks the user to input an integer array of 10 elements.Next, create three methods described below. From inside your main() method, call each of thethree methods described below and print out the results of the methods 2, 3, which return values. 1. printReverse() - a method that receives an array of integers, then reverses the elements ofthe array and prints out all the elements from inside the method. Print all in one lineseparated by commas (see sample output below). Do not print the ‘trailing’ comma!!2. getLargest() – a method that receives an array of integers, then returns the largest integervalue in the array. Return largest integer and print from main(), not method.3. computeTwice()- a method that receives the previously reversed array of integers, thenreturns an array of integers which doubles the value of each number in the array (see thesample output below). Return new array of integers print from main(), not method.. THE OUTPUT…arrow_forwardRedefine the equals method of the class Date (Display 4.13) so that it hasa parameter of type Object and follows the other guidelines we gave for anequals method. (Remember, you should use getClass(), not instanceof.)arrow_forwardWe have two classes; these classes are "Car" and "Price".The "car" class is a class that keeps the id and price of the car.If the "Price" class is, there will be get / set methods for the segment of the fee (For example Y segment Z segment), the number of cars, and the "Car" class list.In the "Price" class, there should be a print method to add / remove cars to the list and find the ids of Vehicles whose segments are equal to X.The segments are as follows. 0$ -15999$ -> Y Segment16000$-24999$ -> Z Segment25000$-50000$ -> T Segment It is necessary to use "Single Linked List".The program should be written in JAVA.arrow_forward
- Write a compareTo method that compares two Song objects based on the artist, and title within artist. For example, given the following Songobjects: "Glass Animals""Heat Waves" "Elton John, Dua Lipa""Cold Heart" "Adele""Easy on Me" "Doja Cat""Kiss Me More" "Adele""My Little Love" They will be put in the following order: "Adele""Easy on Me" "Adele""My Little Love" "Doja Cat""Kiss Me More" "Elton John, Dua Lipa""Cold Heart" "Glass Animals""Heat Waves" In which class does the compareTo method belong?arrow_forwardImprove the method printList to print out the details of all publications ordered on the category of the publications, and then on the title within each category. Note: currently there are only 2 categories, i.e. Book and Journal, but the project may be expended by adding other categories, e.g. Newspaper etc. Here are my four classes. public class Database {private ArrayList<Publication> publicationList; // An array list collection of publications /*** Create a new database*/public Database() {publicationList = new ArrayList<Publication>();} /*** Add a publication** @param publication The publication to be added*/public void addPublication(Publication publication) {if (publicationList.contains(publication)) {System.out.println("This publication has already been added to the list: " + publication);} else {publicationList.add(publication);}} /*** Get the total number of publications** @return The total number of publications*/public int getTotal() {return…arrow_forwardDefine a Static method 'max' with return type as 'int' in class 'ProblemSolution' that take two numbers with type 'int'. Inside the 'max' method, compare the two numbers and return the maximum of the two numbers. Then, inside the 'main' method. Define two 'int' type numbers; the first number (num1) is equal to 5 and the second number (num2) is equal to 2. At the next line, call the 'max' method where its parameter input are the two numbers above, and assign the result of the method to the variable num3 (type 'int'). Finally, on the next line, print out -> "The maximum of " + num1 + " and " + num2 + " is " + num3 Output The maximum of 5 and 2 is 5 Where, There must be space between all the words and numbers. There should not any space after the last numberarrow_forward
- Write a program with a main() method that asks the user to input an integer array of 10 elements.Next, create three methods described below. From inside your main() method, call each of thethree methods described below and print out the results of the methods 2, 3, which return values. 1. printReverse() - a method that receives an array of integers, then reverses the elements ofthe array and prints out all the elements from inside the method. Print all in one lineseparated by commas (see sample output below). Do not print the ‘trailing’ comma!!2. getLargest() – a method that receives an array of integers, then returns the largest integervalue in the array. Return largest integer and print from main(), not method.3. computeTwice()- a method that receives the previously reversed array of integers, thenreturns an array of integers which doubles the value of each number in the array (see thesample output below). Return new array of integers print from main(), not methodEXAMPLE OUTPUT:Enter…arrow_forwardIn Java In the Jackal class, complete the public method definition for setAge() with the integer parameter customAge. Ex: If the input is black Mia 3, then the output is: Color: black Name: Mia Age: 3arrow_forwardFor all methods in each class (labeled), how do I write the JUnit 4 test(s) to test all methods? Full code is shown below: PunctuationNode.java (class) public class PunctuationNode implements Sentence { private String punctuation; private Sentence rest; /** * This is a constructor for class PunctuationNode. * * @param punctuation - a String. * @param rest - a String. */ public PunctuationNode(String punctuation, Sentence rest) { this.punctuation = punctuation; this.rest = rest; } /** * A method to get number of words. * * @return - a integer. */ @Override public int getNumberOfWords() { return this.rest.getNumberOfWords(); } /** * A method to get longest word. * * @return - a integer. */ @Override public String longestWord() { return this.rest.longestWord(); } /** * Returns a String that represents a sentence. * * @return - a Sentence. */ @Override public String toString() { return this.punctuation +…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