Absolute Java (6th Edition)
Absolute Java (6th Edition)
6th Edition
ISBN: 9780134041674
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
Question
Book Icon
Chapter 4, Problem 10PP
Program Plan Intro

To modify the code that is mentioned in the Display 4.15 and 4.16 in chapter-4 by adding the instance variable to specify whether the type of pet is cat or dog. Also, modify the constructors of Display 4.15 and add some methods, such as acepromazine and carprofen.

Program Plan:

Modify a code in Java and add some methods, such as acepromazine and carprofen. Also, add one instance variable to specify the type of pet and modify the constructor as well.

Blurred answer
Students have asked these similar questions
Modify the student class presented in this chapter as follows. Each student object should also contain the scores for three tests. Provide a constructor that sets all instance values based on parameter values. Overload the constructor such that each test score is assumed to be initially zero. Provide a method called setTestScore that accepts two parameters: the test number (1 through 3) and the score. Also provide a method called getTestScore that accepts the test number and returns the appropriate score Provide a method called average that computes and returns the average test score for this student. Modify the toString method such that the test scores and average are included in the description of the student. Modify the driver class main method to exercise the new Student methods. (c++ language)
Modify the Car class example and add the following:  A default constructor that initializes strings to “N/A” and numbers to zero.  An overloaded constructor that takes in initial values to set your fields (6 parameters). accel() method: a void method that takes a double variable as a parameter and increases the speed of the car by that amount. brake() method: a void method that sets the speed to zero.  To test your class, you will need to instantiate at least two different Car objects in the main method in the CarDemo class.  Each of your objects should use a different constructor. For the object that uses the default constructor, you will need to invoke the mutator methods to assign values to your fields. Invoke the displayFeatures() method for both objects and display the variables.  Demonstrate the use of the accessor method getColor() by accessing the color of each car and printing it to the console.  Use the method accel to increase the speed of the first car by 65 mph.  Use…
Create one more method in the Starship class:   encounter(self, enemy_ship) This method takes in self, along with another Starship object. The method should simulate a battle between the two ships.   How the method is implemented is almost entirely up to you.  You could take in user input for each crew member, or have them each act randomly from the available options, or specify exactly what a given crew member of each type should do.  The only requirements are as follows:   Each crew member on each ship should get at least one “turn” before the battle is complete. If the crew member is Injured on their turn, they should do nothing. You may assume that each ship will have at least one crew member uninjured when the encounter begins. You shouldn’t make any assumptions about how many crew members there will be on a given ship, where they will start, or about which subclasses will be present - it’s possible that you’ll have test cases including a ship with no captain, or no doctor.…

Chapter 4 Solutions

Absolute Java (6th Edition)

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education