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 material = wood; = false; %3D Finally, repeat your print statement you wrote earlier to print out what the chair looks like.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 20RQ
icon
Related questions
Question

langauge is c++

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.
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.
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Unreferenced Objects
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
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,