In Java. Sort the list of cars and display them. Sort by make, model, and year.   Each car property is separated by a tab character: \t Output width: 15 (make), 25 (model), 5 (year) I already have a code but it doesn't sort right.  import java.util.*; import java.io.*; class Test{ public static void main(String args[]) { try{ File file=new File("cars.txt"); Scanner sc=new Scanner(file); sc.nextLine(); while(sc.hasNext()) { String line=sc.nextLine(); String data[]=line.split("\t"); String make=data[0]; String model=data[1]; String year=data[2]; System.out.printf("%15s%25s%5s\n",make,model,year); } } catch(Exception e) { System.out.println(e); } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In Java. Sort the list of cars and display them. Sort by make, model, and year.  

Each car property is separated by a tab character: \t

Output width: 15 (make), 25 (model), 5 (year)

I already have a code but it doesn't sort right.

 import java.util.*;
import java.io.*;

class Test{
public static void main(String args[])
{
try{

File file=new File("cars.txt");

Scanner sc=new Scanner(file);

sc.nextLine();
while(sc.hasNext())
{

String line=sc.nextLine();

String data[]=line.split("\t");

String make=data[0];
String model=data[1];
String year=data[2];


System.out.printf("%15s%25s%5s\n",make,model,year);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}

//////////////////

cars.txt

make model year
Ford Expedition 2003
Mazda B-Series 1989
Ford Freestar 2003
Hyundai Elantra 2001
Hyundai Entourage 2008
Chevrolet Camaro 2011
Chevrolet Monte Carlo 2006
Chevrolet Blazer 1996
Chevrolet Aveo 2005
Chevrolet Corvette 1999
Mercedes-Benz E-Class 2006
Dodge Avenger 1995
Pontiac Grand Prix 1973
Mitsubishi Outlander 2011
MINI Clubman 2011
Suzuki Aerio 2007
Dodge Dakota Club 1992
Chevrolet Astro 2002
Chevrolet Tahoe 1996
Mitsubishi Mirage 1994
Porsche 944 1991
Hyundai Elantra 1994
Mercury Grand Marquis 1998
Volkswagen Golf 2001
Jaguar XJ Series 2005
Toyota Echo 2005
GMC Safari 2002
GMC Sierra 1500 2000
Chevrolet Cobalt 2005
Jeep Patriot 2008
Mazda Navajo 1991
Chevrolet Malibu 2001
Saab 900 1990
Mercury Grand Marquis 1998
Hummer H1 2004
Subaru Loyale 1993
Jeep Wrangler 1999
Ford Mustang 1994
Austin Mini Cooper S 1963
Mercedes-Benz M-Class 1998
Jeep Wrangler 2006
Honda Civic 1997
Plymouth Voyager 1994
Ford Club Wagon 1997
Audi 5000S 1984
Saturn VUE 2003
Oldsmobile Achieva 1994
Mercedes-Benz G55 AMG 2006
Chevrolet Express 3500 1997
Lexus ES 1992
Cadillac Allante 1992
Hyundai Tiburon 1997
Pontiac Grand Prix 1965
Ford Focus 2000
Mitsubishi Chariot 1987
Chrysler Prowler 2001
Land Rover Discovery 2012
Volkswagen Scirocco 1984
Ford Bronco 1984
Hyundai Accent 1996
Volkswagen Routan 2012
Volkswagen Golf 2003
GMC Terrain 2010
Ford F150 2009
GMC Sierra 2011
Dodge Ram Van 1500 2000
Chrysler 300 2009
Oldsmobile Achieva 1997
Land Rover Discovery 2008
Toyota 4Runner 2002
Porsche 911 1995
Toyota Land Cruiser 2002
Land Rover Defender 1994
Chevrolet Lumina 1997
Audi TT 2002
Chrysler Town & Country 2009
Nissan Frontier 2000
Toyota Tercel 1997
Buick Riviera 1997

 

Required output:

 

Sort the list of cars and display them. Sort by make, model, and year.
Test Case 1
Audi
50005 1984\n
Audi
TT 2002 \n
Mini Cooper S 1963 \n
Riviera 1997 \n
Allante 1992 \n
Austin
Buick
Cadillac
Chevrolet
Astro 2002 \n
Chevrolet
Aveo 2005 \n
Chevrolet
Blazer 1996 \n
Chevrolet
Camaro 2011 \n
Chevrolet
Cobalt 2005 \n
Chevrolet
Corvette 1999 \n
Express 3500 1997 \n
Lumina 1997 \n
Chevrolet
Chevrolet
Chevrolet
Malibu 2001 \n
Monte Carlo 2006 \n
Tahoe 1996 \n
Chevrolet
Chevrolet
Chrysler
300 2009 \n
Prowler 2001 \n
Town & Country 2009 \n
Chrysler
Chrysler
Dodge
Avenger 1995 \n
Dodge
Dakota Club 1992 \n
Dodge
Ram Van 1500 2000 \n
Ford
Bronco 1984 \n
Ford
Club Wagon 1997 \n
Ford
Expedition 2003 \n
Ford
F150 2009 \n
Ford
Focus 2000 \n
Ford
Freestar 2003 \n
Ford
Mustang 1994 \n
GMC
Safari 2002 \n
GMC
Sierra 2011|\n
GMC
Sierra 1500 2000 \n
GMC
Terrain 2010 \n
Honda
Civic 1997 \n
Hummer
H1 2004 \n
Hyundai
Accent 1996 \n
Elantra 1994 \n
Hyundai
Hyundai
Elantra 2001 \n
Entourage 2008 \n
Tiburon 1997 \n
Hyundai
Hyundai
Jaguar
XJ Series 2005 \n
Jeep
Patriot 2008 \n
Jeep
Wrangler 1999 \n
Transcribed Image Text:Sort the list of cars and display them. Sort by make, model, and year. Test Case 1 Audi 50005 1984\n Audi TT 2002 \n Mini Cooper S 1963 \n Riviera 1997 \n Allante 1992 \n Austin Buick Cadillac Chevrolet Astro 2002 \n Chevrolet Aveo 2005 \n Chevrolet Blazer 1996 \n Chevrolet Camaro 2011 \n Chevrolet Cobalt 2005 \n Chevrolet Corvette 1999 \n Express 3500 1997 \n Lumina 1997 \n Chevrolet Chevrolet Chevrolet Malibu 2001 \n Monte Carlo 2006 \n Tahoe 1996 \n Chevrolet Chevrolet Chrysler 300 2009 \n Prowler 2001 \n Town & Country 2009 \n Chrysler Chrysler Dodge Avenger 1995 \n Dodge Dakota Club 1992 \n Dodge Ram Van 1500 2000 \n Ford Bronco 1984 \n Ford Club Wagon 1997 \n Ford Expedition 2003 \n Ford F150 2009 \n Ford Focus 2000 \n Ford Freestar 2003 \n Ford Mustang 1994 \n GMC Safari 2002 \n GMC Sierra 2011|\n GMC Sierra 1500 2000 \n GMC Terrain 2010 \n Honda Civic 1997 \n Hummer H1 2004 \n Hyundai Accent 1996 \n Elantra 1994 \n Hyundai Hyundai Elantra 2001 \n Entourage 2008 \n Tiburon 1997 \n Hyundai Hyundai Jaguar XJ Series 2005 \n Jeep Patriot 2008 \n Jeep Wrangler 1999 \n
Jeep
Wrangler 1999 n
Wrangler 2006 \n
Defender 1994 \n
Jeep
Land Rover
Discovery 2008 in
Discovery 2012 \n
Land Rover
Land Rover
Lexus
ES 1992 \n
B-Series 1989 \n
Navajo 1991 \n
E-Class 2006 \n
Mazda
Mazda
Mercedes-Benz
Mercedes-Benz
G55 AMG 2006 \n
Mercedes-Benz
M-Class 1998 \n
Mercury
Grand Marquis 1998 \n|
Grand Marquis 1998 \n
Clubman 2011 \n
Chariot 1987 \n
Mercury
MINI
Mitsubishi
Mirage 1994 \n
Outlander 2011 \n
Mitsubishi
Mitsubishi
Nissan
Frontier 2000 \n
Achieva 1994 \n
Achieva 1997 \n
Oldsmobile
Oldsmobile
Voyager 1994 \n
Grand Prix 1965 \n
Plymouth
Pontiac
Pontiac
Grand Prix 1973 \n
Porsche
911 1995|\n
Porsche
944 1991|\n
Saab
900 1990 \n
Saturn
VUE 2003 \n
Loyale 1993 \n
Aerio 2007\n
Subaru
Suzuki
Toyota
4Runner 2002 \n
Toyota
Echo 2005 \n
Тoyota
Land Cruiser 2002 \n
Toyota
Tercel 1997 \n
Volkswagen
Golf 2001 \n
Volkswagen
Golf 2003 \n
Volkswagen
Routan 2012 \n
Scirocco 1984 \n
Volkswagen
Transcribed Image Text:Jeep Wrangler 1999 n Wrangler 2006 \n Defender 1994 \n Jeep Land Rover Discovery 2008 in Discovery 2012 \n Land Rover Land Rover Lexus ES 1992 \n B-Series 1989 \n Navajo 1991 \n E-Class 2006 \n Mazda Mazda Mercedes-Benz Mercedes-Benz G55 AMG 2006 \n Mercedes-Benz M-Class 1998 \n Mercury Grand Marquis 1998 \n| Grand Marquis 1998 \n Clubman 2011 \n Chariot 1987 \n Mercury MINI Mitsubishi Mirage 1994 \n Outlander 2011 \n Mitsubishi Mitsubishi Nissan Frontier 2000 \n Achieva 1994 \n Achieva 1997 \n Oldsmobile Oldsmobile Voyager 1994 \n Grand Prix 1965 \n Plymouth Pontiac Pontiac Grand Prix 1973 \n Porsche 911 1995|\n Porsche 944 1991|\n Saab 900 1990 \n Saturn VUE 2003 \n Loyale 1993 \n Aerio 2007\n Subaru Suzuki Toyota 4Runner 2002 \n Toyota Echo 2005 \n Тoyota Land Cruiser 2002 \n Toyota Tercel 1997 \n Volkswagen Golf 2001 \n Volkswagen Golf 2003 \n Volkswagen Routan 2012 \n Scirocco 1984 \n Volkswagen
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education