Respuesta :
Answer:
Java code is explained below
Explanation:
// Car.java
import java.util.Calendar;
public class Car {
 private String vin;
 private String make;
 private String model;
 private double cost;
 private int year;
 public Car(String vin, String make, String model, double cost, int year) {
   this.vin = vin;
   this.make = make;
   this.model = model;
   this.cost = cost;
   this.year = year;
 }
 public String getModel() {
   return model;
 }
 public double getCost() // returns car’s cost
 {
   return cost;
 }
 public String getMake() // returns car’s make
 {
   return make;
 }
 public boolean isExpensive() // returns true if car has cost above 30000 and
                 // false
 // otherwise
 {
   if (cost > 30000)
     return true;
   else
     return false;
 }
 public boolean isAntique() // returns true if car’s has above 50 years, and
               // false
 // otherwise
 {
   int cyear = Calendar.getInstance().get(Calendar.YEAR);
   if ((cyear-year) > 50)
     return true;
   else
     return false;
 }
 public String toString() // returns string with all car’s data in one line
 // separated by tabs.
 {
   return vin + "\t" + make + "\t" + model + " " + cost + "\t" + year;
 }
}
___________________________
// CarList.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class CarList {
 private ArrayList<Car> type;
 public CarList() throws FileNotFoundException {
   this.type = new ArrayList<Car>();
   Scanner sc1 = new Scanner(new File("inData.txt"));
   while (sc1.hasNextLine()) {
     String str = sc1.nextLine();
     String arr[] = str.split(" ");
     type.add(new Car(arr[0], arr[1], arr[2], Integer.parseInt(arr[3]),
         Integer.parseInt(arr[4])));
   }
   sc1.close();
 }
Â
 public void printList()
 {
   System.out.println("Displaying cars:");
   for(int i=0;i<type.size();i++)
   {
     System.out.println(type.get(i));
   }
 }
 public void printExpensiveCars()
 {
  Â
   System.out.println("List of expensive cars:");
   for(int i=0;i<type.size();i++)
   {
     if(type.get(i).isExpensive())
     {
       System.out.println(type.get(i));
     }
   }
 }
Â
 public Car cheapestCar()
 {
   int cheapIndx=0;
   double min=type.get(0).getCost();
   for(int i=0;i<type.size();i++)
   {
   if(min>type.get(i).getCost())
   {
     min=type.get(i).getCost();
     cheapIndx=i;
   }
   }
   return type.get(cheapIndx);
 }
 public int countCarsWithModel(String model)
 {
   int cnt=0;
   for(int i=0;i<type.size();i++)
   {
     if(type.get(i).getModel().equals(model))
     {
       cnt++;
     }
   }
   return cnt;
 }
Â
 public ArrayList<Car> antiqueCarList ()
 {
   ArrayList<Car> arl=new ArrayList<Car>();
   for(int i=0;i<type.size();i++)
   {
     if(type.get(i).isAntique())
     arl.add(type.get(i));
   }
   return arl;
 }
}
_________________________________
// TestCarList.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class TestCarList {
 public static void main(String[] args) throws FileNotFoundException {
   CarList cl = new CarList();
   cl.printList();
   cl.printExpensiveCars();
   ArrayList arl = cl.antiqueCarList();
   System.out.println("Displaying the AntiqueCar list:");
   for (int i = 0; i < arl.size(); i++) {
     System.out.println(arl.get(i));
   }
   System.out.println("Displaying the cheapest car :");
   System.out.println(cl.cheapestCar());
   System.out.println("No of Royal model Cars :"+ cl.countCarsWithModel("Royal"));
 }
}
____________________________
Output:
Displaying cars:
1234567CS2  Subaru  Impreza 27000.0  2017
1233219CS2  Toyota  Camry 31000.0  2010
9876543CS2  Ford  Mustang 51000.0  1968
3456789CS2  Toyota  Tercel 20000.0  2004
4567890CS2  Crysler  Royal 11000.0  1951
List of expensive cars:
1233219CS2  Toyota  Camry 31000.0  2010
9876543CS2  Ford  Mustang 51000.0  1968
Displaying the AntiqueCar list:
9876543CS2  Ford  Mustang 51000.0  1968
4567890CS2  Crysler  Royal 11000.0  1951
Displaying the cheapest car :
4567890CS2  Crysler  Royal 11000.0  1951
No of Royal model Cars :1