Skip to main content

Please help me whit this java question.

3 replies [Last post]
Joined: 2006-02-17

I have a little problem
The program is OK, but I can not print out it:
QUESTION is how can I print out (class Test).
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

calss Test{
Car c1 = new Car("Audi", "blue", 180);
Car c2,c3,
CarTable myTable= new CarTable();

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

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

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

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)

class CarTable{
public void addCar(String model, String color, int power){
myCar[nbrOfCar] = new Car(model, color, power);
public void addCar(Car newCar){
myCar[nbrOfCar]= newCar;
public Car getCar(int n){
return myCar[n];

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-09-06

we have to build Remote Client utility in which client will access the desktop of remote pc.We can take the screenshot of current desktop of remote pc and send it to the client who want to access the desktop through RMI but the problem is here at every click event we need to take the screenshot, but how can we cature the each and every event on Desktop.

Joined: 2005-09-06

we need to capture every icon of desktop as an object and later control it in various event as we have to develop a remote desktop access client.please reply urgently...!~

Joined: 2006-02-17

try replacing the line with the printout with the following..

for (int i = 0; myTable.getCar(i) != null; i++) {

..I reckon your code would work as is if you had overwritten the toString - method in class CarTable, printing the table's contents. Now the execution of the line System.out.println(myTable) results in the method Object.toString() to be called instead of CarTable.toString(). So two ways, the one I showed or writing the toString - method to CarTable class.