Algoritmlarni loyhalash fani bo’yicha 4-Labaratoriya ish Topshirdi



Download 92.5 Kb.
Sana15.05.2021
Hajmi92.5 Kb.

O’ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI

Algoritmlarni loyhalash fani bo’yicha

4-Labaratoriya ish



Topshirdi: Komilov Muhriddin


Toshkent – 2020


  1. Ixtiyoriy dasturlash tilida Priority Queue strukturaga ega bo’lgan studentlar massivi ifodalovchi dastur tuzing. Ustuvorlikni student yoshi bo’yicha ifodalang.

Student Model:
package algorithm_design.labaratoriya.lab4;

public class Student {


private String firstName;
private String lastName;
private int course;
private int age;

public Student(String firstName, String lastName, int course, int age) { this.firstName = firstName;


this.lastName = lastName;
this.course = course;
this.age = age;
}

public String getFirstName() {


return firstName;
}

public void setFirstName(String firstName) {


this.firstName = firstName;
}

public String getLastName() {


return lastName;
}

public void setLastName(String lastName) {


this.lastName = lastName;
}

public int getCourse() {


return course;
}

public void setCourse(int course) {


this.course = course;
}

public int getAge() {


return age;
}

public void setAge(int age) {


this.age = age;
}
@Override
public String toString() {
return "Student{" +
"firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", course=" + course +
", age=" + age +
'}';
}
}
Main:

package algorithm_design.labaratoriya.lab4;

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
PriorityQueue students = new
PriorityQueue<>(Comparator.comparingInt(Student::getAge));
int n = scanner.nextInt();
for (int i = 0; i < n; i++) {
System.out.print("Ism: ");
scanner = new Scanner(System.in);
String firstName = scanner.nextLine();
System.out.print("Familiyasi: ");
String lastName = scanner.nextLine();
scanner = new Scanner(System.in);
System.out.print("Kursi: ");
int course = scanner.nextInt();
System.out.print("Yoshi: ");
int age = scanner.nextInt();
Student student = new Student(firstName, lastName, course, age);
students.add(student);
System.out.println("----------------------");
}

System.out.println("Studentlar PriorityQueuega qo`shildi"); while (!students.isEmpty()) {


Student student = students.poll();

System.out.println(student.getFirstName() + " " + student.getLastName() + " - " + student.getAge());


}
}
}

Natija:



Download 92.5 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2020
ma'muriyatiga murojaat qiling

    Bosh sahifa
davlat universiteti
ta’lim vazirligi
O’zbekiston respublikasi
maxsus ta’lim
zbekiston respublikasi
axborot texnologiyalari
o’rta maxsus
davlat pedagogika
nomidagi toshkent
guruh talabasi
pedagogika instituti
texnologiyalari universiteti
toshkent axborot
xorazmiy nomidagi
rivojlantirish vazirligi
samarqand davlat
haqida tushuncha
navoiy nomidagi
toshkent davlat
nomidagi samarqand
ta’limi vazirligi
Darsning maqsadi
vazirligi toshkent
Toshkent davlat
tashkil etish
kommunikatsiyalarini rivojlantirish
Ўзбекистон республикаси
Alisher navoiy
matematika fakulteti
bilan ishlash
Nizomiy nomidagi
vazirligi muhammad
pedagogika universiteti
fanining predmeti
таълим вазирлиги
sinflar uchun
o’rta ta’lim
maxsus ta'lim
fanlar fakulteti
ta'lim vazirligi
Toshkent axborot
махсус таълим
tibbiyot akademiyasi
umumiy o’rta
pedagogika fakulteti
haqida umumiy
Referat mavzu
fizika matematika
universiteti fizika
ishlab chiqarish
Navoiy davlat