import [Link].
*;
class MyClass {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
// Creating an array of 4 laptops
Laptop[] laptops = new Laptop[4];
for (int i = 0; i < 4; i++) {
// Reading the input for each laptop
int laptopId = [Link]([Link]());
String brand = [Link]();
String osType = [Link]();
double price = [Link]([Link]());
int rating = [Link]([Link]());
// Creating a Laptop object and adding it to the array
laptops[i] = new Laptop(laptopId, brand, osType, price, rating);
}
// Reading brand and OS type to search
String brandToSearch = [Link]();
String osToSearch = [Link]();
// Count laptops by brand
int count = countOfLaptopsByBrand(laptops, brandToSearch);
if (count > 0) {
[Link](count);
} else {
[Link]("The given brand is not available");
}
// Search laptops by OS type
Laptop[] laptopsByOs = searchLaptopByOsType(laptops, osToSearch);
if (laptopsByOs != null) {
for (Laptop laptop : laptopsByOs) {
[Link]([Link]()); // Print laptopId
[Link]([Link]()); // Print rating
}
} else {
[Link]("The given os is not available");
}
[Link]();
}
// Method to count laptops by brand with a rating more than 3
public static int countOfLaptopsByBrand(Laptop[] laptops, String brand) {
if (laptops == null || [Link] == 0) {
return 0;
}
int count = 0;
for (Laptop laptop : laptops) {
// Check for matching brand (case insensitive) and rating greater than
3
if ([Link]().equalsIgnoreCase(brand) && [Link]() >
3) {
count++;
}
}
return count;
}
// Method to search laptops by OS type and return them in descending order of
laptop ID
public static Laptop[] searchLaptopByOsType(Laptop[] laptops, String osType) {
if (laptops == null || [Link] == 0) {
return null;
}
List<Laptop> matchingLaptops = new ArrayList<>();
for (Laptop laptop : laptops) {
// Case insensitive matching for osType
if ([Link]().equalsIgnoreCase(osType)) {
[Link](laptop);
}
}
// If no matching laptops, return null
if ([Link]()) {
return null;
}
// Sort the matching laptops in descending order of laptopId
[Link]((l1, l2) -> [Link]([Link](),
[Link]()));
// Convert the list to an array and return it
return [Link](new Laptop[0]);
}
}
// Laptop class with attributes and getter methods
class Laptop {
private int laptopId;
private String brand;
private String osType;
private double price;
private int rating;
public Laptop(int laptopId, String brand, String osType, double price, int
rating) {
[Link] = laptopId;
[Link] = brand;
[Link] = osType;
[Link] = price;
[Link] = rating;
}
public int getLaptopId() {
return laptopId;
}
public String getBrand() {
return brand;
}
public String getOsType() {
return osType;
}
public double getPrice() {
return price;
}
public int getRating() {
return rating;
}
}