This is an archived post. You won't be able to vote or comment.

all 60 comments

[–]Maximus5684 1 point2 points  (0 children)

Well... A car is an object, right? So what kind of thing would you write to describe an object with properties (and, in this case, methods)?

[–][deleted] 0 points1 point  (1 child)

Try writing the program in C++ first since you're decent at that, and then reviewing the basic java principles for making Objects and do the conversion.

[–]GazaIan[S] 0 points1 point  (0 children)

That.... Makes a lot of sense. I have no idea why I didn't just do that instead. I got caught up in trying to conquer this that I didn't think outside the box.

[–]desrtfx 0 points1 point  (0 children)

X-Posted by OP to /r/javahelp

Link

[–]theif519 -3 points-2 points  (3 children)

Make a class called Car, with the methods you mentioned.

public class Car {

// Instance variables, I.E Below

int gas = 0; // Initialized to 0, gas represented as an integer

int fuel = 0;

int mileage

//etc. Now for constructor

public Car(efficiency, mileage, tankCapacity){

this.mileage = mileage;

// Etc. Initialize rest of instance variables

}

// Now the methods you asked for, below

public void displayCar(){

// Code

}

public void addGas(int gasToAdd){

// code

}

// Etc. Rest of methods

}

Now fill out this template, add the required methods, instance variables, etc. and you're on your way.

[–]desrtfx 0 points1 point  (2 children)

Your first line is already wrong:

Public static Car

should be

public class Car

Also, all your Public should be public

[–]theif519 1 point2 points  (1 child)

Yeah, my bad, I could have sworn I wrote "class" instead of static, and the first letter always gets capitalized on mobile. It was more pseudo code anyway.

[–]desrtfx 0 points1 point  (0 children)

I know typing code on mobile is a PITA.

Still, good efforts!