Define a method called changePopulation that could be added to the definition of the class SpeciesSecondTry in Listing 5.6. This method has two parameters. One parameter, named area, is of type double and gives the area occupied by the species in square miles. The other parameter, named numberPerMile, is of type int and gives the desired number of individuals per square mile. The method changePopulation changes the value of the instance variable population so that the number of individuals per square mile is (approximately) equal to numberPerMile.
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Concepts of Programming Languages (11th Edition)
C Programming Language
C How to Program (8th Edition)
- I have a Programming Question, The following is a class definition for a simple Ebook. So i need to write a second constructor that takes a String array of pages as input and sets the String array instance variable equal to the input. Continue to default the current page number to zero. Part 2: Write a getter and a setter method for the page number variable. The setter should check to make sure that the input is a valid page number and only update the variable if the new value is valid. Part 3: Write a getCurrentPage method that returns the String of the current page indexed by current_page. Here below are the two instance variables and one parameterless constructor that were provided public class Ebook{ private String[] pages; private int current_page; //constructor public Ebook() { this.pages = {"See Spot.", "See Spot run.", "Run, Spot, run."}; this.current_page = 0; }}arrow_forwardbox1 and box2 are instances of the Box class. Attributes length, width, and height of both box1 and box2 are read from input. Then, two strings are read from input. In the Box class, define instance method print_measurements() with self and one string as parameters to output the string parameter in one line, and the following in the next line: The value of attribute length ' by ' The value of attribute width ' by ' The value of attribute heightarrow_forwardCreate a class with a method. The method has to decide whether a given year is a leap year or not. Note- A year is a leap year if: • It has an extra day i.e. 366 instead of 365. It occurs in every 4 year e.g. 2008, 2012 are leap years. For every 100 years a special rule applies-1900 is not a leap year but 2000 is a leap year. In those cases, we need to check whether it is divisible by 400 or not. > > ClassAssignmentEx2 ©LeapYearDecider javaclassnotes.assignments javaclassnotes.assignments ClassAssignmentEx2() LeapYearDecider() main(String):void A isLeapYear(int):booleanarrow_forward
- 2A. Create a Date class with three integer instance variables named day, month, year. It has a constructor with three parameters for initializing the instance variables, and it has one method named daysSinceJan1(). It computes and returns the number of days since January1ofthe same year, including January 1 and the day in the Date object. For example, if day is a Date object with day = 1, month = 3, and year = 2000, then the call date.daysSinceJan1( ) should return 61 since there are 61 days between the dates of January 1, 2000, and March 1, 2000, including January1 and March 1. Include a DateDemo class that tests the Date class. Don't forget leap years. %3D %3Darrow_forwardWrite a program that test methods in the class. • Hint: the employee deserved retirement if he has year of Service >25 or his age >=65. 5. Design a class named MyInteger. The class contains: • An int data field named value(int) Methods isEven() and respectively. Write a program that test methods in the class. isOdd() that return true if the value is even or odd.arrow_forwardthis is for a python class 9.12 LAB: Product class In main.py define the Product class that will manage product inventory. Product class has three attributes: a product code, the product's price, and the number count of product in inventory. Implement the following methods: A constructor with 3 parameters that sets all 3 attributes to the value in the 3 parameters set_code(self, code) - set the product code (i.e. SKU234) to parameter code get_code(self) - return the product code set_price(self, price) - set the price to parameter price get_price(self) - return the price set_count(self, count) - set the number of items in inventory to parameter count get_count(self) - return the count add_inventory(self, amt) - increase inventory by parameter amt sell_inventory(self, amt) - decrease inventory by parameter amt Ex. If a new Product object is created with code set to "Apple", price set to 0.40, and the count set to 3, the output is: Name: Apple Price: 0.40 Count: 3 Ex. If 10…arrow_forward
- Write a program that test methods in the class. • Hint: the employee deserved retirement if he has year of Service >25 or his age >=65. 5. Design a class named MyInteger. The class contains: • An int data field named value(int) ● Methods isEven() and respectively. Write a program that test isOdd() that return true if the value is even or odd. methods in the class.arrow_forwardFor the Faculty class, create the following: A private int instance variable m_salary. A constructor that takes three parameters (in the order of name, department, salary). It should use the parameter for salary to set the m salary instance variable and then explicitly call the parent class constructor using the super keyword and pass in the two other parameters. A getPaycheck method that implements the same method in the Employee class. It returns the faculty member's paycheck as a string in the following format (the amount of money is equal to m_salary): Pooh-Mathematics-$50000arrow_forwardDefine a class called Country. A Country has population S ize, area, capital, currency, and abbreviation ( (2-3 letters taken from the country name). Define at least two constructors, at least two getter methods, at least two setter methods, and Override the toString() method and the equals() method. The equals() method must return true if the two countries have the same name and same area and false otherwise The abbreviation is the first letter and the letter before the last of the country name and must be generated automatically eg if the country name is Palestine the abbreviation is PN, if the country name is Jordan the abbreviation is JA) Write a main method, define an array of country objects, read countries data from the user, if two countries have the same abbreviation add the last letter from the country name to the abbreviation o one million. f the country inserted last Display countries whose populationSize is greater thanarrow_forward
- IN C++ Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon or liters/km—pick one) and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. Provide another parameterized constructor which takes both efficiency and fuel as parameters. Also supply methods getGasInTank, returning the current amount of gasoline in the fuel tank. getEfficiency() return the efficiency of car. setGasInTank(double fuel), to add gasoline to the fuel tank. setEfficiency(double efficiency) Supply a method Drive () that simulates driving the car for a certain distance, reducing the amount of gasoline in the fuel tank according to its efficiency. Sample usage: Car myHybrid (50); // 50 miles per gallon myHybrid.addGas(20); // Tank 20 gallons myHybrid.Drive(100); // Drive 100 miles double gasLeft = myHybrid.getGasInTank(); // Get gas remaining in tank Supply a main method that tests…arrow_forwardWrite Java program for given scenarios below: Create a class named 'Member' having the following members: Data members 1 - Name 2 - Age 3 - Phone number 4 - Address 5 - Salary It also has a method named 'printSalary' which prints the salary of the members. Two classes 'Employee' and 'Manager' inherits the 'Member' class. The 'Employee' and "Manager' classes have data members 'specialization' and 'department' respectively. Now, assign name, age, phone number, address and salary to an employee and a manager by making an object of both of these classes and print the same.arrow_forwardWrite a class Cylinder that contains information about a cylindrical object. The Cylinder class must have two instance variables: self.r is a floating point value describing the radius of the cylinder self.h is a floating point value describing the height of the cylinder The Cylinder class should also have a constructor and two methods: • _init__(self, diameter, height) takes in two parameters other than self, representing the diameter of the cylinder, and the height, and uses this information to set up self.r and self.h. Note that to get the radius (self.r) from the diameter, you'll need to divide by 2. • get_surface_area(self) returns the surface area of the cylinder, given by the formula: A = 2лr² + 2лrh You should import math and use math.pi to get an accurate value for get_volume (self) returns the volume of the cylinder, given by the formula: V = πr²harrow_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