[text] qwe

Viewer

  1. package project;
  2.  
  3. public class CarsDemo {
  4.  
  5.         public static void main(String[] args) 
  6.         {
  7.                 // TODO Auto-generated method stub
  8.                 Car[] cars = new Car[5];
  9.                 cars[0] = new Car(1,"Ferrari","Sports",250000);
  10.                 cars[1] = new Car(2,"benz","Luxury",400000);
  11.                 cars[2] = new Car(3,"Audi","Luxury",350000);
  12.                 cars[3] = new Car(4,"Ford","Sports",200000);
  13.                 cars[4] = new Car(5,"BMW","Luxury",450000);
  14.                 CarsDemo c = new CarsDemo();
  15.                 Car[] findList = FetchLuxuryCars(cars,"luxury");
  16.                 for(Car find :findList)
  17.                 {
  18.                         System.out.println(find.getCarModel()+" "+find.getCarName()+" "+find.getCarId()+" "+find.getCarPrice());
  19.                 }
  20.                
  21.                
  22.                 System.out.println(Findcars(cars, 400000));
  23.                
  24.                
  25.  
  26.         }
  27.  
  28.         private static int Findcars(Car[] cars, int i) 
  29.         {
  30.                 // TODO Auto-generated method stub
  31.                 int count = 0;
  32.                 for(int k=0;k<cars.length;k++)
  33.                 { 
  34.                         if(cars[k].getCarPrice()<i)
  35.                         {
  36.                                 count++;
  37.                         }
  38.                        
  39.                 }
  40.                 return count;
  41.         }
  42.                
  43.  
  44.         private static Car[] FetchLuxuryCars(Car[] cars, String string) {
  45.                 // TODO Auto-generated method stub
  46.                 int count=0;
  47.                 int j=0;
  48.                 for(int i=0;i<cars.length;i++)
  49.                 {
  50.                         if(cars[i].getCarModel().equalsIgnoreCase(string) && cars[i].getCarName().charAt(0)=='B')
  51.                         {
  52.                                 count++;
  53.                         }
  54.                 }
  55.                 Car[] c = new Car[count];
  56.                 for(int i=0;i<cars.length;i++)
  57.                 {
  58.                        
  59.                         if(cars[i].getCarModel().equalsIgnoreCase(string) && cars[i].getCarName().charAt(0)=='B')
  60.                         {
  61.                                 c[j]=cars[i];
  62.                                 j++;
  63.                         }
  64.                 }
  65.                 return c;
  66.                
  67.         }
  68.  
  69.        
  70.        
  71.         }
  72.  
  73. package project;
  74.  
  75. public class Car {
  76.         private int carId;
  77.         private String carName;
  78.         private String carModel;
  79.         private int carPrice;
  80.         public Car(int carId, String carName, String carModel, int carPrice) {
  81.                 super();
  82.                 this.carId = carId;
  83.                 this.carName = carName;
  84.                 this.carModel = carModel;
  85.                 this.carPrice = carPrice;
  86.         }
  87.         public int getCarId() {
  88.                 return carId;
  89.         }
  90.         public void setCarId(int carId) {
  91.                 this.carId = carId;
  92.         }
  93.         public String getCarName() {
  94.                 return carName;
  95.         }
  96.         public void setCarName(String carName) {
  97.                 this.carName = carName;
  98.         }
  99.         public String getCarModel() {
  100.                 return carModel;
  101.         }
  102.         public void setCarModel(String carModel) {
  103.                 this.carModel = carModel;
  104.         }
  105.         public int getCarPrice() {
  106.                 return carPrice;
  107.         }
  108.         public void setCarPrice(int carPrice) {
  109.                 this.carPrice = carPrice;
  110.         }
  111.        
  112. }

Editor

You can edit this paste and save as new:


File Description
  • qwe
  • Paste Code
  • 16 Sep-2019
  • 2.28 Kb
You can Share it: