My question is based on class relationships. I've written code for 2 classes, one of the "public int..." bits in 1 class has a variable which holds the cost of something. In the other class a variable holds the weight of something. I want to multiply the weight with the cost. Any help guys?

My question is based on class relationships. I've written code for 2 classes, one of the "public int..." bits in 1 class has a variable which holds the cost of something. In the other class a variable holds the weight of something. I want to multiply the weight with the cost. Any help guys?

Here is how you call variables from a seperate file and multiply them together.

double totalCost = class1name.varablename * class2name.variablename;

hope this helps. : )

Edited 5 Years Ago by DarkLightning7: n/a

Unless Class1 and Class2 are nothing more than simple data structures, the convention is to write getters that return those values rather than declaring them public. i.e. class1thing.getValue()

haha, well i can't have my competition who needs the same help for their coursework benefit on my behalf can i now? Gotta have titles which are a bit misleading ;)

And appreciate it bro, still slight problem, the UML diagram shows that the variable in other file needs to be private only so I'm getting an error saying "var has private access only" :/ what now?

Create a function within the files that return the values of weight and cost then call the functions and multiply them together to get your result.

This question has already been answered. Start a new discussion instead.