Computing.Net > Forums > Programming > Please help me whit a java quest.

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Please help me whit a java quest.

Reply to Message Icon

Name: peterx
Date: October 31, 2004 at 13:37:23 Pacific
OS: win xp
CPU/Ram: 256
Comment:

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
---------------
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];




Sponsored Link
Ads by Google

Response Number 1
Name: peterx
Date: October 31, 2004 at 15:08:45 Pacific
Reply:

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


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Please help me whit a java quest.

Please help me whit this java quest www.computing.net/answers/programming/please-help-me-whit-this-java-quest/11397.html

please help me whit this java code www.computing.net/answers/programming/please-help-me-whit-this-java-code/11640.html

Please Help me in VB www.computing.net/answers/programming/please-help-me-in-vb/7830.html