Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hey we can also do this question Like this: #18

Open
sksharma4u opened this issue Feb 4, 2023 · 3 comments
Open

Hey we can also do this question Like this: #18

sksharma4u opened this issue Feb 4, 2023 · 3 comments
Assignees

Comments

@sksharma4u
Copy link

import java.util.*;
public class Main
{

public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
Phone[] obj = new Phone[4];
for(int i=0 ;i<4 ; i++){
obj[i] = new Phone(sc.nextInt() , sc.next() , sc.next(), sc.nextInt());
}
String brand = sc.next();
String os = sc.next();

int value = findPriceForGivenBrand(obj , brand);

if(value > 0){
    System.out.println(value);
}else{
    System.out.println("The given Brand is not available");
}

Phone[] ans = getPhoneIdBasedOnOs(obj , os);
if(ans.length==0){
    System.out.println("No phones are available with specified os and price range");
}else{
    for(int i=0 ; i<ans.length ; i++){
        System.out.println(ans[i].getid());
    }
}

}

public static int findPriceForGivenBrand(Phone[] phone, String brand)
{
int sum =0 ;

for(int i=0 ; i<phone.length; i++){
    if(phone[i].getbrand().equalsIgnoreCase(brand)){
        sum+=phone[i].getprice();
    }
}
return sum;

}

public static Phone[] getPhoneIdBasedOnOs(Phone[] phone, String os)
{
int length =0;
int j =0;
Phone[] obj2 = new Phone[length];
for(int i=0 ; i<phone.length ; i++){
if(phone[i].getos().equalsIgnoreCase(os) && phone[i].getprice()>=50000){
obj2 = new Phone[length+1];
obj2[j] = phone[i];
j++;
}
}
return obj2;
}
}

class Phone
{
int id;
String os ;
String brand;
int price;

public int getid(){
return id;
}

public String getos(){
return os;
}

public String getbrand(){
return brand;
}

public int getprice(){
return price;
}

Phone(int id , String os , String brand , int price){
this.id = id;
this.os = os;
this.brand = brand;
this.price = price;
}
}

@sksharma4u
Copy link
Author

I think it's easy to understand and feasible to write

@Abhijit06
Copy link

import java.util.*; public class Main {

public static void main(String[] args) { Scanner sc = new Scanner(System.in); Phone[] obj = new Phone[4]; for(int i=0 ;i<4 ; i++){ obj[i] = new Phone(sc.nextInt() , sc.next() , sc.next(), sc.nextInt()); } String brand = sc.next(); String os = sc.next();

int value = findPriceForGivenBrand(obj , brand);

if(value > 0){
    System.out.println(value);
}else{
    System.out.println("The given Brand is not available");
}

Phone[] ans = getPhoneIdBasedOnOs(obj , os);
if(ans.length==0){
    System.out.println("No phones are available with specified os and price range");
}else{
    for(int i=0 ; i<ans.length ; i++){
        System.out.println(ans[i].getid());
    }
}

}

public static int findPriceForGivenBrand(Phone[] phone, String brand) { int sum =0 ;

for(int i=0 ; i<phone.length; i++){
    if(phone[i].getbrand().equalsIgnoreCase(brand)){
        sum+=phone[i].getprice();
    }
}
return sum;

}

public static Phone[] getPhoneIdBasedOnOs(Phone[] phone, String os) { int length =0; int j =0; Phone[] obj2 = new Phone[length]; for(int i=0 ; i<phone.length ; i++){ if(phone[i].getos().equalsIgnoreCase(os) && phone[i].getprice()>=50000){ obj2 = new Phone[length+1]; obj2[j] = phone[i]; j++; } } return obj2; } }

class Phone { int id; String os ; String brand; int price;

public int getid(){ return id; }

public String getos(){ return os; }

public String getbrand(){ return brand; }

public int getprice(){ return price; }

Phone(int id , String os , String brand , int price){ this.id = id; this.os = os; this.brand = brand; this.price = price; } }

Thanku Sir, it was helpful for me and easy to understand.

@venkivijay
Copy link
Owner

@sksharma4u Please feel free to raise a PR for this. Checkout the contributing guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants