0% found this document useful (0 votes)
24 views3 pages

Try To Mak It

try to java

Uploaded by

m_ruben2009
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

Try To Mak It

try to java

Uploaded by

m_ruben2009
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Try to make it yourself.

/*Programul permite adougarea de studenti si profesori, si cautarea lor dupa num arul matricol * respectiv dupa numarul de angajat */ import java.io.*; import java.util.*; //definim clasa persoana care a clasa parinte, cu atributele comune atat student ilor cat si // profesorilor si anume: nume, prenume, cnp class Persoana { String Nume, Prenume; long CNP; public Persoana(String nume, String pren, long cnp) { Nume = nume; Prenume = pren; CNP = cnp; }

public void afisPersoana() { System.out.println("Numele= " + Nume + "\nPrenumele= " + Prenume + "\nCN P= " + CNP); } }

//definrea clasei student cu atributele de persoana si numar matricol si an class Student extends Persoana { int An, nrMatricol; public Student(String nume, String pren, long cnp, int an, int nrm) { super(nume, pren, cnp); An = an; nrMatricol = nrm; } public void afisStud(){ super.afisPersoana(); System.out.println("Anul= " + An + "\nNumarul matricol= " + nrMatricol); } } //definim clasa profesor class Profesor extends Persoana { String Materie; int nrAngajat;

public Profesor(String nume, String pren, long cnp, String materie, int nra) { super(nume, pren, cnp); Materie = materie; nrAngajat = nra; } public void afisProf(){ super.afisPersoana(); System.out.println("Materie= " + Materie + "\nNumar angajat= " + nrAngajat); } }

public class gestiuneStudent { public static void main(String args[]) { String nume, pren, materie; int nrm, an, opt, i=0,j=0,k=0, nra; long cnp=0; Scanner s=new Scanner (System.in); s.useDelimiter("\n"); Student stud[] = new Student[10]; //definim un obiect de tip Student cu maxim 10 studenti Profesor prof[] = new Profesor[10]; //definim un obiect de tip Profesor cu maxim 10 profesori do { System.out.println("1 - Adougare student"); System.out.println("2 - Adougare profesor"); System.out.println("3 - Cautare student"); System.out.println("4 - Cautare profesor"); System.out.println("5 - Iesire"); System.out.println("Optiunea dvs: "); opt = s.nextInt(); switch(opt) { case 1: System.out.println("Numele: "); nume = s.next(); System.out.println("Prenumele: "); pren = s.next(); System.out.println("cnp: "); cnp = s.nextLong(); System.out.println("Numarul matricol: "); nrm = s.nextInt(); System.out.println("An: "); an = s.nextInt(); stud[i] = new Student(nume, pren, cnp, an, nrm); i++; break; case 2: System.out.println("Numele: "); nume = s.next(); System.out.println("Prenumele: "); pren = s.next(); System.out.println("cnp: ");

cnp = s.nextLong(); System.out.println("Numarul angajatului: "); nra = s.nextInt(); System.out.println("Materie: "); materie = s.next(); prof[k] = new Profesor(nume, pren, cnp, materie, nra); k++; break; case 3: System.out.println("Numaru matricol: "); nrm = s.nextInt(); try{ for (j=0; j<=i; j++) { if (stud[j].nrMatricol==nrm) stud[j].afisStud(); j=10;} {

} } catch (NullPointerException e) { System.out.println("Persoana negasita"); } break; case 4: System.out.println("Numarul de angajat: "); nra = s.nextInt(); // verificam daca numarul matricol exista, daca nu exista se generaz a o exceptie, // care e tratata prin afisarea mesajului: Persoana ne gasita try{ for (j=0; j<=k; j++) { if (prof[j].nrAngajat==nra) prof[j].afisProf(); } {

} } catch (NullPointerException e) { System.out.println("Persoana negasita"); } break; case 5: System.exit(0); } } while(opt!=5); } }

You might also like