Fozilbek Kenjaboy O'gʻli


Download 94.5 Kb.
Sana29.04.2023
Hajmi94.5 Kb.
#1401113
Bog'liq
Amalyot-1 Karimov Fozilbek


Toshkent Axborot texnologiyalari Universiteti Urganch Filiali Kampyuter Injinering fakulteti 961-21- guruh talabasi Karimov
Fozilbek Kenjaboy O'gʻli
Bu class umumiy maydonlarga ega class 
package Amalyot01; 

public class Maydonlar { 


protected int id; 
protected String name
protected int razmer
protected int year

public Maydonlar(int id, String name, int razmer, int year) { 


this.id = id; 
this.name = name; 
this.razmer = razmer; 
this.year = year; 

public int getId() { 


return id; 

public void setId(int id) { 


this.id = id; 

public String getName() { 


return name; 

public void setName(String name) { 


this.name = name; 

public int getRazmer() { 


return razmer; 

public void setRazmer(int razmer) { 


this.razmer = razmer; 

public int getYear() { 


return year; 

public void setYear(int year) { 


this.year = year; 

@Override 


public String toString() { 
return "Maydonlar{" + 
"id=" + id + 
", name='" + name + '\'' + 
", razmer=" + razmer + 
", year=" + year + 
'}'; 

__________________________________________________________ Bu class manitor deb atadim bu class da asosiy xarakatlarni bajaruvchi metodlar yoziladi. 


package Amalyot01; 

import java.util.Scanner; 

public class Manitor { 

static void qoshish(Maydonlar[] k) { 


Scanner sc = new Scanner(System.in); 
int id = 0; 
for (int i = 0; i < k.length; i++) { 
System.out.print("Nomini kiriting:"); 
String name = sc.next(); 
System.out.print("Razmerini kiriting"); 
int razmer = sc.nextInt(); 
System.out.print("Yilini kiriting"); 
int year = sc.nextInt(); 
Maydonlar m = new Maydonlar(id, name, razmer, year); 
k[i] = m; 
id++; 

static void barchaRoyxat(Maydonlar[] k) { 


for (int i = 0; i < k.length; i++) { 
System.out.println(k[i]); 

static void qidirish(Maydonlar[] k, String name) { 


for (int i = 0; i < k.length; i++) { 
if (k[i].getName().equals(name)) { 
System.out.println(k[i]); 


static void saralash(Maydonlar[] k) { 


int id; 
for (int i = 0; i < k.length; i++) { 
for (int j = i + 1; j < k.length; j++) { 
if (k[i].razmer > k[j].razmer) { 
id = k[i].razmer; 
k[i].razmer = k[j].razmer; 
k[j].razmer = id; 




void ozgartirish (Maydonlar[]k,int id){ 
Scanner sc =new Scanner(System.in); 
for (int i = 0; i < k.length; i++) { 
if (k[i].getId() == id) { 
System.out.println("Tanlang"); 
System.out.println("1-> Nomi\n2-> Razmeri\n3-> Yili"); 
int n = sc.nextInt(); 
switch (n){ 
case 1: 
System.out.print("Nomini o'zgartiring: "); 
String name = sc.next(); 
k[i].setName(name); 
break; 
case 2: 
System.out.print("Razmerini o'zgartiring: "); 
int razmer = sc.nextInt(); 
k[i].setRazmer(razmer); 
break; 
case 3: 
System.out.print("Yilini o'zgartiring: "); 
int year = sc.nextInt(); 
k[i].setYear(year); 
break; 
default: 
System.out.println("Xato tanlandi"); 





__________________________________________________________Bu cllas Videkarta classi u faqat Manitor classdan meros oladi. 


package Amalyot01; 

public class Videokarta extends Manitor{ 


_________________________________________________________ 
Bu class asosiy clas bolib bu yerda codimini ishlatamiz. 
package Amalyot01; 

import java.util.Scanner; 



public class Main { 
public static void main(String[] args) { 
Scanner sc = new Scanner(System.in); 
boolean b = true; 
while (b) { 
System.out.println("Nima haqida malumot kiritmoqchisiz\n1-> kamputer manitori\n2-> Video kartasi"); 
int m = sc.nextInt(); 
switch (m) { 
case 1: 
System.out.print("Nechta manitor haqida malumot kiritmoqchisiz:"); 
int n = sc.nextInt(); 
Maydonlar[] m1 = new Maydonlar[n]; 
Manitor.qoshish(m1); 
Manitor.barchaRoyxat(m1); 
System.out.println("saralashdan keyingi royxat"); 
Manitor.saralash(m1); 
Manitor.barchaRoyxat(m1); 
System.out.print("qidirish uchun nomini kiriting: "); 
String name = sc.next(); 
Manitor.qidirish(m1, name); 
Manitor m3 = new Manitor(); 
System.out.println("O'zgartirish \"id\" ni tanlang"); 
Manitor.barchaRoyxat(m1); 
int id = sc.nextInt(); 
m3.ozgartirish(m1,id); 
Manitor.barchaRoyxat(m1); 
break; 
case 2: 
System.out.print("Nechta Vide karta haqida malumot kiritmoqchisiz:"); 
int a = sc.nextInt(); 
Maydonlar[] m2 = new Maydonlar[a]; 
Videokarta.qoshish(m2); 
Videokarta.barchaRoyxat(m2); 
System.out.println("saralashdan keyingi royxat"); 
Videokarta.saralash(m2); 
Videokarta.barchaRoyxat(m2); 
System.out.print("qidirish uchun nomini kiriting: "); 
String name1 = sc.next(); 
Videokarta.qidirish(m2, name1); 
Videokarta v = new Videokarta(); 
System.out.println("O'zgartirish \"id\" ni tanlang"); 
int id1 = sc.nextInt(); 
Videokarta.barchaRoyxat(m2); 
v.ozgartirish(m2,id1); 
Videokarta.barchaRoyxat(m2); 
break; 
default: 
System.out.println("tanlashda hatolik"); 









Download 94.5 Kb.

Do'stlaringiz bilan baham:




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