O‘ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI
VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVESITETI
DASTURIY INJINIRINGI FAKULTETI
Dasturlash ta`minot tizimlarini loyihalash fanidan
2-Amaliy ish
311-18-guruh talabasi
Bajardi: Javohir Abdug`apporov
1-vazifa
Yotoqxonada turadigan talabalarning yoshi bo’yicha kamayish tartibida.
public class Talaba { private String ism; private String familya; private String sharf; private int yoshi; private int jinsi; private int turar_joy;
public Talaba() {
}
public Talaba(String ism, String familya, String sharf, int yoshi, int jinsi, int turar_joy) { this.ism = ism; this.familya = familya; this.sharf = sharf; this.yoshi = yoshi; this.jinsi = jinsi;
this.turar_joy = turar_joy;
}
public int getYoshi() { return yoshi;
}
public void setYoshi(int yoshi) {
this.yoshi = yoshi;
}
public String getIsm() {
return ism;
}
public void setIsm(String ism) {
this.ism = ism;
}
public String getFamilya() {
return familya;
}
public void setFamilya(String familya) { this.familya = familya;
}
public String getSharf() {
return sharf;
}
public void setSharf(String sharf) {
this.sharf = sharf;
}
public int getJinsi() { return jinsi;
}
public void setJinsi(int jinsi) {
this.jinsi = jinsi;
}
public int getTurar_joy() { return turar_joy;
}
public void setTurar_joy(int turar_joy) {
this.turar_joy = turar_joy;
}
public String get_turarjoy(){ if (getTurar_joy() == 1){
return "yotoqxona";
} else {
return "kvartira";
} }
public String get_jinsi(){ if (getJinsi() == 1){ return "O`gil bola";
}
else return "Qiz bola";
}
public String getInfo(){
return "FISH - " + getFamilya() + " " + getIsm() + " " + getSharf() +" Yoshi " + getYoshi() + " Turar joy turi : " + get_turarjoy(); }
}
import java.util.ArrayList; import java.util.List;
public class Main {
public static void main(String[] args) { List talabas = new ArrayList<>();
// jinsi 1 - ogil bola // 2 - qiz bola
// turar joyi 1- yotoqxona // 2 - kvartira
talabas.add(new Talaba("Uchqun", "Shodmonov", "Shavkatovich", 21, 1, 1)); talabas.add(new Talaba("Sardor", "Suvonov", "Jamshid o`gli", 20, 1, 2)); talabas.add(new Talaba("Shabnam", "Shodmonova", "Shavkatovna", 21, 1, 1)); talabas.add(new Talaba("Ilyos", "Mavlonov", "Jamshidovich", 22, 1, 1)); talabas.add(new Talaba("Shavkat", "Hakimov", "Shodmonovich", 25, 1, 1)); talabas.add(new Talaba("Ibrohim", "Suvonov", "Jamshid o`gli", 18, 1, 1)); talabas.add(new Talaba("Sarvinoz", "Shodmonova", "Shavkatovna", 22, 1, 1)); talabas.add(new Talaba("Sarvar", "Mavlonov", "Jamshidovich", 22, 1, 1));
List talabas1 = new ArrayList<>();
for (int i = 0; i
if (talabas.get(i).get_turarjoy().equalsIgnoreCase("yotoqxona")){ talabas1.add(talabas.get(i));
}
}
int n = talabas1.size(); for (int i = 0; i
if (talabas1.get(j).getYoshi()
} } }
for (int i = 0; i System.out.println(talabas1.get(i).getInfo()); } }}
2-vazifa. Berilgan variantlarasosida ixtiyoriy dasturlash tilidasaralash metodini bajaring.
Merge sort massiv elementlar soni-4400
--------------------------------import java.util.ArrayList; import java.util.List; import java.util.Random;
public class Main { public static void main(String[] args) { Random random = new Random(); int []array = new int[4400];
for (int i = 0; i <4400; i++) {
array[i] = random.nextInt(4500) - 450;
}
System.out.println("Before Merge Sorting:");
for (int i = 0; i <4400; i++) { System.out.print(array[i] + " ");
if (i % 20 == 0) System.out.println();
}
mergeSort(array,4400);
System.out.println("\nAfter Merge Sorting:");
for (int i = 0; i <4400; i++) { System.out.print(array[i] + " "); if (i % 20 == 0) System.out.println();
}
}
public static void mergeSort(int[] a, int n) { if (n < 2) { return;
}
int mid = n / 2; int[] l = new int[mid]; int[] r = new int[n - mid]; for (int i = 0; i < mid; i++) { l[i] = a[i];
}
for (int i = mid; i < n; i++) { r[i - mid] = a[i];
}
mergeSort(l, mid); mergeSort(r, n - mid);
merge(a, l, r, mid, n - mid);
}
public static void merge(
int[] a, int[] l, int[] r, int left, int right) {
int i = 0, j = 0, k = 0; while (i < left && j < right) { if (l[i] <= r[j]) {
a[k++] = l[i++];
} else {
a[k++] = r[j++];
} } while (i < left) {
a[k++] = l[i++];
} while (j < right) { a[k++] = r[j++];
}
}
}
Do'stlaringiz bilan baham: |