trouble with classes and compiling, void type not allowed?

I'm very new to all this but im trying to compile a program that tells a class with a constructor to accept the cars year model and make as an arguement . I think I got that part. The program then is supposed to call an accelerate method 5 times and print the speed each time starting at 0. Sounds simple but after 5 hours I think Ive got as close as I can get..Any suggestions would be greatly appreciated. I'm up against the wall on this. I'm also unsure of how the stars work...do I reward or award them? Thank you !!!!Jsin code as follow in two parts

import java.util.Scanner;

publicclass Car

{

publicstaticvoid main(String[] args)

{

int count;

int speed=0;

int carConstructor;

Constructor car1 =new Constructor();

car1.accelerate();// not sure here

System.out.println("Speed is : " + car1.accelerate() +" MPG");

car1.accelerate();

System.out.println("Speed is : " + car1.accelerate() +" MPG");

car1.accelerate();

System.out.println("Speed is : " + car1.accelerate() +" MPG");

car1.accelerate();

System.out.println("Speed is : " + car1.accelerate() +" MPG");

car1.accelerate();

System.out.println("Speed is : " + car1.accelerate() +" MPG");

car1.brake();// not sure here

System.out.println("Speed is : " + car1.brake(speed) +" MPG");

car1.brake();// not sure here

System.out.println("Speed is : " + car1.brake(speed) +" MPG");

car1.brake();// not sure here

System.out.println("Speed is : " + car1.brake(speed) +" MPG");

car1.brake();// not sure here

System.out.println("Speed is : " + car1.brake(speed) +" MPG");

car1.brake();// not sure here

System.out.println("Speed is : " + car1.brake(speed) +" MPG");

}}

PART 2

import java.util.Scanner;

publicclass Constructor// Creates class called Car

{

Scanner keyboard =new Scanner(System.in);

String yearModel;

String make;

String carConstructor;

privateint speed ;

publicString carConstructor(String yearmodel, String make,int speed)

{

System.out.println("Enter the year model : ");

yearModel = keyboard.nextLine();

System.out.println("Enter the make : ");

make = keyboard.nextLine();

speed = 0;

return carConstructor;

}

publicvoid accelerate(int speed)

{

speed = speed + 5;

}

publicstaticvoid brake(int speed)

{

speed = speed - 5;

}

}

[4525 byte] By [alexerosa] at [2007-11-27 11:37:46]
# 1

> I'm very new to all this but im trying to compile a

> program that tells a class with a constructor to

> accept the cars year model and make as an arguement .

> I think I got that part.

Nope.

This is not a constructor

publicString carConstructor(String yearmodel, String make,int speed)

Your constructor signature should look like the following

public Car(String yearmodel, String make)

Besides the speed (and I don't know where you got that from) do you notice the important differences between those two lines of code?

PS dukes do not assign themselves. Once you have assigned dukes to a thread you need to reward them to the people who answered your question. Please take a brief moment to return to your old thread and reward the dukes to myself and others who took the time to answer your question http://forum.java.sun.com/thread.jspa?threadID=5197350

cotton.ma at 2007-7-29 17:16:21 > top of Java-index,Java Essentials,New To Java...
# 2

hi,

Take this total code and compile and run,

import java.util.Scanner;

public class Car

{

Scanner keyboard = new Scanner(System.in);

String yearModel;

String make;

int speed = 0;

public Car ( )

{

System.out.println("Enter the year model : ");

yearModel = keyboard.nextLine();

System.out.println("Enter the make : ");

make = keyboard.nextLine();

}

public int accelerate()

{

speed = speed + 5;

return speed;

}

public int brake()

{

speed = speed - 5;

return speed;

}

public static void main(String[] args)

{

Car car1 = new Car();

System.out.println("Speed is : " + car1.accelerate() + " MPG");

System.out.println("Speed is : " + car1.accelerate() + " MPG");

System.out.println("Speed is : " + car1.accelerate() + " MPG");

System.out.println("Speed is : " + car1.accelerate() + " MPG");

System.out.println("Speed is : " + car1.accelerate() + " MPG");

System.out.println("Speed is : " + car1.brake() + " MPG");

System.out.println("Speed is : " + car1.brake() + " MPG");

System.out.println("Speed is : " + car1.brake() + " MPG");

System.out.println("Speed is : " + car1.brake() + " MPG");

System.out.println("Speed is : " + car1.brake() + " MPG");

}

};

successfully run output will come

drvijayy2k2a at 2007-7-29 17:16:21 > top of Java-index,Java Essentials,New To Java...
# 3

> hi,

>

> Take this total code and compile and run,

>

> successfully run output will come

Perhaps. But the OP would fail the assignment because the class does not follow the specifications laid out in the assignment.

So you fail too. Better luck next time.

cotton.ma at 2007-7-29 17:16:21 > top of Java-index,Java Essentials,New To Java...
# 4

I suggest you go through a tutorial about OOP, as you need to figure out why there are two classes, and what they should be doing. Here's a link to a nice tutorial online with very similar concepts to what you're attempting to do.

http://java.sun.com/docs/books/tutorial/java/javaOO/classes.html

lance_dragonsa at 2007-7-29 17:16:21 > top of Java-index,Java Essentials,New To Java...
# 5

Thanks again, I got up at 5 am and debug and fixed my code, plus now I understand what i did wrong...I apreciate it!

alexerosa at 2007-7-29 17:16:21 > top of Java-index,Java Essentials,New To Java...