Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 5.2, Problem 13STQ
In Listing 5.12, we set the data for the object speciesOfTheMonth as follows:
speciesOfTheMonth.setSpecies(“Klingon ox”, 10, 15);
Could we have used the following code instead?
speciesOfTheMonth.name = “Klingon ox”;
speciesOfTheMonth.population = 10;
speciesOfTheMonth.growthRate = 15;
If we could have used this alternative code, why didn't we? If we could not have used this alternative code, explain why we could not use it.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a program that defines a class with a data member to holds a “serial number” for each object created from the class. That is, the first object created will be numbered 1, the second 2, and so on. To do this, you’ll need another data member that records a count of how many objects have been created so far. (This member should apply to the class as a whole; not to individual objects. What keyword specifies this?) Then, as each object is created, its constructor can examine this count member variable to determine the appropriate serial number for the new object. Add a member function that permits an object to report its own serial number. Then write a main() program that creates three objects and queries each about its serial number. They should respond I am object number 2, and so on.
This question related to Object oriented programming in c++
Write a program that uses a structure to store the information about the Items in a retail store. It has Items with name, manufacturer (Final) and price.
1. Provide default & Parameterized constructors.
2. Provide getters & setters for data members.
3. Provide A toString() method to print values.
We can add several items to Store. Now create another class store which has name, city and array of Items.
1. Provide default & Parameterized constructors.
2. Provide getters & setters for data members.
3. Provide necessary validation checks ( null pointer exception, index out of bounds,etc). where possible.
4. Provide a method AddItem (Item i) which is used to add items into the store, but number of items should be less than the size of array (check for exception).
5. A print function which shows all items in the store.
6. Create Test Application and test the functionality of above classes.
Use exception also
Programming language : Java
10.
Please do in java code
DJ classDesign, implement and test a DJ class. A DJ object has a name - djName and an isHired attribute (boolean). Also, a DJ object has 3 musicTypes. These are references to the Music class, where the musicType is declared. In Stage 2 you will be required to declare these 3 instance variables as 1 array.A DJ object can return the value of each of its attributes, and change the value of each of its attributes. It can also display itself in the form:Kongapa, Play List: Disco, Rap, Heavy Metal is hiredImpressions, Play List: House, Hip Hop, Jazz is available
Chapter 5 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 5.1 - Consider the program in Listing 5.4 . Suppose you...Ch. 5.1 - Prob. 2STQCh. 5.1 - Prob. 3STQCh. 5.1 - Suppose every species in the world has a peculiar...Ch. 5.1 - Revise the definition of the method writeOutput in...Ch. 5.1 - Revise the definition of the method readInput in...Ch. 5.1 - Revise the definition of the method...Ch. 5.1 - What is the meaning of (int) that appears in the...Ch. 5.1 - Prob. 9STQCh. 5.1 - Define a method called getDensity that could be...
Ch. 5.1 - Define a method called changePopulation that could...Ch. 5.1 - Define a method called changePopulation that could...Ch. 5.2 - In Listing 5.12, we set the data for the object...Ch. 5.2 - Give preconditions and postconditions for the...Ch. 5.2 - What is an accessor method? What is a mutator...Ch. 5.2 - Give the complete definition of a class called...Ch. 5.2 - Prob. 17STQCh. 5.2 - In the definition of the method in Listing 5.15,...Ch. 5.2 - What is a well-encapsulated class definition?Ch. 5.2 - When should an instance variable in a class...Ch. 5.2 - Prob. 21STQCh. 5.2 - In a class definition, is anything private ever...Ch. 5.2 - In a class definition, is the body of any method...Ch. 5.3 - What is a reference type? Are class types...Ch. 5.3 - When comparing two quantities of a class type to...Ch. 5.3 - Prob. 26STQCh. 5.3 - Write a method definition for a method called...Ch. 5.3 - Given the class Species as defined in Listing...Ch. 5.3 - After correcting the program in the previous...Ch. 5.3 - What is the biggest difference between a parameter...Ch. 5.3 - Prob. 31STQCh. 5.3 - Write an equals method for the class Person...Ch. 5.4 - Rewrite the method drawFaceSansMouth in Listing...Ch. 5 - Design a class to represent a credit card. Think...Ch. 5 - Repeat Exercise 1 for a credit card account...Ch. 5 - Repeat Exercise 1 for a coin instead of a credit...Ch. 5 - Repeat Exercise 1 for a collection of coins...Ch. 5 - Consider a Java class that you could use to get an...Ch. 5 - Consider a class that keeps track of the sales of...Ch. 5 - Consider a class MotorBoat that represents...Ch. 5 - Prob. 8ECh. 5 - Prob. 9ECh. 5 - Prob. 10ECh. 5 - Write a program to answer questions like the...Ch. 5 - Define a class called Counter. An object of this...Ch. 5 - Prob. 3PCh. 5 - Define a Trivia class that contains information...Ch. 5 - Define a Beer class that contains the following...Ch. 5 - Write a grading program for an instructor whose...Ch. 5 - Add methods to the Person class from Self-Test...Ch. 5 - Create a class that represents a grade...Ch. 5 - Write a program that uses the Purchase class in...Ch. 5 - Write a program to answer questions like the...Ch. 5 - Consider a class that could be used to play a game...Ch. 5 - Consider a class BasketballGame that represents...Ch. 5 - Consider a class ConcertPromoter that records the...Ch. 5 - Prob. 9PPCh. 5 - Consider a class Movie that contains information...Ch. 5 - Repeat Programming Project 18 from Chapter 4, but...Ch. 5 - Prob. 12PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Where do you declare class-level variables?
Starting Out With Visual Basic (7th Edition)
Define each of the following terms: determinant functional dependency transitive dependency recursive foreign k...
Modern Database Management
Consider the adage Never ask a question for which you do not want the answer. a. Is following that adage ethica...
Experiencing MIS
In the following If Then statement, assume that blnIsInvalid is a Boolean variable. Exactly what condition is ...
Starting Out With Visual Basic (8th Edition)
Consider the adage Never ask a question for which you do not want the answer. a. Is following that adage ethica...
Using MIS (10th Edition)
The ____________ is always transparent.
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Implement closer_city, a function that takes a latitude, longitude, and two cities, and returns the name of the city that is relatively closer to the provided latitude and longitude. You may only use selectors and constructors (introduced above) for this question. You may also use the distance function defined above. Remember, the point of data abstraction, as we've said, is that we do not need to know how an abstract data type is implemented, but rather just how we can interact with and use the data type. def closer_city (lat, lon, cityl, city2): """ Returns the name of either cityl or city2, whichever is closest to coordinate (lat, lon). |||||| >>> berkeley = make_city('Berkeley', 37.87, 112.26) >>> stanford = make_city('Staníprd', 34.05, 118.25) >>> closer_city (38.33, 121.44, berkeley, stanford) 'Stanford' >>> bucharest = make_city('Bucharest', 44.43, 26.10) >>> vienna = make_city('Vienna', 48.20, 16.37) >>> closer_city (41.29, 174.78, bucharest, vienna) 'Bucharest' "*** YOUR CODE…arrow_forwardWrite in python and please include docstring. Write a class named Employee that has private data members for an employee's name, ID_number, salary, and email_address. It should have an init method that takes four values and uses them to initialize the data members. It should have get methods named get_name, get_ID_number, get_salary, and get_email_address. Write a separate function (not part of the Employee class) named make_employee_dict that takes as parameters a list of names, a list of ID numbers, a list of salaries and a list of email addresses (which are all the same length). The function should take the first value of each list and use them to create an Employee object. It should do the same with the second value of each list, etc. to the end of the lists. As it creates these objects, it should add them to a dictionary, where the key is the ID number and the value for that key is the whole Employee object. The function should return the resulting dictionary. For example, it…arrow_forwardI need help writing a program for this on pythonarrow_forward
- Write a java program that uses a structure to store the information about the Items in a retail store. It has Items with name, manufacturer (Final) and price. Provide default & Parameterized constructors. Provide getters & setters for data members. Provide A toString() method to print values. We can add several items to Store. Now create another class store which has name, city and array of Items. Provide default & Parameterized constructors. Provide getters & setters for data members. Provide necessary validation checks ( null pointer exception, index out of bounds,etc). where possible. Provide a method AddItem (Item i) which is used to add items into the store, but number of items should be less than the size of array (check for exception). A print function which shows all items in the store. Create Test Application and test the functionality of above classes.arrow_forwardYour task is to create a class name polygon that contains 2 data members i.e. length of type float and width (a pointer of type float). Create a single object named “one” in the main and assign values to the data member of the polygon object. Then create another object named “two” that is a copy of the “one”. Create a shallow copy constructor that copies only the pointer data member of the class polygon and then demonstrate that both objects share a common memory i.e. modifying one object in fact modifies the other.Create a display function that will show the values of the polygon object.arrow_forwardadvanced java For this assignment you will write a program to represent geometric shapes and some operations that can be performed on them. The idea here is that shapes in higher dimensions inherit data from lower dimensional shapes. For example a cube is a three dimensional square. A sphere is a three dimensional circle and a glome is a four dimensional circle. A cylinder is another kind of three dimensional circle. The circle, sphere, cylinder, and glome all share the attribute radius. The square and cube share the attribute side length. There are various ways to use inheritance to relate these shapes but please follow the inheritance described in the table below. All shapes inherit getName() from the superclass Shape. Specification: The program should have the following classes: Shape, Circle, Square, Cube, Sphere, Cylinder, and Glome and two interfaces Area and Volume (Area.java and Volume.java are given below). The volume of a glome is 0.5(π2)r4 where r is the radius. Your classes…arrow_forward
- The code given below represents a saveTransaction() method which is used to save data to a database from the Java program. Given the classes in the image as well as an image of the screen which will call the function, modify the given code so that it loops through the items again, this time as it loops through you are to insert the data into the salesdetails table, note that the SalesNumber from the AUTO-INCREMENT field from above is to be inserted here with each record being placed into the salesdetails table. Finally, as you loop through the items the product table must be update because as products are sold the onhand field in the products table must be updated. When multiple tables are to be updated with related data, you should wrap it into a DMBS transaction. The schema for the database is also depicted. public class PosDAO { private Connection connection; public PosDAO(Connection connection) { this.connection = connection; } public void…arrow_forwardCreate a class Student with following data members- name, roll no and marks as private data member. Create array of objects for three students, compare their marks using operator overloading, and display the records of the student who is getting highest score.arrow_forwardIn this program, you are provided with phenotype counts of F1 and F2 offspring at two research institutes. The data are generated from an initial parental cross of elegant cranes, whose genetics are identical to fruit flies, with the exception that they look like crane birds. The cranes for each institute come from the same original source. For each institute, in the parental generation (P0), one parent displays the wild-type (WT) phenotype and one the disease phenotype. The WT parent always has a homozygous genotype, and whether the disease parent has a homozygous genotype depends on which scenario describes data in the F1 generation. The possibilities for F1 individuals are: (a) All individuals are disease; (b) All individuals are wild-type; (c) There are disease and wild-type individuals. When both disease and WT individuals (item (c)) are available in the F1 generation then you should use the F1 cross, (disease) X WT. For each institute, there are three possible modes of…arrow_forward
- Part 2: Sorting the WorkOrders via dates Another error that will still be showing is that there is not Comparable/compareTo() method setup on the WorkOrder class file. That is something you need to fix and code. Implement the use of the Comparable interface and add the compareTo() method to the WorkOrder class. The compareTo() method will take a little work here. We are going to compare via the date of the work order. The dates of the WorkOrder are saved in a MM-DD-YYYY format. There is a dash '-' in between each part of the date. You will need to split both the current object's date and the date sent through the compareTo() parameters. You will have three things to compare against. You first need to check the year. If the years are the same value then you need to go another step to check the months, otherwise you compare them with less than or greater than and return the corresponding value. If you have to check the months it would be the same for years. If the months are the same you…arrow_forwardUsing the scenario of Object oriented programming Q1 Write a program that defines a class with a data member to holds a “serial number” for each object created from the class. That is, the first object created will be numbered 1, the second 2, and so on. To do this, you’ll need another data member that records a count of how many objects have been created so far. (This member should apply to the class as a whole; not to individual objects. What keyword specifies this?) Then, as each object is created, its constructor can examine this count member variable to determine the appropriate serial number for the new object. Add a member function that permits an object to report its own serial number. Then write a main() program that creates three objects and queries each about its serial number. They should respond I am object number 2, and so on.arrow_forwardWritten in Python with docstring please if applicable Thank youarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License