You are on page 1of 2

public class Solution {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
Car c[]=new Car[4];
for(int i=0;i<4;i++) {
String regNo=sc.nextLine();
double price=sc.nextDouble();
sc.nextLine();
boolean isACCar=sc.nextBoolean();
sc.nextLine();
String company=sc.nextLine();
c[i]=new Car(regNo,price,isACCar,company);

}
String regNo=sc.nextLine();
Car temp=getCar(c,regNo);
int count=getACCarCount(c);
if(temp!=null) {
System.out.println(temp.getPrice());
}
else {
System.out.println("Car RegNo not found");
}

System.out.println(count);
}
public static Car getCar(Car[] carList, String carRegNo)
{
//method logic
Car t=null;
for(int i=0;i<4;i++) {
if(carList[i].getRegNo().equalsIgnoreCase(carRegNo)) {
t=carList[i];
}
}
return t;
}
public static int getACCarCount(Car[] carList)
{
int count=0;
for(int i=0;i<4;i++) {
if(carList[i].isACCar()) {
count++;
}
}
return count;
}

}
class Car
{
private String regNo;
private double price;
private boolean isACCar;
private String company;
public String getRegNo() {
return regNo;
}
public void setRegNo(String regNo) {
this.regNo = regNo;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public boolean isACCar() {
return isACCar;
}
public void setACCar(boolean isACCar) {
this.isACCar = isACCar;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public Car(String regNo, double price, boolean isACCar, String company) {
super();
this.regNo = regNo;
this.price = price;
this.isACCar = isACCar;
this.company = company;
}

You might also like