Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question
100%

Write a Java program that prompts a user for vehicle data and stores it in a linked list, and then sorts the list in ascending order based on miles-per-gallon and writes the sorted data to a text file, you can follow these steps:

  1. Create a class named Vehicle with private fields: make (String), model (String), and milesPerGallon (double). Include getters and setters for these fields.
  2. Implement the Comparable interface for Vehicle class and override the compareTo() method to compare vehicles based on their milesPerGallon.
  3. Create a main class (for example, VehicleDriver.java) to handle user input and perform the necessary operations.
  4. Inside the main method, create a BufferedReader object for user input.
  5. Prompt the user to enter the number of vehicle data they want to enter and store it in a variable (for example, nVehicles).
  6. Use a loop to iterate nVehicles times and prompt the user to enter make, model, and miles per gallon for each vehicle.
  7. Create Vehicle objects using the input data and add them to a LinkedList.
  8. Sort the LinkedList in ascending order based on miles-per-gallon using the Collections.sort() method.
  9. Prompt the user to enter a file name to write the sorted data to.
  10. Create a FileWriter object and iterate over the LinkedList, writing each vehicle's information to the file.
  11. Close the writer and display a success message.

Please and thank you! Also, if it is not to much can you demonstrate/show a screenshot that the file can be seen/viewed in Notepad.

Expert Solution
Check Mark
Still need help?
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Is there a way to implement a simple graphical user interface that will allow the user to manually input a vehicle's make, model, and mpg and also be able to write the data to a text file of the user's choosing with a display message of success or failure?

Solution
Bartleby Expert
by Bartleby Expert
SEE SOLUTION
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Is there a way to implement a simple graphical user interface that will allow the user to manually input a vehicle's make, model, and mpg and also be able to write the data to a text file of the user's choosing with a display message of success or failure?

Solution
Bartleby Expert
by Bartleby Expert
SEE SOLUTION
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education