Hi!
I have a little problem
The program is OK, but I can not print out:
QUESTION is how can I print out (class Test).
I mean How can I write toString()methode.how can I print out "myTable"
and the out put must be
like this:
Audi blue 180
Volvo red 120
Ford black 137
Saab white 125
I mean this toString() in class car must print out
every thing both in class car and class carTable.
but toString methode is just in class Car not in Class carTable.
---------------
calss Test{
Car c1 = new Car("Audi", "blue", 180);
Car c2,c3,
CarTable myTable= new CarTable();
myTable.addCar(c1);

myTable.addCar(new Car("Volvo","red",120));

myTable.addCar(new Car("Ford","black",137));

myTable.addCar(new Car("Saab","white",125));

System.out.println(myTable);//???????
-------------
class Car{
public Car(String model, String color, double power){
public String getModel()
public String getColor()
public double getPower()
public void setModel(String model)
public void setColor(String color)
public void setPower(double power)
public String toString()//?????????????
------------------
class CarTable{
public void addCar(String model, String color, int power){
myCar[nbrOfCar] = new Car(model, color, power);
nbrOfCar++;
}
public void addCar(Car newCar){
myCar[nbrOfCar]= newCar;
nbrOfCar++;
}
public Car getCar(int n){
return myCar[n];

Recommended Answers

All 2 Replies

>but toString methode is just in class Car not in Class carTable.
So define it for carTable.

Hi again!
Sorry!
I wrote wrong about toString. I mean How can I write toSting methode.
It make no difference where we write the toString methode, but important is how can I print out the class Test.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.