Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
7th Edition
ISBN: 9780134802213
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 8, Problem 4MC
Making an instance of one class a field in another class is called_____.
- a. nesting
- b. class fielding
- c. aggregation
- d. concatenation
Expert Solution & Answer
Learn your wayIncludes step-by-step video
schedule03:16
Students have asked these similar questions
5. class definition for GameEnemy
Next, we want to start making enemies for our upcoming video game, so we will define a class called GameEnemy.
Every GameEnemy will have a name, an x location, a y location, and a number of hit points (which must be a non-
negative integer ). The_init__ method for GameEnemy will take all of these parameters (in that order) and store them
on the object. GameEnemy also needs a method called healthbar, which will allow us to show that enemy's health bar in
the game. It returns the enemy's name followed by a number of asterisks to show how many hit points it has left. The
exact format is shown below.
Sample runs should look like:
>>> enemy = GameEnemy ("TODD", 100, 200, 5)
>>> enemy.healthbar()
TODD: ******
>>> enemy-%
ence
100
>>> enemy-y
200
If vou havo qu octiona
Assignment:
1- Create a class called Book with the following attributes:
1. title: The title of the book.
2. author: The author of the book.
3. pages: The number of pages in the book.
Use a constructor (__init___) to initialize these attributes when creating an object
from the class. Add a method inside the class calle description() which returns a
description of the book
Lec 3: Classes and Objects
Object-oriented programming
2- Create a class called Phone with the following attributes:
1. brand: The brand of the phone.
2. price: The price of the phone.
Use a constructor (__init__) to initialize these attributes when creating an object
from the class. Add a method inside the class called show_info(), which prints the
phone's details
Design a Ship class that has the following members:• A field for the name of the ship (a string).• A field for the year that the ship was built (a string).• A constructor and appropriate accessors and mutators.• A toString method that displays the ship's name and the year it was built.Disign a CruiseShip class that extends the Ship class. The CruiseShip class should have thefollowing members:• A field for the maximum number of passengers (an int).• A constructor and appropriate accessors and mutators.• A toString method that overrides the toString method in the base class. The CruiseShipclass's toString method should display only the ship's name and the maximum number ofpassengers.Design a CargoShip class that extends the Ship class. The CargoShip class should have thefollowing members:• A field for the cargo capacity in tonnage (an int).• A constructor and appropriate accessors and mutators.• A toString method that overrides the toString method in the base class. The CargoShipclass's…
Chapter 8 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Ch. 8.1 - What is the difference between an instance field...Ch. 8.1 - Prob. 8.2CPCh. 8.1 - Describe the limitation of static methods.Ch. 8.8 - Prob. 8.4CPCh. 8.9 - Look at the following statement, which declares an...Ch. 8.9 - Assume that the following enumerated data type has...Ch. 8.9 - Prob. 8.7CPCh. 8 - This type of method cannot access any non-static...Ch. 8 - Prob. 2MCCh. 8 - If you write this method for a class, Java will...
Ch. 8 - Making an instance of one class a field in another...Ch. 8 - This is the name of a reference variable that is...Ch. 8 - This enum method returns the position of an enum...Ch. 8 - Assuming the following declaration exists: enum...Ch. 8 - You cannot use the fully qualified name of an enum...Ch. 8 - The Java Virtual Machine periodically performs...Ch. 8 - If a class has this method, it is called...Ch. 8 - CRC stands for a. Class, Return value, Composition...Ch. 8 - True or False: A static member method may refer to...Ch. 8 - True or False: All static member variables are...Ch. 8 - Prob. 14TFCh. 8 - Prob. 15TFCh. 8 - Prob. 16TFCh. 8 - True or False: Enumerated data types are actually...Ch. 8 - True or False: enum constants have a toString...Ch. 8 - public class MyClass { private int x; private...Ch. 8 - Assume the following declaration exists : enum...Ch. 8 - Consider the following class declaration: public...Ch. 8 - Consider the following class declaration: public...Ch. 8 - A pet store sells dogs, cats, birds, and hamsters....Ch. 8 - Prob. 1SACh. 8 - Prob. 2SACh. 8 - Prob. 3SACh. 8 - Even if you do not write an equals method for a...Ch. 8 - A has a relationship can exist between classes....Ch. 8 - Prob. 6SACh. 8 - Is it advisable or not advisable to write a method...Ch. 8 - Prob. 8SACh. 8 - Look at the following declaration: enum Color {...Ch. 8 - Assuming the following enum declaration exists:...Ch. 8 - Under what circumstances does an object become a...Ch. 8 - Area Class Write a class that has three overloaded...Ch. 8 - BankAccount Class Copy Constructor Add a copy...Ch. 8 - Carpet Calculator The Westfield Carpet Company has...Ch. 8 - LandTract Class Make a LandTract class that has...Ch. 8 - Month Class Write a class named Month. The class...Ch. 8 - CashRegister Class Write a CashRegister class that...Ch. 8 - Sales Receipt File Modify the program you wrote in...Ch. 8 - Parking Ticket Simulator For this assignment you...Ch. 8 - Geometry Calculator Design a Geometry class with...Ch. 8 - Car Instrument Simulator For this assignment, you...Ch. 8 - First to One Game This game is meant for two or...Ch. 8 - Heads or TaiLs Game This game is meant for two or...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Identify the zero-force members in the truss. Prob. F6-5
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
Theprogramming language was developed by Bjarne Stroustrup in the early 1980s at Bell Laboratories.
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Write a default constructor and a second constructor for the class RatingScore, as described in Exercise 9 of t...
Java: An Introduction to Problem Solving and Programming (8th Edition)
A file that contains a Flash animation uses the __________ file extension. a. .class b. .swf c. .mp3 d. .flash
Web Development and Design Foundations with HTML5 (8th Edition)
Which of the following loops would you use to read all of the items from the file associated with myFile? a. Wh...
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
In Exercises 57 through 64, identify any errors. DimnumAsDoublenum=InputBoxPickanumberfrom1to10.txtOutput.Text=...
Introduction To Programming Using Visual Basic (11th Edition)
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
- This function is used to check whether an object is an instance of a specific class or a subclass of that class. a. isinstance b. isobject c. isreference d. _ _str_ _arrow_forwardWrite a class named Car that has the following member variables: yearModel: An int that holds the car’s year model. name: A string that holds the name of the car. company: A string that holds the company of the car. speed: An int that holds the car’s current speed. In addition, the class should have the following member functions. Mutator: Appropriate accessor functions to set the values of object’s yearModel, name, company, and speed member variables. Accessor: Appropriate accessor functions to get the values stored in an object’s yearModel, company, and speed member variables. Accelerate: The accelerate function should add 5 to the speed member variable each time it is called. Brake: The brake function should subtract 5 from the speed member variable each time it is called. Demonstrate the class in a program that creates a Car object, call the setter functions to set the values and then call the accelerate function five times. After each call to the accelerate function, get…arrow_forward2. Car Class Write a class named car that has the following fields: ▪ yearModel. The year Model field is an int that holds the car's year model. ▪ make. The make field is a String object that holds the make of the car, such as "Ford", "Chevrolet", "Honda", etc. ▪ speed. The speed field is an int that holds the car's current speed. In addition, the class should have the following methods. ■ Constructor. The constructor should accept the car's year model and make as arguments. These values should be assigned to the object's year Model and make fields. The constructor should also assign 0 to the speed field.arrow_forward
- JAVAarrow_forwardTrue or false: Just as a class can have multiple constructors, it can also have multiple destructors.arrow_forwardclass Widget: """A class representing a simple Widget === Instance Attributes (the attributes of this class and their types) === name: the name of this Widget (str) cost: the cost of this Widget (int); cost >= 0 === Sample Usage (to help you understand how this class would be used) === >>> my_widget = Widget('Puzzle', 15) >>> my_widget.name 'Puzzle' >>> my_widget.cost 15 >>> my_widget.is_cheap() False >>> your_widget = Widget("Rubik's Cube", 6) >>> your_widget.name "Rubik's Cube" >>> your_widget.cost 6 >>> your_widget.is_cheap() True """ # Add your methods here if __name__ == '__main__': import doctest # Uncomment the line below if you prefer to test your examples with doctest # doctest.testmod()arrow_forward
- Design a class named Pet, which should have the following fields: • name. The name field holds the name of a pet. • animal. The animal field holds the type of animal that a pet is. Example values are “Dog”, “Cat”, and “Bird”. • age. The age field holds the pet’s age. The Pet class should also have the following methods: • setName. The setName method stores a value in the name field. • setAnimal. The setAnimal method stores a value in the animal field. • setAge. The setAge method stores a value in the age field. • getName. The getName method returns the value of the name field. • getAnimal. The getAnimal method returns the value of the animal field. • getAge. The getAge method returns the value of the age field. Write the Java code for the Pet class and demonstrate it.arrow_forwardRectangle Object Monitoring Create a Rectangle class that can compute the total area of all the created rectangle objects using static fields (variables). Remember that a Rectangle has two attributes: Length and Width. Implement the class by creating a computer program that will ask the user about three rectangle dimensions. The program should be able to display the total area of the three rectangle objects. For this exercise, you are required to apply all OOP concepts that you learned in class. Sample output: Enter Length R1: 1 Enter Width R1: 1 Enter Length R2: 2 Enter Width R2: 2 Enter Length R3: 3 Enter Width R3: 3 The total area of the rectangles is 14.00 Note: All characters in boldface are user inputs.arrow_forward5.Fruit class:First create a Fruit class that contains code common to all of the fruits.1. Fruit class has two data fields called color and seed.2. A private data field called season. 3. Three constants named SUMMER, WINTER, and AUTUMN to denote the season.4. The accessor and mutator methods for all three data fields.Apple class:Apple class is a subclass of Fruit. 1. Write a class called Apple which extends the Fruit class.2. Apples are produced in Winter season.3. Declare a data field called varieties. There are three varieties:a. Ciderb. Cookingc. Dessert 4. A method named toString () that returns a string description for the Apple. Mango class:Mango class is a subclass of Fruit. 1. Write a class called Mango which extends the Fruit class.2. Mangoes are produced in Summer season.3. Declare a data field called propagation. There are two ways:a. graftingb. budding 4. A method named toString () that returns a string description for the Mango. UML Diagram:Draw a UML diagram including all…arrow_forward
- Assignment - LocationsFor this assignment, we will be creating our location class and then a few locations to subclass from it. Most of these classes will be rather short so you can put them all in locations.py if you would likeCreate the Location classCreate the Town classCreate the Palace and Lumbermill classes Location ClassThe Location class establishes the basic properties of a location: manager - holds the character that manages the locationforeColor - holds the fore color of the locationbackColor - holds the back color of the locationEnter() - default method for entering a location. By default, the manager should greet you and all text displayed should use the foreColor and backColor of the location.Exit() - default method for leaving a location. By default, the manager should say bye to you and all text displayed should use the foreColor and backColor of the location.Upkeep() - default method that is called when time is advanced Town ClassThe Town class will inherit from the…arrow_forwardAssignment:The BankAccount class models an account of a customer. A BankAccount has the followinginstance variables: A unique account id sequentially assigned when the Bank Account is created. A balance which represents the amount of money in the account A date created which is the date on which the account is created.The following methods are defined in the BankAccount class: Withdraw – subtract money from the balance Deposit – add money to the balance Inquiry on:o Balanceo Account ido Date createdarrow_forwardLab 2 – Designing a class This lab requires you to think about the steps that take place in a program by writing pseudocode. Read the following program prior to completing the lab. Design a class named Computer that holds the make, model, and amount of memory of a computer. Include methods to set the values for each data field, and include a method that displays all the values for each field. For the programming problem, create the pseudocode that defines the class and enter it below. Enter pseudocode herearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY