import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Scanner;
public class Solution {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
List<Mobile> list = new ArrayList<>();
for(int i=0;i<4;i++){
String mobileId = sc.nextLine();
String modelName = sc.nextLine();
String price = sc.nextLine();
String brand = sc.nextLine();
Mobile mobile = new Mobile(Integer.parseInt(mobileId),Integer.parseInt(price),modelName,brand);
mobile.setMobileId(Integer.parseInt(mobileId));
mobile.setPrice(Integer.parseInt(price));
mobile.setModelName(modelName);
mobile.setBrand(brand);
list.add(mobile);
}
String brand = sc.nextLine();
int ans = countMobilesByBrand(list,brand);
if(ans == 0){
System.out.println("No such mobile found.");
}
else {
System.out.println(ans);
}
Mobile ans1 =getSecondHighestPricedMobile(list);
if(Objects.isNull(ans1)){
System.out.println("No such mobile found.");
}else{
System.out.println(ans1.getModelName());
System.out.println(ans1.getPrice());
System.out.println(ans1.getBrand());
}
}
public static class Mobile {
private int mobileId;
private String modelName;
private int price;
private String brand;
public Mobile(int mobileId, int price, String modelName, String brand) {
this.mobileId = mobileId;
this.price = price;
this.modelName = modelName;
this.brand = brand;
}
public int getMobileId() {
return mobileId;
}
public void setMobileId(int mobileId) {
this.mobileId = mobileId;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getModelName() {
return modelName;
}
public void setModelName(String modelName) {
this.modelName = modelName;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
}
private static int countMobilesByBrand(List<Mobile> list, String brand) {
int count = 0;
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getBrand().equals(brand))
count++;
}
return count;
}
private static Mobile getSecondHighestPricedMobile(List<Mobile>list){
int max = -1;
int ans =-1;
for (int i = 0; i < list.size(); i++) {
if(list.get(i).getPrice()%2 ==0)
continue;
if(max == -1) {
max = list.get(i).getPrice();
continue;
}
int value = list.get(i).getPrice();
if(value > max){
ans = max;
max = value;
continue;
}
if(value>ans){
ans = value;
}
}
if(ans == -1)
return null;
for(int i = 0; i < list.size(); i++){
if(ans == list.get(i).getPrice())
return list.get(i);
}
return null;
}
}
Mobile. Code java
Telegram :- https://t.me/Allcodingsolution
import java.util.List;
import java.util.Objects;
import java.util.Scanner;
public class Solution {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
List<Mobile> list = new ArrayList<>();
for(int i=0;i<4;i++){
String mobileId = sc.nextLine();
String modelName = sc.nextLine();
String price = sc.nextLine();
String brand = sc.nextLine();
Mobile mobile = new Mobile(Integer.parseInt(mobileId),Integer.parseInt(price),modelName,brand);
mobile.setMobileId(Integer.parseInt(mobileId));
mobile.setPrice(Integer.parseInt(price));
mobile.setModelName(modelName);
mobile.setBrand(brand);
list.add(mobile);
}
String brand = sc.nextLine();
int ans = countMobilesByBrand(list,brand);
if(ans == 0){
System.out.println("No such mobile found.");
}
else {
System.out.println(ans);
}
Mobile ans1 =getSecondHighestPricedMobile(list);
if(Objects.isNull(ans1)){
System.out.println("No such mobile found.");
}else{
System.out.println(ans1.getModelName());
System.out.println(ans1.getPrice());
System.out.println(ans1.getBrand());
}
}
public static class Mobile {
private int mobileId;
private String modelName;
private int price;
private String brand;
public Mobile(int mobileId, int price, String modelName, String brand) {
this.mobileId = mobileId;
this.price = price;
this.modelName = modelName;
this.brand = brand;
}
public int getMobileId() {
return mobileId;
}
public void setMobileId(int mobileId) {
this.mobileId = mobileId;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getModelName() {
return modelName;
}
public void setModelName(String modelName) {
this.modelName = modelName;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
}
private static int countMobilesByBrand(List<Mobile> list, String brand) {
int count = 0;
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getBrand().equals(brand))
count++;
}
return count;
}
private static Mobile getSecondHighestPricedMobile(List<Mobile>list){
int max = -1;
int ans =-1;
for (int i = 0; i < list.size(); i++) {
if(list.get(i).getPrice()%2 ==0)
continue;
if(max == -1) {
max = list.get(i).getPrice();
continue;
}
int value = list.get(i).getPrice();
if(value > max){
ans = max;
max = value;
continue;
}
if(value>ans){
ans = value;
}
}
if(ans == -1)
return null;
for(int i = 0; i < list.size(); i++){
if(ans == list.get(i).getPrice())
return list.get(i);
}
return null;
}
}
Mobile. Code java
Telegram :- https://t.me/Allcodingsolution
👍1
Infytq
Maximu of 4 unique upper case alphabets
💯% test cases passed
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
Maximu of 4 unique upper case alphabets
💯% test cases passed
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
👍1
Infytq
Maximu of 4 unique upper case alphabets
💯% test cases passed
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
Maximu of 4 unique upper case alphabets
💯% test cases passed
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
INFYTQ
Helath is wealth Code
Phyton 3 ✅✅
💯% test cases passed
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
Helath is wealth Code
Phyton 3 ✅✅
💯% test cases passed
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
Guys I have sended the code that are working and passed
If it is not passing to you you can done mistakes please check the code again
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
If it is not passing to you you can done mistakes please check the code again
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
INFYTQ M×N Matrix Code
💯% all test cases passed
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
💯% all test cases passed
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
Smallest character python3 code Accenture exam all testcases passed code i given
Accenture exam
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
Accenture exam
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution
@Allcodingsolution