Question

In: Computer Science

In java, ask the user for a filename. Display the oldest car for every manufacturer from...

In java, ask the user for a filename. Display the oldest car for every manufacturer from that file.

Files Given:

car-list.txt

car-list-1.txt

car-list-2.txt

car-list-3.txt

(they are too big for question)

Required Output:

Standard Input                 Files in the same directory
car-list-1.txt
  • car-list.txt
  • car-list-1.txt
  • car-list-2.txt
  • car-list-3.txt
Enter filename\n
Oldest cars by make\n
          Acura                   Legend 1989 2T1BPRHE8EC858192\n
           Audi                    80/90 1988 2GKALMEK4E6424961\n
        Bentley  Continental Flying Spur 2006 WBA3G7C5XFK430850\n
            BMW                      600 1959 1N6AA0ED2FN639969\n
        Bugatti                   Veyron 2009 SCFEBBBC5AG474636\n
          Buick                  Century 1987 2HNYD18625H455550\n
       Cadillac                  DeVille 1994 19UUA56793A243886\n
      Chevrolet                   Camaro 1968 WAUDF98E18A693314\n
       Chrysler           Town & Country 1996 1GYS4EEJ3DR377025\n
          Dodge                  Charger 1970 WBAEW53475P758543\n
          Eagle                   Vision 1995 SCFHDDAJ3AA914259\n
        Ferrari          599 GTB Fiorano 2010 2G61M5S34E9207892\n
           Ford                 Fairlane 1966 2G4WF551041378204\n
            GMC              Sonoma Club 1992 WAUBFAFL9DN784019\n
          Honda                     CR-X 1984 1FT7W2A66EE489233\n
         Hummer                       H2 2008 5N1AR2MM0FC360861\n
        Hyundai                Entourage 2008 1GYS3SKJ7FR311229\n
       Infiniti                        Q 1992 SCFEBBAK0CG532695\n
          Isuzu                    Space 1994 2T1BURHEXEC222169\n
         Jaguar                   X-Type 2006 2G4GU5GV2C9513452\n
           Jeep                 Cherokee 1995 5XYKT3A67FG750891\n
            Kia                  Spectra 2006 2C3CDYAG7EH527567\n
    Lamborghini                 Countach 1988 JTMHY7AJ1B5630207\n
     Land Rover              Range Rover 1988 5UXFE8C59AL755549\n
          Lexus                       LS 1993 WAUNF78P97A339372\n
        Lincoln              Continental 1988 WAUXL68E74A407027\n
          Lotus                    Elise 2007 5NPEB4AC8CH254031\n
       Maserati                  Biturbo 1987 1G4HF57909U685797\n
        Maybach                       57 2004 1ZVBP8AM3B5509118\n
          Mazda                      626 1984 WUARL48H69K855595\n
  Mercedes-Benz                  S-Class 1986 JN1BJ0HP2EM742216\n
        Mercury                   Cougar 1970 WBANE73577C052898\n
     Mitsubishi                  Starion 1985 WAUSF98E66A919061\n
         Morgan                   Aero 8 2007 WBA3C3G57FN486516\n
         Nissan                    Quest 2001 1D4PT4GX3BW366571\n
     Oldsmobile           Custom Cruiser 1992 WDDHF5KB6FB836573\n
          Panoz                Esperante 2006 1G6KD57Y67U241895\n
       Plymouth                  Voyager 1992 WBAWB73589P509971\n
        Pontiac                  Tempest 1965 WBAKA4C59BC513301\n
        Porsche                      911 1986 JTHBE1KS8A0650998\n
    Rolls-Royce                  Phantom 2005 WAUCFAFH6EN529880\n
           Saab                     9000 1989 WBAVA37528N742448\n
         Saturn                      VUE 2006 1FBAX2CM5FK123544\n
          Scion                       xB 2006 4T3BA3BB7CU135336\n
         Shelby                    GT350 1969 KL4CJESB0FB714062\n
     Studebaker                   Avanti 1962 1GD312CG5DF955034\n
         Subaru                    Justy 1990 KM8JT3AB2CU942198\n
         Suzuki                       SJ 1986 WAU4FAFR9AA736195\n
         Toyota                   Celica 1982 3VWF17AT4FM332454\n
     Volkswagen                     Golf 1987 WDCYC7DF8FX386498\n
          Volvo                      850 1995 1GD312CG7BF949846\n
51 result(s)\n

Test Case 2

Standard Input                 Files in the same directory
car-list-2.txt
  • car-list.txt
  • car-list-1.txt
  • car-list-2.txt
  • car-list-3.txt
Enter filename\n
Oldest cars by make\n
          Acura                  Integra 1995 WBA3B5G54EN915107\n
     Alfa Romeo                      164 1994 5GAER23758J589585\n
           Audi                    4000s 1985 JN8AF5MR9DT832857\n
        Bentley  Continental Flying Spur 2007 JN1BY0AP0AM634709\n
            BMW                      600 1959 KNADM5A36E6321537\n
        Bugatti                   Veyron 2009 SCFEBBBC5AG474636\n
          Buick                 Somerset 1985 5N1AA0NC1DN101234\n
       Cadillac                  DeVille 1994 19UUA56793A243886\n
      Chevrolet                 Corvette 1953 3GYFNGEY7BS365963\n
       Chrysler                   Cirrus 1999 1GYFC33249R710666\n
         Daewoo                    Lanos 2002 KNDMG4C79E6368226\n
          Dodge                     Omni 1978 SALGR2VF2FA732350\n
          Eagle                   Summit 1996 KNAGM4AD9D5309595\n
        Ferrari             430 Scuderia 2008 1HGCP2E70CA912895\n
           Ford                 Fairlane 1966 2G4WF551041378204\n
            Geo                    Prizm 1994 SALGS2DF9DA398353\n
            GMC         Rally Wagon 3500 1993 1N6AF0KX1EN730343\n
          Honda                  Prelude 1985 19UUA76667A337717\n
        Hyundai                 Santa Fe 2001 JTDKN3DP0C3011229\n
       Infiniti                        Q 1992 1G4HP52K444142193\n
          Isuzu                  Trooper 1997 4F2CY0C75BK199939\n
         Jaguar                   X-Type 2006 2G4GU5GV2C9513452\n
           Jeep           Grand Cherokee 2003 1GYFK43549R321965\n
            Kia                   Sephia 1995 4F2CY0C77AK663764\n
    Lamborghini                 Countach 1989 1FTSW2A51AE796515\n
     Land Rover              Range Rover 1988 5UXFE8C59AL755549\n
          Lexus                       LS 1991 1G4HF57959U054981\n
        Lincoln                 Town Car 1989 1D7RV1CT3BS523594\n
          Lotus                     Elan 1990 WBANA53575C102986\n
       Maserati             Quattroporte 1984 1G6DS5E31C0696841\n
        Maybach                       57 2003 JTJBJRBZ7F2575213\n
          Mazda                      626 1985 19UUA56663A426458\n
  Mercedes-Benz                     W201 1991 SCFFBCCD3BG450032\n
        Mercury                   Cougar 1970 WBANE73577C052898\n
           MINI                   Cooper 2002 WBAYP1C51FD265309\n
     Mitsubishi                  Starion 1985 WAUSF98E66A919061\n
         Nissan                       NX 1992 WAUDV74F98N860145\n
     Oldsmobile                 Toronado 1992 JH4DC54893S582029\n
          Panoz                Esperante 2005 WA1CMAFE4ED877109\n
        Peugeot                      207 2007 3C63DPBL8CG511366\n
       Plymouth                  Voyager 1992 WBAWB73589P509971\n
        Pontiac                  Tempest 1965 WBAKA4C59BC513301\n
        Porsche                      911 1986 JTHBE1KS8A0650998\n
    Rolls-Royce                  Phantom 2005 WAUCFAFH6EN529880\n
           Saab                     9000 1989 WBAVA37528N742448\n
         Saturn                 S-Series 2002 2T1KU4EE6DC200286\n
          Scion                       xD 2011 YV1672MC1AJ515133\n
         Shelby                    GT350 1969 KL4CJESB0FB714062\n
         Subaru                     Brat 1986 3D7TT2CT3BG995173\n
         Suzuki                       SJ 1988 1D4PU5GK6BW944265\n
         Toyota                   Celica 1982 3VWF17AT4FM332454\n
     Volkswagen                   Passat 1987 1G6DV1EP8C0229130\n
          Volvo                      C70 1998 2C3CDZBT6FH112033\n
53 result(s)\n

Test Case 3

Standard Input                 Files in the same directory
car-list-3.txt
  • car-list.txt
  • car-list-1.txt
  • car-list-2.txt
  • car-list-3.txt
Enter filename\n
Oldest cars by make\n
          Acura                   Legend 1989 2T1BPRHE8EC858192\n
   Aston Martin              DB9 Volante 2006 KNDKG3A24A7680578\n
           Audi                    80/90 1988 2GKALMEK4E6424961\n
        Bentley  Continental Flying Spur 2006 2C3CCABG2CH411828\n
            BMW                      600 1959 1N6AA0ED2FN639969\n
          Buick                  Skylark 1986 1G6AB5R31F0410780\n
       Cadillac                  DeVille 1994 19UUA56793A243886\n
      Chevrolet                  Corvair 1960 1GTN1TEH5FZ654712\n
       Chrysler                 Imperial 1926 3N1CE2CP2FL275760\n
       Citroën                       CX 1989 1N6AA0CJ6EN188987\n
          Dodge                  Charger 1970 WBAEW53475P758543\n
          Eagle                   Vision 1995 SCFHDDAJ3AA914259\n
        Ferrari          599 GTB Fiorano 2010 2G61M5S34E9207892\n
           Ford                  Mustang 1971 WAUWFAFR6DA642708\n
            Geo                    Prizm 1993 SCFEDCAD4CG747594\n
            GMC              Sonoma Club 1992 WAUBFAFL9DN784019\n
          Honda                     CR-X 1984 1FT7W2A66EE489233\n
         Hummer                       H2 2008 5N1AR2MM0FC360861\n
        Hyundai                    XG350 2002 WAUFMAFC2EN588576\n
       Infiniti                        Q 1992 SCFEBBAK0CG532695\n
          Isuzu                    Space 1994 2T1BURHEXEC222169\n
         Jaguar                   S-Type 2001 WBASN2C55DC838510\n
           Jeep                 Cherokee 1995 5XYKT3A67FG750891\n
            Kia                  Spectra 2006 2C3CDYAG7EH527567\n
    Lamborghini                 Countach 1988 JTMHY7AJ1B5630207\n
     Land Rover              Range Rover 1988 5UXFE8C59AL755549\n
          Lexus                       LS 1993 WAUNF78P97A339372\n
        Lincoln              Continental 1988 WAUXL68E74A407027\n
          Lotus                    Exige 2004 1D7RV1CT6AS741379\n
        Maybach                       57 2004 1ZVBP8AM3B5509118\n
          Mazda                      626 1984 WUARL48H69K855595\n
  Mercedes-Benz                  S-Class 1986 JN1BJ0HP2EM742216\n
        Mercury                   Cougar 1970 WBANE73577C052898\n
     Mitsubishi                   Galant 1986 5N1AT2ML1EC611331\n
         Morgan                   Aero 8 2007 WBA3C3G57FN486516\n
         Nissan                       NX 1992 WAUDV74F98N860145\n
     Oldsmobile                 Toronado 1992 JH4DC54893S582029\n
          Panoz                Esperante 2008 3D73Y4EL2AG593685\n
       Plymouth                   Volare 1976 1G6EL12Y32B567559\n
        Pontiac                  Tempest 1965 WBAKA4C59BC513301\n
        Porsche                      911 1986 WBSBR93426P234215\n
    Rolls-Royce                    Ghost 2012 1D7RE2GK4BS527662\n
           Saab                      900 1996 ZFBCFACH5FZ823825\n
         Saturn                      VUE 2006 1FBAX2CM5FK123544\n
          Scion                       xB 2006 4T3BA3BB7CU135336\n
         Shelby                    GT350 1969 KL4CJESB0FB714062\n
     Studebaker                   Avanti 1962 1GD312CG5DF955034\n
         Subaru                    Justy 1990 KM8JT3AB2CU942198\n
         Suzuki                       SJ 1986 WAU4FAFR9AA736195\n
         Toyota                      MR2 1986 JTDKTUD35ED964783\n
     Volkswagen                     Golf 1987 WDCYC7DF8FX386498\n
          Volvo                      850 1995 1GD312CG7BF949846\n
52 result(s)\n

A few lines of cars-list that might help:

