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:
- Create a class named Vehicle with private fields: make (String), model (String), and milesPerGallon (double). Include getters and setters for these fields.
- Implement the Comparable interface for Vehicle class and override the compareTo() method to compare vehicles based on their milesPerGallon.
- Create a main class (for example, VehicleDriver.java) to handle user input and perform the necessary operations.
- Inside the main method, create a BufferedReader object for user input.
- Prompt the user to enter the number of vehicle data they want to enter and store it in a variable (for example, nVehicles).
- Use a loop to iterate nVehicles times and prompt the user to enter make, model, and miles per gallon for each vehicle.
- Create Vehicle objects using the input data and add them to a LinkedList.
- Sort the LinkedList in ascending order based on miles-per-gallon using the Collections.sort() method.
- Prompt the user to enter a file name to write the sorted data to.
- Create a FileWriter object and iterate over the LinkedList, writing each vehicle's information to the file.
- 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.
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 4 images
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?
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?
- Javaarrow_forwardIn Python Write a class called OrthokonBoard that represents the board for a two-player game that is played on a 4x4 grid. This class does not do everything needed to play a game - it's just responsible for handling the rules concerning the game board. Things like asking the user for moves, printing results for the user, keeping track of whose turn it is, and running the game loop would be the responsibility of one or more other classes. A large, complex program can be simplified by being broken down into multiple classes, each of which has multiple methods. Objects of these different classes then interact with each other to accomplish the desired tasks. This is known as object-oriented programming (OOP). You are only concerned with the OrthokonBoard class. The board starts with four red pieces on row 0 and four yellow pieces on row 3. A valid move consists of a player moving one of their pieces orthogonally or diagonally as far as it can go until it hits another piece or the edge of…arrow_forwardWrite a Program in java Define an interface named Shape with a single method named area that calculates the area of the geometric shape: public double area(); Implement the Shape interface for Rectangle, Circle and Triangle class. Implement a class CalculateAreas that has a function that takes shape type array of objects and builds an array of (double values) values for each corresponding shapesarrow_forward
- An array of class objects can be created in Java. False or Truearrow_forwardDevelop a Java program that simulates a library book checkout system. The program should allow users to check out and return books, maintain a catalog of available books, and display information about overdue books. Follow these guidelines: Create a Book class with attributes like title, author, and availability status. Implement methods to check out and return books, updating the availability status accordingly. Create an array or a collection to store instances of the Book class representing the current catalog. Prompt users to input their library card number before checking out or returning a book for tracking purposes. Keep track of due dates for checked-out books. Assume a standard lending period of 14 days. Display information about overdue books, including the book details and the number of days overdue. Provide feedback messages for successful checkouts, returns, or overdue book information. Include JavaDoc comments for class and method documentation. Utilize single-line…arrow_forwardJava Help Please! The Triangle series is a mathematical sequence of integers defined by the formula: triangle_number = Example: if we start with the integer 1, the series is: 1, 3, 6, 10, 15, 21, 28, 36, … Write a TriangleSeries class that implements Iterable. The TriangleSeries must have a constructor that allows us to specify the “start” number in the (sub) series we want to calculate, and the last number in the (sub)series. Also create a TriangleSequenceIterator that returns the proper integer in the series. Assume the starting value for the series is whatever start-value the client specified when they instantiated the TriangleSeries instance. Your iterator should return false for hasNext() when the “end value” is reached. For your convenience, here is the Iterator interface: interface Iterator<E> { boolean hasNext(); E next();}------ import java.util.Iterator;/** * Triangle Series Rule: t = n * (n + 1) / 2 */public class TriangleSeries implements Iterable<Integer>…arrow_forward
- Need help on java homework assignment, It says Create a class Vehicle. A Vehicle has a single instance variable of type String named "vehicleType" that describes the vehicle. It has an abstract method getTires that takes no parameters and returns an ArrayList<Tire> object that describes each Tire of the vehicle. A Tire class has been provided. Vehicle has a single constructor that takes the vehicle type as a parameter.Create a class Bicycle that extends Vehicle that has two Tires, both of type "skinny". Bicycle should have a single default constructor.Create a class Dragster that extends Vehicle and has four Tires, two of type "slick" and two of type "medium". Dragster should have a single default constructor.Write a tester program to test Bicycle and Dragster objects. Use declarations such as Vehicle b = new Bicycle();in your tester. Here is the code provided : public class Tire { private String size; public Tire(String siz) { size = siz; } public String…arrow_forward1. Design a Java JFood class for a food which implements both cloneable and comparable interfaces The class should have the following private member variables: mId: an integer that holds the food ID mName: a string that holds the food name mQuantity: an integer that holds quantity of servings of food mCalory: a double that holds calory of one serving of food mIngredients: an array of String that holds the names of all ingredients and its size is three and the class should have the following public member functions: default constructor: initializes the product to some default one constructor #2: accepts id, name, quantity, calory and ingredients as arguments. The method should set these values to the appropriate instance variables setFood: accepts quantity, calory and ingredients as arguments. The method should set the arguments to the appropriate instance variables. Please note ingredients need be set as deep copy. Five respective get functions to retrieve the five instance…arrow_forwardWrite a code for the following using Console.WriteLine.arrow_forward
- The goal of this coding exercise is to create two classes BookstoreBook and LibraryBook. Both classes have these attributes: author: Stringtiltle: Stringisbn : String- The BookstoreBook has an additional data member to store the price of the book, and whether the book is on sale or not. If a bookstore book is on sale, we need to add the reduction percentage (like 20% off...etc). For a LibraryBook, we add the call number (that tells you where the book is in the library) as a string. The call number is automatically generated by the following procedure:The call number is a string with the format xx.yyy.c, where xx is the floor number that is randomly assigned (our library has 99 floors), yyy are the first three letters of the author’s name (we assume that all names are at least three letters long), and c is the last character of the isbn.- In each of the classes, add the setters, the getters, at least three constructors (of your choosing) and override the toString method (see samplerun…arrow_forwardDesign a class called Post. This class models a StackOverflow post. It should have properties for title, description and the date/time it was created. We should be able to up-vote or down-vote a post. We should also be able to see the current vote value. In the main method, create a post, up-vote and down-vote it a few times and then display the the current vote value.arrow_forwardFibonacci A fibonacci sequence is a series of numbers in which each number is the sum of the two preceding numbers. For example: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so on… For this, you will implement a class that takes a positive integer (n) and returns the number in the nth position in the sequence. Examples When n is 1, the returned value will be 0. When n is 4, the returned value will be 2. When n is 9, the returned value will be 21. come up with the formula and base cases Implementation Create a class Fibonacci with a public static method getValue. Create a Main class to test and run your Fibonacci class.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education