• Post Reply Bookmark Topic Watch Topic
  • New Topic

I havent ''created' objects they told me for car ,motor, etc  RSS feed

 
maikl Gen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
create class Vehicle that describes a vehicle that contains:
*engine
*sysd(the whole system of the vehicle)
*owner
*number plate
*number position
*number wheels
*number of passengers
*Using(example :professional...)
*Manufacter
*max speed
*lenth rezerbouar(in lt)
*litre venzinis
Also there are some methods
fillRezerbouar:Full rezerbouar.The whole (lt) in rezerbouar it is equal with the length of rezerbouar
kmRezerbouar:Finds the distance it can do the vehicle that has in rezerbouar.
Engine,sysd and owner are the parts of the vehicle in which described by classes.
*Engine are described by engine class.It has 2 fields kubismos and horsepower.It has 3 methods(start(),stop(),reverse())
in which appear some message .What ever you want
*Sysd described by the class Steering and it have 4 methods(Start(),stop(),turnleft(),turnright()) that i appear
what message i want to
*Owner described by a class Veh_Owner and it has 3 fields(name,lastname,address).
Create the class Car,Truck,Motorcycle that extends the Vehicle.These classes have this fields
*number of doors for the class Car
*number of wheels for class Truck
Every object from any type of vehicle it has the methods:
*transferOwnership:that takes as parametre the new owner,change old with the new owner and appear a message"owenr has
been changed"
*drive :appear a message depends on the type of vehicle.Example:"You need a car driving license dear<name of owner>" for the object type "Car"
Create class "Sedan","Sport",and "Cabrio" that extends the "Car".
For the cars sedan using is family,for the cabrio using is journey and for sport using is for professional.
In the main program: One business having K(The K giving by keyboard)vehicles.When will insert the whole of vehicles the user should give how many
of them are type of "Car",how many of that are "Truck",how many of that are "Motorcycle".(This all will be repeated until the adding is difference
to K).
All objects created by the specific constructor that initialize all variable except of the owner (type Veh_owner) and the number of plate.
Insert all characteristic of motors,cars,truck(example :number of passengers of cars 9,number of wheels motor 2...).When will created the objects with
the allowed .
HELP ADVICES:
*Every characteristic of each class should be private and it should have methods access(access methods) and changing(accessor methods) in all classes
*in subclasses "Vehicle" it should "up-method" of the current class.
----------------------------
What i did .I want help only with the objects ,constructors.
my main class:

 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maikl,
that is a lot of code to have produced and not have it be working.

Do you have specific questions? (As it stands it looks like you want someone to refactor your project, and that is just not happening--at least by me.)
Les
 
maikl Gen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Les Morgan wrote:maikl,
that is a lot of code to have produced and not have it be working.

Do you have specific questions? (As it stands it looks like you want someone to refactor your project, and that is just not happening--at least by me.)
Les
no no i dont say no one to solve it I want only to create a car , a motor and a truck with objects .On this program i havent create a vehicle type of car ,truck and motor.What you suggest to create the vehicles?
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This tutorial explains about creating objects. Basically, you use the new keyword to create an object from a class.

But it looks like you're supposed to add constructors to your classes. A very basic constructor looks like this:

If you want your constructor to initialize a field, it would look like this:

That should be enough information to get you started.
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
increase=3/100;
This will always be zero because you're doing an integer divide.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I can see several problems, I am afraid.
  • 1: You are trying to do too much all at once. Shorten the Car class by 99%, so you have 4 wheels a suggested, and nothing else. Once you have that working, then consider adding other features. Add them one at a time, so you only have a few lines of new code to compile.
  • 2: Your code is very difficult to read because it is not consistently indented and has too many blank lines in.
  •  
    maikl Gen
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Knute Snortum wrote:This tutorial explains about creating objects. Basically, you use the new keyword to create an object from a class.

    But it looks like you're supposed to add constructors to your classes. A very basic constructor looks like this:

    If you want your constructor to initialize a field, it would look like this:

    That should be enough information to get you started.
    could i create an array with this?example array with cars,array with trucks and array with motors?but my problem is the user give the number if he gives 100 .I should create a hundret objects or to have an array 100 ..its little ''complicated'' isnt it? what you guys suggest me to do with this things?First i should create the objects ok .Second i think to pass them depends on the category (car,truck,motor) in arrays.I am losing that user will give much more.I have confused
     
    Campbell Ritchie
    Marshal
    Posts: 56533
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I shall try to correct some of your formatting:-There is too much code for me to correct everything. Note blank lines between successive methods.
    You are using the keyword static often. Why? I have a rule of thumb: every occurrence of static is a mistake, unless there is a good explanation for it.
    Why are you importing button from its own class? Why are the fields in the Erg3 class not marked private, as those in the Vehicle class are?

    [edit]I had to have two attempts at the indentation and it still isn't quite right. If you have { at the end of the line always put a few spaces before the {
     
    Knute Snortum
    Sheriff
    Posts: 4276
    127
    Chrome Eclipse IDE Java Postgres Database VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    could i create an array with this?example array with cars,array with trucks and array with motors?but my problem is the user give the number if he gives 100 .I should create a hundret objects or to have an array 100 ..its little ''complicated'' isnt it? what you guys suggest me to do with this things?First i should create the objects ok .Second i think to pass them depends on the category (car,truck,motor) in arrays.I am losing that user will give much more.I have confused

    I'm having some trouble understanding your English. (This is not a criticism; my Greek is pretty bad!) If I'm understanding you correctly, you could put your Car objects into an array, but a List like an ArrayList would be easier. Lists grow to whatever size you need.

    But back to your code. Your code is very poorly formatted. Good formatting is essential, not just something nice to do. It will help show you the flow and control of your logic.

    Next, you have a lot of code in the main() method. Ideally, the main() method should have one or two line in it:

    And then you write a run() method. See Main is a Pain.

    Do these things and then your other questions will be easier to answer.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!