Hey everyone, I'm pretty new with Java and am preparing for a class I'm taking later this summer. I've been doing a lot of self study and have been attempting to get as far as I can in some Java books by myself. Right now I'm working on a carpet calculator problem and I'm a bit stuck. I'm attempting to create a RoomDimension class to set the area of a room, then use a method from that class to establish an argument in a RoomCarpet class which calculates the total cost of of carpeting for the room.
public class RoomCarpet { private double carpetCost; private double roomSize; private RoomDimension yourSize; // This is what I'm having trouble with public RoomCarpet(double cost, double roomsize){ // I'm not sure if I should use double or a RoomDimension object as the parameter carpetCost = cost; yourSize = new RoomDimension(); // I'm not sure what to pass as arguments here roomSize = yourSize.getArea(); } ...
and here's the RoomDimension class:
public class RoomDimension { private double length; private double width; public RoomDimension(double len, double w){ length = len; width = w; } public RoomDimension(RoomDimension object2){ length = object2.length; width = object2.width; } public double getArea(){ return length * width; } public String toString(){ String str; str = "This rooms area is " + getArea(); return str; } }
I'd appreciate any help I can get. Thanks!