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 6, Problem 2AW
Look at the following partial class definition, and then respond to the questions that follow it:
public class Book
{
private String title;
private String author;
private String publisher;
private int copiesSold;
}
- a. Write a constructor for this class. The constructor should accept an argument for each of the fields.
- b. Write accessor and mutator methods for each field.
- c. Draw a UML diagram for the class, including the methods you have written.
Expert Solution & Answer
Learn your wayIncludes step-by-step video
schedule06:16
Students have asked these similar questions
Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a double), and one for the width (a double). The class should have:
a constructor that accepts arguments for the two fields
a method that returns the tract’s area(i.e. length * width)
an equals method that accepts a LandTract object as an argument. If the argument object
holds the same data (i.e. length and width) as the calling object, this method should return
true. Otherwise, it should return false.
a toString method (that returns a String representation of the tract’s length, width, and
area).
Demonstrate the class in a program by creating an array of three LandTract objects initialized with user input. Then, print the info of the LandTract objects stored in the array by invoking the toString method (implicitly or explicity). Also, use the equals method to compare at least two LandTract objects and print wether they are of equal size or not.
Sample Output:…
Practice with writing a program that contains three classes:
Ship
CruiseShip
CargoShip Classes
Design a Ship class with 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 that accepts two arguments for the two fields, and appropriate accessors and mutators
A toString method that returns a string with the ship’s name and the year it was built
Design a CruiseShip class that extends the Ship class. The CruiseShip class should have the following members:
A field for the maximum number of passengers (an int)
A constructor that accepts three arguments for the three fields and appropriate accessors and mutators
A toString method that overrides the toString method in the base class. The CruiseShip class’s toString method should return a string with only the ship’s name and the maximum number of passengers.
Design a CargoShip class that extends the Ship class. The CargoShip class should have the…
46. It is an advanced concept in Object Oriented Programming that is achieved by separating the use of a method from its implementation.
Abstraction
Polymorphism
None of the Choices
Classes
Give an explanation for the answer. Thank you
Chapter 6 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Ch. 6.1 - What does an object use its fields for?Ch. 6.1 - Prob. 6.2CPCh. 6.1 - How is a class like a blueprint?Ch. 6.1 - You have programs that create Scanner, Random, and...Ch. 6.1 - Prob. 6.5CPCh. 6.1 - What values do reference variables hold?Ch. 6.1 - Prob. 6.7CPCh. 6.2 - You hear someone make the following comment: A...Ch. 6.2 - Prob. 6.9CPCh. 6.2 - When a variable is said to reference an object,...
Ch. 6.2 - Prob. 6.11CPCh. 6.2 - Prob. 6.12CPCh. 6.2 - Prob. 6.13CPCh. 6.2 - Prob. 6.14CPCh. 6.2 - Prob. 6.15CPCh. 6.2 - What is a stale data item?Ch. 6.3 - Assume that r1 and r2 are variables that reference...Ch. 6.4 - How is a constructor named?Ch. 6.4 - What is a constructors return type?Ch. 6.4 - Prob. 6.20CPCh. 6.7 - Prob. 6.21CPCh. 6.7 - What is a methods signature?Ch. 6.7 - Look at the following class: public class...Ch. 6.7 - How many default constructors may a class have?Ch. 6.9 - Prob. 6.25CPCh. 6.9 - When designing an object-oriented application, who...Ch. 6.9 - How do you identify the potential classes in a...Ch. 6.9 - What are a classs responsibilities?Ch. 6.9 - What two questions should you ask to determine a...Ch. 6.9 - Will all of a classs actions always be directly...Ch. 6 - This is a collection of programming statements...Ch. 6 - A class is analogous to a(n) _______. a. house b....Ch. 6 - An object is a(n) ________. a. blueprint b....Ch. 6 - This is a class member that holds data. a. method...Ch. 6 - This key word causes an object to be created in...Ch. 6 - This is a method that gets a value from a classs...Ch. 6 - This is a method that stores a value in a field or...Ch. 6 - When the value of an item is dependent on other...Ch. 6 - This is a method that is automatically called when...Ch. 6 - When a local variable has the same name as a...Ch. 6 - This is automatically provided for a class if you...Ch. 6 - Prob. 12MCCh. 6 - Prob. 13MCCh. 6 - A classs responsibilities are __________. a. the...Ch. 6 - True or False: The new operator creates an...Ch. 6 - True or False: Each instance of a class has its...Ch. 6 - True or False: When you write a constructor for a...Ch. 6 - True or False: A class may not have more than one...Ch. 6 - True or False: To find the classes needed for an...Ch. 6 - Find the error in the following class: public...Ch. 6 - Prob. 2FTECh. 6 - The following statement attempts to create a...Ch. 6 - Find the error in the following class: public...Ch. 6 - Find the error in the following class: public...Ch. 6 - Design a class named Pet, which should have the...Ch. 6 - Look at the following partial class definition,...Ch. 6 - Consider the following class declaration: public...Ch. 6 - Look at the following description of a problem...Ch. 6 - The bank offers the following types of accounts to...Ch. 6 - Assume that you are writing an application that...Ch. 6 - What is the difference between a class and an...Ch. 6 - A contractor uses a blueprint to build a set of...Ch. 6 - What is an accessor method? What is a mutator...Ch. 6 - is it a good idea to make fields private? Why or...Ch. 6 - If a class has a private field, what has access to...Ch. 6 - Prob. 6SACh. 6 - Assume a program named MailList.java is stored in...Ch. 6 - Why are constructors useful for performing...Ch. 6 - Under what circumstances does Java automatically...Ch. 6 - What do you call a constructor that accepts no...Ch. 6 - Prob. 11SACh. 6 - How does method overloading improve the usefulness...Ch. 6 - Employee Class Write a class named Employee that...Ch. 6 - Car Class Write a class named Car that has the...Ch. 6 - Personal Information Class Design a class that...Ch. 6 - Retail Item Class Write a class named RetailItem...Ch. 6 - Payroll Class Design a Payroll class that has...Ch. 6 - TestScores Class Design a TestScores class that...Ch. 6 - Circle Class Write a Circle class that has the...Ch. 6 - Temperature Class Write a Temperature class that...Ch. 6 - Days in a Month Write a class named MonthDays, The...Ch. 6 - A Game of Twenty-One For this assignment, you will...Ch. 6 - Freezing and Boiling Points The following table...Ch. 6 - SavingsAccount Class Design a SavingsAccount class...Ch. 6 - Deposit and Withdrawal Files Use Notepad or...Ch. 6 - Patient Charges Write a class named Patient that...Ch. 6 - Dice Game Write a program that uses the Die class...Ch. 6 - Roulette Wheel Colors On a roulette wheel, the...Ch. 6 - Coin Toss Simulator Write a class named Coin. The...Ch. 6 - Tossing Coins for a Dollar For this assignment you...Ch. 6 - Fishing Game Simulation For this assignment, you...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
For each of the following activities, give a PEAS description of the task environment and characterize it in te...
Artificial Intelligence: A Modern Approach
This problem concerns the m. o module from Figure 7.5 and the following version of the swap, c function that co...
Computer Systems: A Programmer's Perspective (3rd Edition)
Use the following tables for your answers to questions 3.7 through 3.51 : PET_OWNER (OwnerID, OwnerLasst Name, ...
Database Concepts (7th Edition)
Compare and contrast the if single-selection statement and the while iteration statement. How are these two sta...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
Give the definitions of the constructors for the class TitledEmployee that you gave as the answer to Self-Test ...
Problem Solving with C++ (10th 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
- Analysis: Q1: There are common attributes and methods between kids and trainers. What is the best choice for designing and writing the codes of these two classes? Explain your answer. Q2: Draw a simple class diagram showing only relationships between the classes. Implementation: After analysing the given requirements, implement the required application: with Object Oriented Programming style following the rules of good programming style (e.g. adding comments, etc.) using only the material covered in M251 (and its prerequisites) Hints: For each class, it is required to implement constructors, setters, getters, toString() method, and any other necessary method If the user tries to do an operation that could violate the state of objects, the operation should be ignored and the application should display an error message (e.g. adding a kid to the same group twice, etc.) Checking equality of any 2 objects should be done via the equals() method There is a class that will do the main job of…arrow_forwardStatic class members are exactly what they sound like. When and how can they be used?arrow_forwardBuild a UML Diagram for Programming Exercise 2arrow_forward
- Library Information System Design and Testing Library Item Class Design and TestingDesign a class that holds the Library Item Information, with item name, author, publisher. Write appropriate accessor and mutator methods. Also, write a tester program(Console and GUI Program) that creates three instances/objects of the Library Items class. Extending Library Item Class Library and Book Classes: Extend the Library Item class in (1) with a Book class with data attributes for a book’s title, author, publisher and an additional attributes as number of pages, and a Boolean data attribute indicating whether there is both hard copy as well as eBook version of the book. Demonstrate Book Class in a Tester Program (Console and GUI Program) with an object of Book class.arrow_forwardDesign a class named Computer that holds the make, model , and amount of memory of a computer. Include methods to set values for each data field, and include a method that displays all the values for each field. Create the UML diagram ( class diagram) and write the pseudocode that define the classarrow_forwardis a construct that defines objects of the same type. A class An object A method A data fieldarrow_forward
- Analysis: Q1: There are common attributes and methods between passengers and drivers. What is the best choice for designing and writing the codes of these two classes? Explain your answer. Q2: Draw a simple class diagram showing only relationships between the classes. Implementation: After analysing the given requirements, implement the required application: with Object Oriented Programming style following the rules of good programming style (e.g. adding comments, etc.) • using only the material covered in M251 (and its prerequisites) Java language*arrow_forwardStatic variables can... ...can be accessed even without creating an object of that class. ...only be accessed by static methods. ...not be accessed using class prefix. ...not be inherited.arrow_forwardTrue or False An interface can be used to define a set of methods that a class must implement.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- New Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
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