Lab13A: A Tale of Two Classes When teaching objects often you may hear the example "a chair is an object". Well for this lab, we are going to use this example. Create a class called "Chair", this is going to be a class which can create "Chair" objects. Also create a separate class to drive the function of Chair, call this driver class "Lab13A". The Driver class will contain the main method you typically make while Chair will not have a main method. Chair class: • Variables (Attributes): - notice they are public. This isn't normal, but it's ok for this lab. o public int numOfLegs o public bool/boolean rolling o public String/string material //what is the chair made of //how many legs are on the chair //does it roll or not
Lab13A: A Tale of Two Classes When teaching objects often you may hear the example "a chair is an object". Well for this lab, we are going to use this example. Create a class called "Chair", this is going to be a class which can create "Chair" objects. Also create a separate class to drive the function of Chair, call this driver class "Lab13A". The Driver class will contain the main method you typically make while Chair will not have a main method. Chair class: • Variables (Attributes): - notice they are public. This isn't normal, but it's ok for this lab. o public int numOfLegs o public bool/boolean rolling o public String/string material //what is the chair made of //how many legs are on the chair //does it roll or not
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
language is c++
picture includes sample output with user input in bold
![Lab13A: A Tale of Two Classes
When teaching objects often you may hear the example "a chair is an object". Well for this lab, we are
going to use this example.
Create a class called "Chair", this is going to be a class which can create "Chair" objects. Also create
a separate class to drive the function of Chair, call this driver class "Lab13A". The Driver class will
contain the main method you typically make while Chair will not have a main method.
Chair class:
• Variables (Attributes): - notice they are public. This isn't normal, but it's ok for this lab.
o public int numOfLegs
o public bool/boolean rolling
o public String/string material //what is the chair made of
//how many legs are on the chair
//does it roll or not
Using these attributes you can describe most chairs. For example, you might have a wooden chair
with 4 legs that does not roll, or you may have a rolling chair made of leather with 5 legs.
Now that you know the parameters and their data types you can make a constructor also called
Chair; a constructor is a special method that shares its name with the class name, it is responsible for
creating the object and starting it off with values for its attributes. It should take in user inputs to
provide meaningful info for each attribute.
This class isn't going to have any methods, so it should only include a constructor and the attributes.
Driver class:
This class is going to have a main method and take user input for the attributes for the Chair object.
Once you have all that information, create a new object with those variables as parameters.
Once you have done that, print out the information about your chair. You can use the name of your
Chair object and the dot operator (a period) to print out info about the chair you created.
Then, to show you really understand how the dot operator can work. Change the attributes to:
numofLegs = 4;
rolling = false;
material = wood;
Finally, repeat your print statement you wrote earlier to print out what the chair looks like.
Tip: When taking in parameters to a constructor, you may want to do have the variables used in the
constructor header be different words from the attributes in the Chair class. When dealing with
rolling/not rolling you may want to use an IF statement with different print statements.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Ff04f523d-cad1-46a0-8446-99b6c9606c43%2F4322c1e6-3170-4076-8931-6485d1d84e28%2Faql8ir5_processed.png&w=3840&q=75)
Transcribed Image Text:Lab13A: A Tale of Two Classes
When teaching objects often you may hear the example "a chair is an object". Well for this lab, we are
going to use this example.
Create a class called "Chair", this is going to be a class which can create "Chair" objects. Also create
a separate class to drive the function of Chair, call this driver class "Lab13A". The Driver class will
contain the main method you typically make while Chair will not have a main method.
Chair class:
• Variables (Attributes): - notice they are public. This isn't normal, but it's ok for this lab.
o public int numOfLegs
o public bool/boolean rolling
o public String/string material //what is the chair made of
//how many legs are on the chair
//does it roll or not
Using these attributes you can describe most chairs. For example, you might have a wooden chair
with 4 legs that does not roll, or you may have a rolling chair made of leather with 5 legs.
Now that you know the parameters and their data types you can make a constructor also called
Chair; a constructor is a special method that shares its name with the class name, it is responsible for
creating the object and starting it off with values for its attributes. It should take in user inputs to
provide meaningful info for each attribute.
This class isn't going to have any methods, so it should only include a constructor and the attributes.
Driver class:
This class is going to have a main method and take user input for the attributes for the Chair object.
Once you have all that information, create a new object with those variables as parameters.
Once you have done that, print out the information about your chair. You can use the name of your
Chair object and the dot operator (a period) to print out info about the chair you created.
Then, to show you really understand how the dot operator can work. Change the attributes to:
numofLegs = 4;
rolling = false;
material = wood;
Finally, repeat your print statement you wrote earlier to print out what the chair looks like.
Tip: When taking in parameters to a constructor, you may want to do have the variables used in the
constructor header be different words from the attributes in the Chair class. When dealing with
rolling/not rolling you may want to use an IF statement with different print statements.
![Sample output:
You are about to create a chair.
How many legs does your chair have: 8
Is your chair rolling (true/false): true
What is your chair made of: plastic
Your chair has 8 legs, is rolling, and is made of plastic.
This program is going to change that.
Your chair has 4 legs, is not rolling, and is made of wood.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Ff04f523d-cad1-46a0-8446-99b6c9606c43%2F4322c1e6-3170-4076-8931-6485d1d84e28%2F9zqvsmk_processed.png&w=3840&q=75)
Transcribed Image Text:Sample output:
You are about to create a chair.
How many legs does your chair have: 8
Is your chair rolling (true/false): true
What is your chair made of: plastic
Your chair has 8 legs, is rolling, and is made of plastic.
This program is going to change that.
Your chair has 4 legs, is not rolling, and is made of wood.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
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.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education