- package project;
- public class CarsDemo {
- public static void main(String[] args)
- {
- // TODO Auto-generated method stub
- Car[] cars = new Car[5];
- cars[0] = new Car(1,"Ferrari","Sports",250000);
- cars[1] = new Car(2,"benz","Luxury",400000);
- cars[2] = new Car(3,"Audi","Luxury",350000);
- cars[3] = new Car(4,"Ford","Sports",200000);
- cars[4] = new Car(5,"BMW","Luxury",450000);
- CarsDemo c = new CarsDemo();
- Car[] findList = FetchLuxuryCars(cars,"luxury");
- for(Car find :findList)
- {
- System.out.println(find.getCarModel()+" "+find.getCarName()+" "+find.getCarId()+" "+find.getCarPrice());
- }
- System.out.println(Findcars(cars, 400000));
- }
- private static int Findcars(Car[] cars, int i)
- {
- // TODO Auto-generated method stub
- int count = 0;
- for(int k=0;k<cars.length;k++)
- {
- if(cars[k].getCarPrice()<i)
- {
- count++;
- }
- }
- return count;
- }
- private static Car[] FetchLuxuryCars(Car[] cars, String string) {
- // TODO Auto-generated method stub
- int count=0;
- int j=0;
- for(int i=0;i<cars.length;i++)
- {
- if(cars[i].getCarModel().equalsIgnoreCase(string) && cars[i].getCarName().charAt(0)=='B')
- {
- count++;
- }
- }
- Car[] c = new Car[count];
- for(int i=0;i<cars.length;i++)
- {
- if(cars[i].getCarModel().equalsIgnoreCase(string) && cars[i].getCarName().charAt(0)=='B')
- {
- c[j]=cars[i];
- j++;
- }
- }
- return c;
- }
- }
- package project;
- public class Car {
- private int carId;
- private String carName;
- private String carModel;
- private int carPrice;
- public Car(int carId, String carName, String carModel, int carPrice) {
- super();
- this.carId = carId;
- this.carName = carName;
- this.carModel = carModel;
- this.carPrice = carPrice;
- }
- public int getCarId() {
- return carId;
- }
- public void setCarId(int carId) {
- this.carId = carId;
- }
- public String getCarName() {
- return carName;
- }
- public void setCarName(String carName) {
- this.carName = carName;
- }
- public String getCarModel() {
- return carModel;
- }
- public void setCarModel(String carModel) {
- this.carModel = carModel;
- }
- public int getCarPrice() {
- return carPrice;
- }
- public void setCarPrice(int carPrice) {
- this.carPrice = carPrice;
- }
- }
[text] qwe
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: