Example; the area of floor that is 12 feet long and 10 feet wide is 120 square feet. If the carpet costs $8 per square foot the total cost is $960. (12 * 10 * 8 = 960)
Create a class named RoomDimension that has two fields; length and width.
A method that returns the area of the room.
Creat a class named RoomCarpet that has two fields; cost per square feet and the RoomDimension object.
A method that returns the total cost of the carpet.
Write a driver class that asks the user to enter the dimensions of the room and the price per square foot.
The application should display the total cost of the carpet.
These are the code snippets I wrote:
My problem is with the getTotalCost function in the RoomCarpet class. How do I pull the two doubles so that I can do the math equations?
 1
There are only two hard things in computer science: cache invalidation, naming things, and offbyone errors
 1
Practice only makes habit, only perfect practice makes perfect.
So, practice mindfully. Practice doing the right things and doing things right. — Junilu
[How to Ask Questions] [How to Answer Questions]
 1
Practice only makes habit, only perfect practice makes perfect.
So, practice mindfully. Practice doing the right things and doing things right. — Junilu
[How to Ask Questions] [How to Answer Questions]
fred rosenberger wrote:You don't need to pull the dimensions from the RoomDimension object. To calculate the cost, you don't care if it's 10x12 or if it's 120x1. All you want is the area of the room. So, you can call the RoomDimension's getArea() method, and multiply that by the cost.
the way it was assigned, was like this...
RoomCarpet
 size : RoomDimension
 carperCost : double
+ RoomCarpet(dim: RoomDimension, cost : double)
+ getTotalCost() : double
+ toString() : String
<>


RoomDimension
 length : double
 width : double
+ RoomDimension(len : double, w : double)
+ getArea() : double
+ toString() : String
So according to the diagram, I think I do have to call the two doubles from RoomDimension. Or am I understanding this incorrectly? I am sorry, this is all very new to me.
Thanks for your help.
 1
Practice only makes habit, only perfect practice makes perfect.
So, practice mindfully. Practice doing the right things and doing things right. — Junilu
[How to Ask Questions] [How to Answer Questions]
 1
In the real world, you go to a carpet store. You ask the salesman "How much will it cost to carpet my room?". He says "Well, how big is your room?"
He doesn't care what the specific dimensions are, he only cares about the total area. So you can say "120 square feet", and he can give you an answer.
There are only two hard things in computer science: cache invalidation, naming things, and offbyone errors