I need help with aggregation class

Discussion in 'Java' started by darksence, Dec 4, 2008.

  1. darksence

    darksence

    Joined:
    Dec 4, 2008
    Messages:
    1
    I wrote this code and its telling me that i cannot perform the * operation in my totalCost method, can someone tell me whats wrong and how can i fix it plz? ty.

    public class RoomCarpet
    {
    private RoomDimension room;
    private double cost;

    public RoomCarpet()
    {
    room = new RoomDimension();
    cost = 0;
    }
    public RoomCarpet(double length, double width, double c)
    {
    room = new RoomDimension(length, width);
    cost = c;
    }
    public void setCost(double c)
    {
    cost = c;
    }
    public double getCost()
    {
    return cost;
    }
    public double totalCost()
    {
    return room * cost; //this is where i get the error message
    }
    public String toString()
    {
    String str;
    str = room.toString() + "\n" + "The cost of the square foot of carpet is "
    + getCost() + "\n" + "The total cost of carpet is" + totalCost();
    return str;
    }
    }
    darksence, Dec 4, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick Osborn

    Aggregation vs. composition

    Rick Osborn, Jan 23, 2004, in forum: Java
    Replies:
    11
    Views:
    57,927
    amitg_amity
    Aug 31, 2009
  2. Markos Charatzas

    Interfaces and aggregation

    Markos Charatzas, Jan 30, 2004, in forum: Java
    Replies:
    7
    Views:
    1,945
    BarryNL
    Feb 2, 2004
  3. Anonymous
    Replies:
    3
    Views:
    32,113
  4. MegaC
    Replies:
    1
    Views:
    329
    Steve Pugh
    Mar 9, 2006
  5. Aff@n
    Replies:
    1
    Views:
    362
    Ian Collins
    Oct 16, 2006
Loading...

Share This Page