Starting Out with Programming Logic and Design (4th Edition)
Starting Out with Programming Logic and Design (4th Edition)
4th Edition
ISBN: 9780133985078
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 14, Problem 2PE

Car Class

Design a class named Car that has the following fields:

  • yearModel: The yearModel field is an Integer that holds the car’s year model.
  • make: The make field references a String that holds the make of the car.
  • speed: The speed field is an Integer that holds the car's current speed.

In addition, the class should have the following constructor and other methods:

  • Constructor: The constructor should accept the car’s year model and make as arguments. These values should be assigned to the object’s yearMode1 and make fields. The constructor should also assign 0 to the speed field.
  • Accessors: Design appropriate accessor methods to get the values stored in an object’s yearModel, make, and speed fields.
  • accelerate: The accelerate method should add 5 to the speed field each time it is called.
  • brake: The brake method should subtract 5 from the speed field each time it is called.

Next, design a program that creates a Car object, and then calls the accelerate method five times. After each call to the accelerate method, get the current speed of the car and display it. Then call the brake method five times. After each call to the brake method, get the current speed of the car and display it.

Blurred answer
Students have asked these similar questions
Car ClassWrite a class named Car that has the following fields:•  yearModel. The yearModel field is an int that holds the car’s year model.•  make. The make field references a String object that holds the make of the car.•  speed. The speed field is an int that holds the car’s current speed. In addition, the class should have the following constructor and other methods.•  Constructor. The constructor should accept the car’s year model and make as arguments. These values should be assigned to the object’s yearModel and make fields. The constructor should also assign 0 to the speed field.•  Accessors. Appropriate accessor methods should get the values stored in an object’s yearModel, make, and speed fields.•  accelerate. The accelerate method should add 5 to the speed field each time it is called.•  brake. The brake method should subtract 5 from the speed field each time it is called.Demonstrate the class in a program that creates a Car object, and then calls the accelerate method five…
2. 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.
Employee and ProductionWorker Classes Create an Employee class that has properties for the following data: Employee name Employee number Next, create a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have properties to hold the following data: Shift number (an integer, such as 1, 2, or 3) Hourly pay rate The workday is divided into two shifts: day and night. The Shift property will hold an integer value representing the shift that the employee works. The day shift is shift 1 and the night shift is shift 2. Create an application that creates an object of the ProductionWorker class and lets the user enter data for each of the object’s properties. Retrieve the object’s properties and display their values.

Chapter 14 Solutions

Starting Out with Programming Logic and Design (4th Edition)

Ch. 14.2 - Prob. 14.11CPCh. 14.2 - What is a constructor? When does a constructor...Ch. 14.2 - What is a default constructor?Ch. 14.3 - Prob. 14.14CPCh. 14.3 - Suppose a class has a field named description. The...Ch. 14.3 - Prob. 14.16CPCh. 14.4 - Prob. 14.17CPCh. 14.4 - What technique was described in this section for...Ch. 14.4 - What are classes responsibilities?Ch. 14.4 - Prob. 14.20CPCh. 14.5 - In this section, we discussed superclasses and...Ch. 14.5 - Prob. 14.22CPCh. 14.5 - What does a subclass inherit from its superclass?Ch. 14.5 - Look at the following pseudocode; which is the...Ch. 14.6 - Look at the following pseudocode class...Ch. 14 - Prob. 1MCCh. 14 - Prob. 2MCCh. 14 - A(n) ____ is a member of a class that holds data....Ch. 14 - The _________ specifies how a classs field or...Ch. 14 - A classs fields are commonly declared with the...Ch. 14 - Prob. 6MCCh. 14 - In many programming languages, the _____ key word...Ch. 14 - A(n) ____ method gets a value from a class's field...Ch. 14 - A(n) ____ method stores a value in a field or...Ch. 14 - A(n) ____ method is automatically called when an...Ch. 14 - A set of standard diagrams for graphically...Ch. 14 - When the value of an item is dependent on other...Ch. 14 - A classs responsibilities are _____. a. objects...Ch. 14 - In an inheritance relationship, the _____ is the...Ch. 14 - In an inheritance relationship, the _____ is the...Ch. 14 - The ___________ characteristic of object-oriented...Ch. 14 - The practice of procedural programming is centered...Ch. 14 - Object reusability has been a factor in the...Ch. 14 - It is a common practice in object-oriented...Ch. 14 - One way to find the classes needed for an...Ch. 14 - The superclass inherits fields and methods from...Ch. 14 - Polymorphism allows a class variable of the...Ch. 14 - Prob. 1SACh. 14 - Prob. 2SACh. 14 - What is the difference between a class and an...Ch. 14 - In many programming languages, what does the New...Ch. 14 - The following pseudocode statement calls an...Ch. 14 - Prob. 6SACh. 14 - What does a subclass inherit from its superclass?Ch. 14 - Look at the following pseudocode, which is the...Ch. 14 - Prob. 1AWCh. 14 - Look at this partial class definition, and then...Ch. 14 - Look at the following description of a problem...Ch. 14 - In pseudocode, write the first line of the...Ch. 14 - Look at the following pseudocode class...Ch. 14 - Pet Class Design a class named Pet, which should...Ch. 14 - Car Class Design a class named Car that has the...Ch. 14 - Personal Information Class Design a class that...Ch. 14 - Emp1oyee and ProductionWorker Classes Design an...Ch. 14 - Essay Class Design an Essay class that extends the...
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
    Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
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