Java – Classe Camion

/**
   * @author Simone De Luca
*/

import java.io.*;

public class Camion(){
	
	// attributi
	private int ruote;
	private int posti;
	private String nomeCamion;
	private boolean isNew;
	
	// metodi
	public Camion(String nomeCamion, boolean isNew, int posti, int ruote) {
		this.nomeCamion = nomeCamion;
		this.isNew = isNew;
		
		if(posti > 1) this.posti = posti;
		else this.posti = 2;
		
		if(ruote > 3) this.ruote = ruote;
		else this.ruote = 2;
	} // fine costruttore
	
	// getters
    String getNome() { return nomeCamion; }
    boolean getIsNew() { return isNew; }
    int getRuote() { return ruote; }
    int getPosti() { return posti; }
    
    // setters
    String setNome(String nome) { this.nome = nome; }
    boolean setIsNew(boolean isNew) { this.isNew = isNew; }
    int setRuote(int ruote) { this.ruote = ruote; }
    int setPosti(int posti) { this.posti = posti; }
	
	boolean cmp_posti(Camion c2) {
		if(c2.getPosti() == this.posti) return true;
		else return false;		
	} // fine metodo compara posti
	
	// main
	public static void main() {
		Camion c1;
		c1 = new Camion("Camion 1", true, 4, 6);
		Camion c2;
		c2 = new Camion("Camion 2", false, 4, 4);
		
		System.out.println(c1.toString());
		System.out.println(c2.toString());
		System.out.println(c1.cmp_posti(c2));
				
	} // end main

} // end class

You may also like...


x

Leggi anche...

Java - Autonoleggio
Classe Veicolo: [code lang="java"] //import java.io.Serializable; public class Veicolo /*implements Serializable*/{ private String targa...
Powershell: Esercitazione sui processi
CONSEGNA: - contare il numero dei processi attivi - far selezionare all'utente quanti processi vuole esportare - prendere n. process...
PowerShell: Esercitazione sui servizi
CONSEGNA: - prendere servizi in base a status - contare n processi per ogni tipo - esportare ogni quey in 3 formati - zippare il...
powered by RelatedPosts