make    model  year   vin
Lexus  LX 2010   4T3BA3BB8CU505032
Dodge  Ram Van B350   1994   5N1CR2MNXEC243935
Volkswagen Type 2 1986   WAUDF48H17K529096
Buick  Lucerne    2011   1FTNX2A57AE582302
Isuzu  Axiom  2004   WBA3A5C53EP267014
GMC    3500 Club Coupe    1995   WBAEK73435B009775
Jaguar XF 2012   WBAFR7C50CC926771
Toyota Tacoma 2010   JTEBU5JR2C5510537
BMW    X6 M   2013   1D7RB1CT9BS271133
Pontiac    GTO    1964   WAUJFAFH5DN416041
Volkswagen CC 2013   1C3CCBAG9EN215371
Ford   LTD Crown Victoria 1993   WBXPA93424W053318
Ford   Aerostar   1994   1FMEU6FE6AU161181
Volvo  S60    2001   WAUSF78E27A949809
Mitsubishi Eclipse    1991   1FTEW1C80AK681226
Volkswagen Touareg    2004   1B3CB5HA6AD986681
Volvo  S80    2002   WBAYA8C58FG901796
Acura  RL 2008   19UUA66268A236346
Porsche    928    1986   2T1BURHE2FC730993
Buick  Somerset   1987   WAUCKAFR5AA102258
Volkswagen Touareg    2010   WAUKF98P49A574439
Chevrolet  Express    2006   JH4KB163X7C282844
Dodge  Charger    2011   WBAHL83566D244296
Toyota Matrix 2012   2C3CCAEG0FH601353
Chevrolet  2500   2000   WAUBF48H37K132190
Jaguar XK Series  2005   19UUA9F25BA671349
Hummer H3 2006   1FMEU6EE2AU658326
Lincoln    MKT    2010   1GT022CG3EF969732
Mitsubishi Galant 1997   WBAUC73528V077781
Lotus  Exige  2006   2T2BK1BA6EC560905
Suzuki Sidekick   1993   3C3CFFAR1DT265678
Mercury    Cougar 1993   3C63D3JL5CG653202
Dodge  Ram Wagon B350 1994   3VWKP7AJ8DM315908
Chevrolet  G-Series G20   1992   1D4RE5GG2BC413258
BMW    M3 2009   5N1AN0NUXFN200196
BMW    X5 2004   WAUUL78E75A789974
Ford   E-Series   1996   WP1AE2A27CL645373
Mazda  Mazda6 2007   WBAYP9C58ED417275
Mazda  Tribute    2005   19UUA9F76CA390478
Lotus  Elise  2007   1G6DJ5EG7A0576643
Dodge  Dakota 2002   WBA3A9C5XFK249518
Volkswagen Quantum    1984   WBANV13548C686202
Lexus  RX 2001   KM8JT3AB2DU052530
Pontiac    Turbo Firefly  1990   5NPDH4AE1CH808652
Land Rover Freelander 2010   4T1BD1EB7EU689348
Acura  NSX    2002   1FTNF2B54AE400508
Mercedes-Benz  SL-Class   2002   WBA3B9G54FN126853
Cadillac   Escalade   2004   2T1BU4EEXCC690200
Toyota Camry Solara   2008   3GYFNFE36FS186821

Notes in program and right format if possible, thanks. You can use any of the sorting searches like bubble or selection search or QuickSort since this is the section we are working on.

P.S This was the question I was given, I can't edit it to give more detail and I can't edit the outputs needed to have anything else because those are non editable and so are the given files.

Solutions

Expert Solution

For the above mentioned Program i had use directory path to my "D" Drive. So Assuming that my files is in "D" drive i am sharing my work.

============================================



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

// A class to represent a cars.
class cars
{
int year;
String make, model,vin;
  
// Constructor
public cars(String make, String model,int year,
String vin)
{
this.make = make;
this.model = model;
this.year = year;
this.vin=vin;
}
  
// Used to print cars details in main()
public String toString()
{
return this.make + " " + this.model +
" " + this.year+" "+this.vin;
}
}
  
class Sortbyroll implements Comparator<cars>
{
// Used for sorting in ascending order of
// roll number
public int compare(cars a, cars b)
{
return a.year - b.year;
}
}

