added micro lab
This commit is contained in:
parent
c4ebc182aa
commit
075524c606
31
src/learn/MicroLabTask1.java
Normal file
31
src/learn/MicroLabTask1.java
Normal file
@ -0,0 +1,31 @@
|
||||
package learn;
|
||||
|
||||
public class MicroLabTask1 {
|
||||
public static int countE(String[] strings) {
|
||||
int count = 0;
|
||||
for (String s : strings) {
|
||||
for (char c: s.toCharArray()) {
|
||||
if (c == 'e') {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static <T extends Comparable<T>> int findFirstOutOfPlace(T[] arr) {
|
||||
for (int i = 0; i < arr.length - 1; i++) {
|
||||
if (arr[i+1].compareTo(arr[i]) < 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(countE(new String[]{"hello", "my", "dear", "friend", "and", "enemies"}));
|
||||
System.out.println(findFirstOutOfPlace(new Integer[]{0,1,2,3}));
|
||||
System.out.println(findFirstOutOfPlace(new Integer[]{0,1,3,2}));
|
||||
}
|
||||
}
|
45
src/learn/MicroLabTask2.java
Normal file
45
src/learn/MicroLabTask2.java
Normal file
@ -0,0 +1,45 @@
|
||||
package learn;
|
||||
|
||||
class Car {
|
||||
int speed;
|
||||
String brand;
|
||||
|
||||
Car(int speed, String brand) {
|
||||
this.speed = speed;
|
||||
this.brand = brand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Car{speed=" + speed + "km/h, brand='" + brand + "'}";
|
||||
}
|
||||
}
|
||||
|
||||
class Person {
|
||||
String firstname;
|
||||
String lastname;
|
||||
int age;
|
||||
int height;
|
||||
|
||||
Person(String firstname, String lastname, int age, int height) {
|
||||
this.firstname = firstname;
|
||||
this.lastname = lastname;
|
||||
this.age = age;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
Person(String firstname) {
|
||||
this(firstname, "", 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public class MicroLabTask2 {
|
||||
public static void main(String[] args) {
|
||||
Car car1 = new Car(250, "Porsche 911");
|
||||
System.out.println(car1);
|
||||
|
||||
Person p = new Person("Homer");
|
||||
String v = p.lastname.toUpperCase();
|
||||
System.out.println(v);
|
||||
}
|
||||
}
|
34
src/learn/MicroLabTask3.java
Normal file
34
src/learn/MicroLabTask3.java
Normal file
@ -0,0 +1,34 @@
|
||||
package learn;
|
||||
|
||||
class Printer {
|
||||
private static int totalNumberOfPrinters = 0;
|
||||
private String printerName;
|
||||
|
||||
Printer(String name) {
|
||||
this.printerName = name;
|
||||
totalNumberOfPrinters++;
|
||||
}
|
||||
|
||||
public boolean setPrinterName(String printerName) {
|
||||
boolean different = !this.printerName.equals(printerName);
|
||||
this.printerName = printerName;
|
||||
return different;
|
||||
}
|
||||
|
||||
public static int getTotalNumberOfPrinters() {
|
||||
return totalNumberOfPrinters;
|
||||
}
|
||||
|
||||
private void toLowerCase() {
|
||||
this.printerName = this.printerName.toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
public class MicroLabTask3 {
|
||||
public static void main(String[] args) {
|
||||
Printer p1 = new Printer("First printer");
|
||||
Printer p2 = new Printer("Printer the Second");
|
||||
Printer p3 = new Printer("Printerus III");
|
||||
System.out.println(Printer.getTotalNumberOfPrinters());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user