Dasturlash uslublari va paradigmalar


Download 49.89 Kb.
Sana06.11.2020
Hajmi49.89 Kb.
#141499
Bog'liq
3-topshiriq


314-18 guruh talabasi Ma’rupov Bahodirjonning “Dasturlash uslublari va paradigmalar” fanidan bajargan 3-topshirig’i

16-variant



  1. To’rt o'zgaruvchiga ega bo'lgan sinf yarating. Displey funktsiyasini va ushbu o'zgaruvchilarni o'zgartirish funksiyasini qo'shing. Ushbu o'zgaruvchilar qiymatlari yig'indisini topadigan va shu to’rt o'zgaruvchining eng katta qiymatini topadigan funksiyani qo'shing.

Java dasturlash tilida dastur ko’di

import java.util.Random;


import java.util.Scanner;

public class Task1 {


int var1;
int var2;
int var3;
int var4;

public Task1() {


System.out.print("O'zgaruvchilarning qiymatlarini kiriting \n1: ");
Scanner scanner=new Scanner(System.in);
var1=scanner.nextInt();
System.out.print("2: ");
var2=scanner.nextInt();
System.out.print("3: ");
var3=scanner.nextInt();
System.out.print("4: ");
var4=scanner.nextInt();
}

public void setVar1(int var1) {


this.var1 = var1;
}

public void setVar2(int var2) {


this.var2 = var2;
}

public void setVar3(int var3) {


this.var3 = var3;
}

public void setVar4(int var4) {


this.var4 = var4;
}

public String display() {


return "Task1{" +
"var1=" + var1 +
", var2=" + var2 +
", var3=" + var3 +
", var4=" + var4 +
'}';
}

public int getSum(){


return var1+var2+var3+var4;
}

public int getMax(){


return Math.max(Math.max(var1,var2),Math.max(var3,var4));
}
}

class Main{


public static void main(String[] args) {
Random random=new Random();
Task1 task1=new Task1();
System.out.println(task1.display());
System.out.println("Max: "+task1.getMax());
System.out.println("Sum: "+task1.getSum());
task1.setVar1(random.nextInt(20));
task1.setVar2(random.nextInt(20));
task1.setVar3(random.nextInt(20));
task1.setVar4(random.nextInt(20));
System.out.println(task1.display());
}
}

Natija



  1. Belgilangan diapazonda qiymatini bittaga oshirishi yoki kamaytirishi mumkin bo'lgan o'nli hisoblagichni amalga oshiradigan sinfni tavsiflang. Standart qiymatlar va ixtiyoriy qiymatlar bilan hisoblagichni ishga tushirishni ta'minlang. Hisoblagich ikkita usulga ega bo’lishi kerak:

Java dasturlash tilida dastur ko’di

import java.util.Random;

public class Task2 {
public int var;

public Task2() {


Random random=new Random();
var=random.nextInt(40);
}

public Task2(int var) {


this.var = var;
}

public int getValue(){


return var;
}

public void increaseValue(){


var++;
}
public void decreaseValue(){
var--;
}
}

class Main2{


public static void main(String[] args) {
Task2 task2=new Task2();
System.out.println("Initial value: "+task2.getValue());
task2.increaseValue();
System.out.println("After increasing value: "+task2.getValue());
task2.decreaseValue();
task2.decreaseValue();
task2.decreaseValue();
System.out.println("After decreasing value 3 times: "+task2.getValue());
}
}

Natija


Download 49.89 Kb.

Do'stlaringiz bilan baham:




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