added micro lab

This commit is contained in:
Louis Heredero 2024-10-04 13:26:49 +02:00
parent c4ebc182aa
commit 075524c606
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
3 changed files with 110 additions and 0 deletions

View 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}));
}
}

View 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);
}
}

View 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());
}
}