Question: IN JAVA. I need help with my code it is outputting on left in red when I need it to display what is shown on

IN JAVA. I need help with my code it is outputting on left in red when I need it to display what is shown on the right. My spacing for my output is off. Question is:
Ask the use for the name of a car maker. Display the oldest and newest car from that maker. Modify your display to include the VIN of the car.
Format the output in columns of 15,25,5, and 18. If two cars have the same year, compare based on the VIN. Text file is cars-list.txt which contains over 30,000 characters of car information. My code below:
import java.io.*;
import java.util.Scanner;
public class SortCars {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.print("What car make are you looking for?
");
String carName = sc.nextLine();
String oldestCarYear ="9999";
String oldestCarVin ="";
String newestCarYear ="0000";
String newestCarVin ="";
String newCar ="";
String oldCar ="";
File file = new File("car-list.txt");
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String st;
while ((st = br.readLine())!= null){
String[] result = st.split(",");
if (result[0].equals(carName)){
if (oldestCarYear.compareTo(result[2])>0){
oldestCarYear = result[2];
oldestCarVin = result[3];
oldCar = st;
} else if (oldestCarYear.equals(result[2]) && oldestCarVin.compareTo(result[3])>0){
oldestCarVin = result[3];
oldCar = st;
}
if (newestCarYear.compareTo(result[2])0){
newestCarYear = result[2];
newestCarVin = result[3];
newCar = st;
} else if (newestCarYear.equals(result[2]) && newestCarVin.compareTo(result[3])0){
newestCarVin = result[3];
newCar = st;
}
}
}
} catch (Exception e){
e.printStackTrace();
}
System.out.println("Oldest "+ carName);
if (oldCar !=""){
String[] carInfo = oldCar.split(",");
System.out.format("%-15s %-25s %-5s %-18s%n", carInfo[0], carInfo[1], carInfo[2], carInfo[3]);
} else {
System.out.println("No car is Available !");
}
System.out.println("Newest "+ carName);
if (newCar !=""){
String[] carInfo = newCar.split(",");
System.out.format("%-15s %-25s %-5s %-18s%n", carInfo[0], carInfo[1], carInfo[2], carInfo[3]);
} else {
System.out.println("No car is Available !");
}
}
}
IN JAVA. I need help with my code it is

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!