public class JavaApplication43 {

  
public static void main(String[] args)throws IOException
{
  
  
try
{
BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter File Name : ");
String inp=br1.readLine();
String pp="D:\\"+inp;
File file=new File(pp); //creates a new file instance
FileReader fr=new FileReader(file); //reads the file
BufferedReader br=new BufferedReader(fr); //creates a buffering character input stream
  
String line;
ArrayList<cars> ar = new ArrayList<cars>();
while((line=br.readLine())!=null)
{
  
String h[]=line.split(" ");
  
int po=Integer.parseInt(h[2]);
ar.add(new cars(h[0], h[1], po,h[3]));

  

}
fr.close(); //closes the stream and release the resources
System.out.println("Unsorted");
for (int i=0; i<ar.size(); i++)
System.out.println(ar.get(i));
  
Collections.sort(ar, new Sortbyroll());
  
System.out.println("\nSorted by year");
for (int i=0; i<ar.size(); i++)
System.out.println(ar.get(i));
}
catch(IOException e)
{
e.printStackTrace();
}
  
  
  

  
  
}
  
}


Related Solutions

Ask the user for the name of a car maker. Display the oldest and newest car...
Ask the user 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. Standard Input                 Files in the same directory Toyota car-list.txt Required Output What car make are you looking for?\n Oldest Toyota\n Toyota MR2 1985 WAUFFAFL2CN997894\n Newest Toyota\n Toyota Venza 2013 WAUEH54B01N735764\n Standard Input                 Files in the same directory Chevrolet...
Ask the user for a filename, then ask the user for a line of text. Write...
Ask the user for a filename, then ask the user for a line of text. Write the line of text the filename specified by the user. The filename may be absolute or relative to the project directory.
Write a program that will ask for the user to input a filename of a text...
Write a program that will ask for the user to input a filename of a text file that contains an unknown number of integers. And also an output filename to display results. You will read all of the integers from the input file, and store them in an array. (You may need to read all the values in the file once just to get the total count) Using this array you will find the max number, min number, average value,...
Requirements1. Name the java class (and filename) Week3_StringLab .2. Print a welcoming message. 3. Ask user...
Requirements1. Name the java class (and filename) Week3_StringLab .2. Print a welcoming message. 3. Ask user to enter a string. Use the nextLine() input method, 4. Use that string to test out at least 6 String methods, from the String class. 5. Of those 6, you must use these 3 methods: .split(), .indexOf (int ch), .subString (int beginningIndex). 6. Use 3+ other methods that you wish to try. 7. Print out the string BEFORE using each method .8. Have the...
Using the given file, ask the user for a name, phone number, and email. Display the...
Using the given file, ask the user for a name, phone number, and email. Display the required information. These are the Files that I made: import java.util.Scanner; public class Demo5 { public static void main(String args[]) { Scanner keyboard = new Scanner(System.in); System.out.println("New number creation tool"); System.out.println("Enter name"); String name = keyboard.nextLine(); System.out.println("Enter phone number"); String phoneNumber = keyboard.nextLine(); System.out.println("Enter email"); String email = keyboard.nextLine(); Phone test1 = new SmartPhone(name, phoneNumber, email); System.out.print(test1); System.out.println("Telephone neighbor: " + ((SmartPhone) test1).getTeleponeNeighbor()); }...
This is to be done using MIPS assembly language. Display the following menus, ask user to...
This is to be done using MIPS assembly language. Display the following menus, ask user to select one item. If 1-3 is selected, display message “item x is selected”, (x is the number of a menu item), display menus again; if 0 is selected, quit from the program. 1. Menu item 1 2. Menu item 2 3. Menu item 3 0. Quit Please select from above menu (1-3) to execute one function. Select 0 to quit
This is in java, thank you! Problem2: In this problem you ask the user for a...
This is in java, thank you! Problem2: In this problem you ask the user for a month and day. You will then calculate the season based on the month and day. Create a class named Problem2 Create two integer instance variables, month and day. Create a constructor to initialize the both variables. The constructor should accept two arguments as parameters, m and d. Initialize the instance variables with these two values. Create a method called calcSeason. It should not have...
write a program i java that ask the user to enter salary, user ID and username...
write a program i java that ask the user to enter salary, user ID and username and out put them
Design a program in Java to display the following: Car Design Enter the car model's year:...
Design a program in Java to display the following: Car Design Enter the car model's year: 1957 Enter the car's make: Chevy The model year is 1957 The make is Chevy The speed is 0 Let's see what it can do!! The speed is,... 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 STOP! STOP! Let me OUT! The...
Design a program in Java to display the following: Car Design Enter the car model's year:...
Design a program in Java to display the following: Car Design Enter the car model's year: 1957 Enter the car's make: Chevy The model year is 1957 The make is Chevy The speed is 0 Let's see what it can do!! The speed is,... 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 STOP! STOP! Let me OUT! The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT