Package Collections; import java util. ArrayList; import


Download 21.37 Kb.
Sana14.11.2020
Hajmi21.37 Kb.
#145931
Bog'liq
Laboratoriya ishi


Laboratoriya ishi № 1.

Mavzu : Talabalar yotoxonasidan talabalarni samarali qidirish dasturi

Program code:

package Collections;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class First {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList students[] = new ArrayList[100];
ArrayList rooms = new ArrayList<>();
Map> map[] = new Map[100];
ArrayList>> list= new ArrayList<>();

int roomAmount;
System.out.print("Xonalar sonini kiriting : ");
roomAmount = scanner.nextInt();
for (int i = 0; i < roomAmount; i++) {
map[i] = new HashMap<>();
students[i] = new ArrayList<>();
System.out.print(i+1 + " - xona nomerini kiriting : ");
rooms.add(scanner.nextInt());
System.out.print(rooms.get(i) + " - xona talabalari sonini kiriting : ");
int student = scanner.nextInt();
for (int j = 0; j < student; j++) {
System.out.print(j+1+" - talaba familiyasini kiriting : ");
students[i].add(scanner.next());
}
map[i].put(rooms.get(i), students[i]);
list.add(map[i]);
System.out.println();
}

System.out.println("\tTATU KIF Fakulteti yotoxonasidan talabalarni qidirish dasturiga xush kelibsiz!\n");


System.out.println("Qanday ma'lumotni qidirmoqchisiz?");
System.out.println("1. Xona raqami orqali talabalarni qidirish ");
switch (scanner.nextInt()){
case 1:
homeMenu(list,rooms);break;
}
}

public static void homeMenu(ArrayList>> list, ArrayList rooms){
System.out.println("Qaysi xonadan talabalarni qidirmoqchisiz : ");
for (int i = 0; i < rooms.size(); i++) {
System.out.println((i+1)+ ". " + rooms.get(i));
}
search(list,rooms);
}

public static void search(ArrayList>> list, ArrayList rooms){
Scanner scanner = new Scanner(System.in);
int number = scanner.nextInt();
for (int i = 0; i < list.get(number-1).get(rooms.get(number-1)).size(); i++) {
System.out.println(list.get(number-1).get(rooms.get(number-1)).get(i));
}
System.out.println("\tOrqaga qaytish uchun 0 ni kiriting");
System.out.println("\tDasturdan chiqish uchun boshqa sonni kiriting");
switch (scanner.nextInt()){
case 0: homeMenu(list, rooms);break;
default:
System.out.println("Dasturdan foydalanganligingiz uchun rahmat");
}
}
}

Output:


Xonalar sonini kiriting : 3

1 - xona nomerini kiriting : 201

201 - xona talabalari sonini kiriting : 3

1 - talaba familiyasini kiriting : Sheronov

2 - talaba familiyasini kiriting : Hoshimjonov

3 - talaba familiyasini kiriting : Hamroqulov

2 - xona nomerini kiriting : 202

202 - xona talabalari sonini kiriting : 3

1 - talaba familiyasini kiriting : Tursunboyev

2 - talaba familiyasini kiriting : Ergashov

3 - talaba familiyasini kiriting : Gulmamatov

3 - xona nomerini kiriting : 203

203 - xona talabalari sonini kiriting : 4

1 - talaba familiyasini kiriting : Zulfuqorov

2 - talaba familiyasini kiriting : Mavlonov

3 - talaba familiyasini kiriting : Alimov

4 - talaba familiyasini kiriting : Sobirov

TATU KIF Fakulteti yotoxonasidan talabalarni qidirish dasturiga xush kelibsiz!

Qanday ma'lumotni qidirmoqchisiz?

1. Xona raqami orqali talabalarni qidirish

1

Qaysi xonadan talabalarni qidirmoqchisiz :



1. 201

2. 202


3. 203

1

Sheronov



Hoshimjonov

Hamroqulov

Orqaga qaytish uchun 0 ni kiriting

Dasturdan chiqish uchun boshqa sonni kiriting

0

Qaysi xonadan talabalarni qidirmoqchisiz :



1. 201

2. 202


3. 203

2

Tursunboyev



Ergashov

Gulmamatov

Orqaga qaytish uchun 0 ni kiriting

Dasturdan chiqish uchun boshqa sonni kiriting

0

Qaysi xonadan talabalarni qidirmoqchisiz :



1. 201

2. 202


3. 203

3

Zulfuqorov



Mavlonov

Alimov


Sobirov

Orqaga qaytish uchun 0 ni kiriting

Dasturdan chiqish uchun boshqa sonni kiriting

7

Dasturdan foydalanganligingiz uchun rahmat



Process finished with exit code 0

Download 21.37 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling