Question: How do i make a list that sorts them by make model and year while giving them appropriate space? Current code i have: import java.io

How do i make a list that sorts them by make model and year while giving them appropriate space?
Current code i have:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class DisplayCars {
public static void main(String[] args){
String filename = "cars.txt";
try {
BufferedReader reader = new BufferedReader(new FileReader(filename));
String line;
// Skip the header line
reader.readLine();
while ((line = reader.readLine())!= null){
// Split the line by tab character
String[] carProperties = line.split("\t");
// Check if the array has at least three elements
if (carProperties.length >=3){
// Extracting car properties
String make = carProperties[0];
String model = carProperties[1];
String year = carProperties[2];
// Displaying the formatted output
System.out.printf("%15s%25s%5s%n", make, model, year);
} else {
System.out.println("
: "+ line);
}
}
reader.close();
} catch (IOException e){
e.printStackTrace();
}
}
}
How do i make a list that sorts them by make

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!