Results 1 to 2 of 2
  1. #1
    Lucas is offline Member
    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Default Car attributes, initializing, get, set and display

    So I have built the following:

    Java Code:
    public class Automovil {
    	String marca;
    	int modelo;
    	int numeroDeCaballos;
    	double precio;
    	boolean airbag;
    	
    	public Automovil(String startMarca, int startModelo, int startNumeroDeCaballos, double startPrecio, boolean startAirbag) {
    		marca = startMarca;
    		modelo = startModelo;
    		numeroDeCaballos = startNumeroDeCaballos;
    		precio = startPrecio;
    		airbag = startAirbag;
    	}
    	
    	public String getMarca() {
    		return marca;
    	}
    	
    	public void setMarca(String startMarca) {
    		marca = startMarca;
    	}
    	
    	public int getModelo() {
    		return modelo;
    	}
    	
    	public void setModelo(int startModelo) {
    		modelo = startModelo;
    	}
    	
    	public int getNumeroDeCaballos() {
    		return numeroDeCaballos;
    	}
    	
    	public void setNumeroDeCaballos(int startNumeroDeCaballos) {
    		numeroDeCaballos = startNumeroDeCaballos;
    	}
    	
    	public double getPrecio() {
    		return precio;
    	}
    	
    	public void setPrecio(double startPrecio) {
    		precio = startPrecio;
    	}
    	
    	public boolean getAirbag() {
    		return airbag;
    	}
    	
    	public void setAirbag(boolean startAirbag) {
    		airbag = startAirbag;
    	}
    	
    }
    How can I initialize my program and set its variables? I know I have to create a new class and set the attributes values, but how do I connect them?

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    First For this constructions you can use Builder pattern Creational Patterns - Builder Pattern
    Second What is mean "how do I connect them". Do you not understand how use this class in your projects?
    Skype: petrarsentev
    http://TrackStudio.com

Similar Threads

  1. Help with initializing error
    By GDW in forum New To Java
    Replies: 7
    Last Post: 10-20-2010, 08:10 PM
  2. Creating and initializing a SWT spinner widget
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 04:50 PM
  3. Initializing variables using constructors
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-13-2008, 08:28 PM
  4. Initializing SAXParser
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-14-2007, 06:33 PM
  5. Initializing Arrays
    By bugger in forum New To Java
    Replies: 5
    Last Post: 11-09-2007, 09:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •