-2

UML Details of the methods of Ders(LESSON) class are as follows:

addStudent(Student student)=ogrenciEkle(Ogrenci ogrenci), searchStudent(Integer studentNo)=ogrenciBul(Integer ogrenciNo)

Ogrenci(Student)=class,studentNo=ogrenciNO,arananOgrenciNo=searchStudentNo(given)-Hashmap< Integer,Ogrenci> ogrenciler

I want to search in hashmap with Integer(given number)in ogrenciBul(searchStudent) method

package araSinav2;
import java.util.*;
public class Ders {
    private String kod,isim;
    private HashMap<Integer,Ogrenci> ogrenciler;
    private OgretimUyesi hoca;
    private int kapasite;

    private Ders(String kod,String isim){
        this.kod=kod;
        this.isim=isim;
    }

    public String getKod() {return kod;}
    public String getIsim() {return isim;}
    public OgretimUyesi getHoca() {return hoca;}
    public void setHoca(OgretimUyesi hoca) {this.hoca = hoca;}
    public int getKapasite() {return kapasite;}
    public void setKapasite(int kapasite) {this.kapasite = kapasite;}

    //public int getKayitliOgreciKapasite() {return kapasite;}

    public Ogrenci ogrenciBul(Integer arananOgrenciNo){

    }   
}
J.Doe123
  • 15
  • 3

2 Answers2

1

No method needed, you simply return a value with map.get(index) where index is the key in the map referring to the object.

However, if you really need the method, do this:

public Ogrenci ogrenciBul(Integer arananOgrenciNo){
    return ogrenciler.get(arananOgrenciNo);
}   

It returns the whole instance of object Ogrenci.

Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183
0

Iterate the HashMap like this How to efficiently iterate over each Entry in a Map?

Then for each entry check if it's a match. If it's a match then return it.

Your question is not very clear though, but hope this helps.

Community
  • 1
  • 1
Morten Telling
  • 56
  • 1
  • 1
  • 11