ESPI B3 SYSOPS Langage Programmation Java

De Epsi-Wis
Aller à la navigation Aller à la recherche

Introduction à la … Java

    -->    Intro a la méthodologie de développement logiciel
                o    Approche système classique |langace C
                o    Approche iterative {Objet} | Langage Java


Exercice 1 26/10/2021


etudiant.java

package ecole;

import java.util.Scanner;

public class Etudiant {
	public int id;
	private String nom;
	private String prenom;
	private float note;
	
	public Etudiant(int numero, String nom) {
		
		this.id = numero;
		this.nom = nom;
	}
	
	
	public Etudiant(int id, String nom, String prenom, float note) {
		super();
		this.id = id;
		this.nom = nom;
		this.prenom = prenom;
		this.note = note;
	}


	public String getPrenom() {
		return prenom;
	}

	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}

	public int getNumero() {
		return id;
	}
	public String getNom() {
		return nom;
	}
	
	public float getNote() {
		return note;
	}	
	public void setNote(float note) {
		this.note = note;
	}
	
	/*
	public String toString() {
		
		return "Etudiant : id : "+this.getNumero()+" - nom : "+
			       this.getNom() + " - note : "+ this.getNote();
	}
	*/
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		float mark;
		String name;
		
		try ( Scanner scanner = new Scanner( System.in ) ) {
            
            System.out.print( "Veuillez saisir le nom : " );
            name = scanner.nextLine();
           
            System.out.print( "Veuillez saisir la note : " );
            mark = scanner.nextFloat();
                              
        }
			
		Etudiant e1 = new Etudiant(1001, "Toto");
		System.out.print("Saisir la note de l etudiant : ");
		
		e1.setNote(15);
		System.out.println("Etudiant : numero : "+
		   e1.getNumero()+" - nom : "+e1.getNom() + " - note : "+ e1.getNote());
		
		Etudiant e2 = new Etudiant(1002, name, "", mark);
		
		System.out.println("Etudiant : numero : "+e2.getNumero()+" - nom : "+
		       e2.getNom() + " - note : "+ e2.getNote());
	}


	@Override
	public String toString() {
		return "Etudiant [id=" + id + ", nom=" + nom + ", prenom=" + prenom + ", note=" + note + "]";
	}
}


MainTest.java

package ecole;

public class MainTest {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
	Etudiant e1 = new Etudiant(1001, "Toto");
	
	e1.id = 1;
	System.out.println(e1);
	}

}

Java-TP-26-20-2021