Results 1 to 3 of 3
Thread: Comparing costs method
- 04-17-2009, 09:33 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 18
- Rep Power
- 0
Comparing costs method
I am doing a qestion in which i had to build a car class and create a series of simple functionality.
However the method mostCostly is proving dificult.
The desired functionality of this method is as follows:
"The mostCostly method returns the greater cost of the two Cars by comparing the cost of itself with the cost of the Car passed in as a parameter."
Just experiencing dificulties coparing the peramiter to itself. (presuming itself means (Class "Car"))
My attempt at this is:
i know the methods completely wrong and doesnt do anything but does anyone know how i would go about creating this method.Java Code:package assignment3; import java.awt.Color; public class Car { private String model; private Color color; private int cost; public Car(String model, Color color, int cost) { this.model = model; this.color = color; this.cost = cost; } public Car(String model) { this.model = model; cost = 10000; color = Color.black; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } public Color getColor() { return color; } public void setColor(Color color) { this.color = color; } public int getCost() { return cost; } public void setCost(int cost) { this.cost = cost; } public int mostCostly(Car car) { int perameterCar = car.getCost(); int largest1 = perameterCar - cost; int largest2 = cost - perameterCar; car.equals(car); return largest; } }
Thanx George-Long time no c-
-:eek:-
- 04-17-2009, 09:46 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 8
maybe?Java Code:if (cost > car.cost)
- 04-17-2009, 09:55 AM #3
Member
- Join Date
- Mar 2009
- Posts
- 18
- Rep Power
- 0
Thanx for the help just couldn't get my head round the class relationship side as im new to this.
I think this is the right idea now to return the higher value.Java Code:public int mostCostly(Car car) { int largest = 0; if (cost > car.cost) { largest = cost; } else { largest = car.cost; } return largest; }-Long time no c-
-:eek:-
Similar Threads
-
Comparing two images
By GhosT in forum Advanced JavaReplies: 13Last Post: 04-25-2009, 12:37 AM -
Comparing Images
By shaungoater in forum Advanced JavaReplies: 0Last Post: 03-17-2008, 10:38 AM -
comparing
By Feng in forum New To JavaReplies: 2Last Post: 11-23-2007, 09:40 AM -
Comparing JavaWebFrameworks
By pegitha in forum Web FrameworksReplies: 1Last Post: 05-18-2007, 06:23 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks